diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2017-12-30 18:55:39 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2017-12-30 18:55:39 -0200 |
commit | 7a1e71848c9935f06fc2f75547a4ff294322574b (patch) | |
tree | ac8c094c92cc2b71087fbfbf3ab3bf594b831fa3 | |
parent | 947f13f968d0f22894103a6223b8730d1c79e5d4 (diff) | |
download | kvmx-7a1e71848c9935f06fc2f75547a4ff294322574b.tar.gz kvmx-7a1e71848c9935f06fc2f75547a4ff294322574b.tar.bz2 |
Use STORAGE more often an adds datadir param
-rwxr-xr-x | kvmx | 35 | ||||
-rw-r--r-- | kvmxfile | 3 |
2 files changed, 20 insertions, 18 deletions
@@ -153,8 +153,9 @@ function __kvmx_initialize { KVMXFILE="`readlink $GLOBAL_USER_CONFIG_FOLDER/$VM`" KVMX_PROJECT_FOLDER="`dirname $KVMXFILE`" STORAGE="`dirname $image`" - STATE_DIR="$STORAGE/state/$VM" - LOG_DIR="$STORAGE/log" + DATADIR="${datadir:-$STORAGE}" + STATE_DIR="$DATADIR/state/$VM" + LOG_DIR="$DATADIR/log" PIDFILE="$STATE_DIR/pid" PORTFILE="$STATE_DIR/port" XDMCPPORTFILE="$STATE_DIR/xdmcp" @@ -169,9 +170,9 @@ function __kvmx_initialize { MONITORFILE="$STATE_DIR/monitor" CONSOLEFILE="$STATE_DIR/console" - if [ -e "$STORAGE/ssh/$VM.key" ]; then - mkdir -p "$STORAGE/ssh" - SSHKEY="$STORAGE/ssh/$VM.key" + if [ -e "$DATADIR/ssh/$VM.key" ]; then + mkdir -p "$DATADIR/ssh" + SSHKEY="$DATADIR/ssh/$VM.key" else SSHKEY="$APP_BASE/share/ssh/insecure_private_key" fi @@ -319,9 +320,9 @@ function kvmx_up { fi if [ -e "$basekey" ]; then - vmname="$(basename `dirname $image`)" - imagekey="`dirname $image`/ssh/$vmname.key" - mkdir -p "`dirname $image`/ssh" + vmname="$(basename $STORAGE)" + imagekey="$STORAGE/ssh/$vmname.key" + mkdir -p "$STORAGE/ssh" cp $basekey $imagekey cp $basekey.pub $imagekey.pub @@ -916,8 +917,7 @@ function kvmx_clone { # If dest is given without a full path, clone to the same basedir # as the original guest. if [ "$FOLDER" == "$DEST" ]; then - FOLDER="`dirname $image`" - FOLDER="`dirname $FOLDER`/$DEST" + FOLDER="`dirname $STORAGE`/$DEST" fi # Check if dest machine exists @@ -939,9 +939,9 @@ function kvmx_clone { # Copy image and configuration echo "Copying basebox..." if which rsync &> /dev/null; then - rsync -ah --sparse --progress `dirname $image`/ $FOLDER/ + rsync -ah --sparse --progress $STORAGE/ $FOLDER/ else - cp -r --sparse=always `dirname $image` $FOLDER/ + cp -r --sparse=always $STORAGE/ $FOLDER/ fi # Remove old state folder @@ -1005,7 +1005,7 @@ function kvmx_destroy { rm -f $image rm -rf $STATE_DIR - echo "$BASENAME: removed image and state files, but not the whole `dirname $image` folder." + echo "$BASENAME: removed image and state files, but not the whole $STORAGE folder." } # Shred a guest @@ -1135,8 +1135,8 @@ function kvmx_log { # Rotate SSH keys function kvmx_rotate_sshkeys { # Generate new keypair - mkdir -p "$STORAGE/ssh" - SSHKEY="$STORAGE/ssh/$VM.key" + mkdir -p "$DATADIR/ssh" + SSHKEY="$DATADIR/ssh/$VM.key" __kvmx_ssh_keygen $SSHKEY.new "$user@`basename $image .img`" # Replace pubkey on server @@ -1342,8 +1342,7 @@ function kvmx_rename { # If dest is given without a full path, rename to the same basedir # as the original guest. if [ "$FOLDER" == "$DEST" ]; then - FOLDER="`dirname $image`" - FOLDER="`dirname $FOLDER`/$DEST" + FOLDER="`dirname $STORAGE`/$DEST" fi # Check if dest machine exists @@ -1364,7 +1363,7 @@ function kvmx_rename { # Copy image and configuration echo "Renaming guest..." - mv "`dirname $image`" "$FOLDER" + mv "$STORAGE" "$FOLDER" # Remove old state folder rm -rf $FOLDER/state/* @@ -85,6 +85,9 @@ run_xephyr="0" # Where the guest image is stored #image="$HOME/.local/share/kvmx/$VM/box.img" +# Where datafiles are stored: just set this if you know what you're doing +#datadir="$HOME/.local/share/kvmx/$VM" + # Image size size="10G" |