ec818dbbc3
commit includes the default configuration files, which don't work with Debian "etch".
157 lines
4.3 KiB
Bash
Executable file
157 lines
4.3 KiB
Bash
Executable file
#!/bin/bash
|
|
#
|
|
# Copyright (c) 02005 sense.lab <senselab@systemausfall.org>
|
|
#
|
|
# License: This script is distributed under the terms of version 2
|
|
# of the GNU GPL. See the LICENSE file included with the package.
|
|
#
|
|
# $Id$
|
|
#
|
|
# managing our work at the cryptobox
|
|
#
|
|
# development actions:
|
|
# chroot - run first tests in a chroot environment
|
|
# qemu - run the qemu emulation with the uncompressed image
|
|
# qemuz - run the qemu emulation with the compressed image
|
|
# upload - copy your local files to tmpfs on a running cryptobox
|
|
# diff - compare tmpfs-files on a running cryptobox with the original
|
|
# merge - apply the diff to the local copy
|
|
# ssh - open a ssh connection to a running cryptobox
|
|
#
|
|
# problems of this script:
|
|
# - chroot has to run as root
|
|
#
|
|
|
|
set -ue
|
|
|
|
# include common functions and settings
|
|
source $(dirname $0)/common.sh.inc
|
|
|
|
################### some settings #####################
|
|
|
|
# to connect to a development cryptobox with ssh
|
|
SSH_CONFIG_FILE=$(get_config_file ssh_config)
|
|
|
|
# extract the hostname of the cryptobox from the ssh_config file
|
|
SSH_HOST=$(grep "^Host " "$SSH_CONFIG_FILE" | head -1 | sed 's/^Host *\(.*\)$/\1/')
|
|
|
|
|
|
####################### functions ######################
|
|
|
|
|
|
function qemu_boot()
|
|
# parameter: iso_image_file
|
|
{
|
|
# create a virtual harddisk image file
|
|
if [ ! -e "$HD_IMAGE" ]
|
|
then echo "Creating temporary harddisk image ..."
|
|
dd if=/dev/zero of="$HD_IMAGE" bs=1M count=$HD_IMAGE_SIZE
|
|
fi
|
|
echo "Starting qemu ..."
|
|
qemu -hda "$HD_IMAGE" -cdrom "$1" -boot d -m 96 -net nic -net tap || true
|
|
}
|
|
|
|
|
|
function upload2box()
|
|
# upload local files to a development cryptobox
|
|
# this is necessary to use an "old" development cd with
|
|
# new code - this affects only the web-interface and the
|
|
# cbox-manage.sh-script (the boot behaviour stays the same)
|
|
#
|
|
# of course, only the directories that are mapped to tmpfs can
|
|
# be updated this way
|
|
{
|
|
local DIRS="var/www usr/share/cryptobox usr/lib/cryptobox"
|
|
echo "Uploading the following dirs: $DIRS "
|
|
[ -e "$TMP_DIR" ] || mkdir -p "$TMP_DIR"
|
|
for a in $DIRS
|
|
do mkdir -p "$TMP_DIR/$a"
|
|
cp -r "$TEMPLATE_DIR/$a/." "$TMP_DIR/$a"
|
|
done
|
|
find "$TMP_DIR" -type d -name '\.svn' | while read a
|
|
do rm -rf "$a"
|
|
done
|
|
echo "Copying local files to the cryptobox ... "
|
|
if scp -F "$SSH_CONFIG_FILE" -rpq "$TMP_DIR/." cryptobox:/tmp/mirror
|
|
then echo "Set the base for future diffs to current state ..."
|
|
ssh -F "$SSH_CONFIG_FILE" "$SSH_HOST" "$DEV_FEATURES_SCRIPT" set_diff_base
|
|
else echo 'ERROR: copying failed!'
|
|
fi
|
|
rm -rf "$TMP_DIR"
|
|
}
|
|
|
|
|
|
function merge_from_box()
|
|
# merge a diff from a running development cryptobox into
|
|
# your local copy
|
|
{
|
|
echo "Check for collisions ... (dry-run)"
|
|
if box_diff | patch --dry-run -p1 -d "$TEMPLATE_DIR"
|
|
then echo
|
|
echo "Applying diff ..."
|
|
box_diff | patch -p1 -d "$TEMPLATE_DIR"
|
|
echo
|
|
echo "Set the base for future diffs to current state ..."
|
|
ssh -F "$SSH_CONFIG_FILE" "$SSH_HOST" "$DEV_FEATURES_SCRIPT" set_diff_base
|
|
else echo "Merging will fail - do it manually!"
|
|
fi
|
|
}
|
|
|
|
|
|
# get the diff of a running cryptobox system between its current state
|
|
# and its original content
|
|
function box_diff()
|
|
{
|
|
ssh -F "$SSH_CONFIG_FILE" "$SSH_HOST" "$DEV_FEATURES_SCRIPT" diff
|
|
}
|
|
|
|
|
|
############################# main #####################################
|
|
|
|
[ $# -eq 0 ] && echo "[`basename $0`] - no arguments supplied - maybe you want to use '--help'" && exit 1
|
|
|
|
ACTION=--help
|
|
[ $# -gt 1 ] && ACTION=$1
|
|
|
|
case "$1" in
|
|
diff )
|
|
# get a diff from a running development cryptobox
|
|
box_diff
|
|
;;
|
|
merge )
|
|
merge_from_box
|
|
;;
|
|
upload )
|
|
upload2box
|
|
;;
|
|
chroot )
|
|
# chroot may only be called as root
|
|
[ "$(id -u)" -ne 0 ] && echo "the action 'chroot' may only be called as root!" >&2 && exit 1
|
|
echo
|
|
echo "##############################################################################"
|
|
echo "# BEWARE: you can severly harm your real harddisk in the chroot environment! #"
|
|
echo "##############################################################################"
|
|
echo
|
|
chroot_image
|
|
;;
|
|
qemu )
|
|
qemu_boot "$IMAGE_FILE"
|
|
;;
|
|
qemuz )
|
|
qemu_boot "$IMAGEZ_FILE"
|
|
;;
|
|
ssh )
|
|
ssh -F "$SSH_CONFIG_FILE" "$SSH_HOST"
|
|
;;
|
|
help|--help )
|
|
echo "Syntax: `basename $0` ( qemu | qemuz | chroot | upload | diff | merge | ssh | help )"
|
|
echo
|
|
;;
|
|
* )
|
|
echo -e "unknown action: $1"
|
|
echo
|
|
$0 help
|
|
exit 1
|
|
;;
|
|
esac
|
|
|