diff options
| -rw-r--r-- | ChangeLog.md | 40 | ||||
| -rw-r--r-- | TODO.md | 14 | ||||
| -rwxr-xr-x | kvmx | 78 | ||||
| -rwxr-xr-x | kvmx-create | 2 | ||||
| -rw-r--r-- | kvmxfile | 13 | ||||
| -rwxr-xr-x | share/provision/debian/desktop-basic | 5 | ||||
| -rwxr-xr-x | share/provision/debian/web-full | 2 |
7 files changed, 125 insertions, 29 deletions
diff --git a/ChangeLog.md b/ChangeLog.md index b99c8cf..5f75806 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,19 +1,53 @@ # ChangeLog -## 0.4.0 - Unreleased +## 0.5.0 - 2025-11-14 + +* Persistent SSH sessions, to speed up connections, especially clipboard + copy and paste between the host and the guests: + * Enabled by default. + + * Configurable with `ssh_persist`, `ssh_control_master`, `ssh_control_path` + and `ssh_control_persist` variables. + +## 0.4.1 - 2024-12-17 + +* Fixes the case when the virtual machine guest is registered under a + different name, other than the name of the project folder on + `__kvmx_initialize`. + +* Fixes VM name and folder logic handling on `kvmx_init`. + +## 0.4.0 - 2024-11-22 * Adds `kvmx sshdir` action, which SSH's to the guest and changes to a given folder. If no arguments are given, it tries to change to the equivalent - folder in the guest, so it can be a way to "cd" to the same directory but + folder in the guest, so it can be a way to `cd` to the same directory but inside the guest. If the folder in the host is also mounted in the guest in a similar mountpoint, it's a handy way to move to the same folder, but inside the guest. - For folders inside $HOME, user name conversion is automatically done since + For folders inside $`HOME`, user name conversion is automatically done since the user inside the guest might not match the user in the host. + Note: this is done in a best-effort basis. It might not work depending + on the remote shell in use. To increase the chances, it's suggested that + the remote shell's startup scripts support the `STARTUP_FOLDER` as + follows. + + Example 1 (sh-compatible): + + # Only change to the startup folder if it's set + if [ ! -z "$STARTUP_FOLDER" ]; then + cd $STARTUP_FOLDER + fi + + Example 2 (sh-compatible): + + # Make sure we start at the startup folder, defaulting to home + cd $STARTUP_FOLDER + ## 0.3.0 - 2024-09-19 * Increase the maximum number of shared folders to avoid error in when KVMX @@ -11,6 +11,11 @@ ## Usability +* [ ] Add a `cryptdisks` action to handle unlocking of encrypted volumes used + by a guest VM. The specific unlocking procedure should be configurable, + and the action must test whether the volume is available and not already + unlocked. + * [ ] Hard pause VM (--hard): besides pausing the process, also try to pause it in the QEMU monitor. @@ -39,6 +44,15 @@ * [ ] Support for per-guest `known_hosts` for SSH logins. +* [ ] Support for storing guest VMs in (remote) repositories, with supporing + actions such as `repo`, `push`, `pull` etc. + +* [ ] Commands to run when the machine comes back from sleep. + But how to detect that the host (like a laptop) came out from + a sleep state? Maybe track the time lapses and run a command + if the interval is too high? Both the interval and the command + could be configurable. + ## Virtualization * [ ] Config option to [disable @@ -19,7 +19,7 @@ # # Basic parameters -VERSION="0.3.0" +VERSION="0.4.1" BASENAME="`basename $0`" DIRNAME="`dirname $0`" ACTION="$1" @@ -67,6 +67,25 @@ function __kvmx_ssh_command { # See http://blog.djm.net.au/2013/11/chacha20-and-poly1305-in-openssh.html SSH_OPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=FATAL -o ProxyCommand=none -o Ciphers=chacha20-poly1305@openssh.com $ssh_key_param" + + # Persist SSH sessions, to speed up connections, especially clipboard copy + # and paste between the host and the guests + if [ "$ssh_persist" != "n" ]; then + if [ -z "$ssh_control_master" ]; then + ssh_control_master="auto" + fi + + if [ -z "$ssh_control_persist" ]; then + ssh_control_persist="0" + fi + + if [ -z "$ssh_control_path" ]; then + ssh_control_path="$HOME/.ssh/kvmx-${VM}-%r@%h:%p" + fi + + SSH_OPTS="$SSH_OPTS -o ControlMaster=$ssh_control_master -o ControlPath=$ssh_control_path -o ControlPersist=$ssh_control_persist" + fi + SSH_COMMAND="ssh $SSH_OPTS -o User=$SSH_LOGIN" SCP_COMMAND="scp $SSH_OPTS -o User=$SSH_LOGIN" } @@ -106,7 +125,20 @@ function __kvmx_initialize { # Check if second argument is a VM name or option if [ -z "$2" ]; then - VM="$(basename `pwd`)" + CANDIDATE_DEST="`pwd`/kvmxfile" + CANDIDATE_SRC="`find $GLOBAL_USER_CONFIG_FOLDER -lname $CANDIDATE_DEST | head -1`" + + if [ ! -z "$CANDIDATE_SRC" ]; then + CANDIDATE_SRC="`basename $CANDIDATE_SRC`" + fi + + # This covers the case when the VM is configured with a different name then the folder name + if [ ! -z "$CANDIDATE_SRC" ] ; then + VM="$CANDIDATE_SRC" + else + VM="$(basename `pwd`)" + fi + SHIFTARGS="1" elif [ -e 'kvmxfile' ] && [ ! -e "$GLOBAL_USER_CONFIG_FOLDER/$2" ] && [ "$2" != "$(basename `pwd`)" ]; then VM="$(basename `pwd`)" @@ -1007,15 +1039,15 @@ function kvmx_sshdir { #exit 1 fi - DEST="$1" + DEST="$*" # Defaults to the current folder if [ -z "$DEST" ]; then DEST="`pwd`" # Fix ~/ path - if echo $DEST | grep -q -e "^$HOME"; then - DEST="$(echo $DEST | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" + if echo "$DEST" | grep -q -e "^$HOME"; then + DEST="$(echo "$DEST" | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" fi fi @@ -1030,11 +1062,14 @@ function kvmx_sshdir { # * https://stackoverflow.com/questions/626533/how-can-i-ssh-directly-to-a-particular-directory#626670 # * https://unix.stackexchange.com/questions/86941/how-to-ssh-into-a-specific-directory # - $ssh_env $SSH_COMMAND -t -p $SSH 127.0.0.1 "cd $DEST && exec \$SHELL --login" + #$ssh_env $SSH_COMMAND -t -p $SSH 127.0.0.1 "cd $DEST && exec \$SHELL --login" # Implementation using approach 2, with a special environment variable # STARTUP_FOLDER, which needs to be supported by the shell startup scripts #$ssh_env $SSH_COMMAND -t -p $SSH 127.0.0.1 "export STARTUP_FOLDER=$DEST && exec \$SHELL --login" + + # Implementation using approach 3: best effort, trying both approaches 1 and 2 at the same time + $ssh_env $SSH_COMMAND -t -p $SSH 127.0.0.1 "export STARTUP_FOLDER=$DEST && cd $DEST && exec \$SHELL --login" } # Enhanced SSH login into the guest @@ -1242,6 +1277,7 @@ function kvmx_poweroff { fi echo "Rsyncing from guest: $poweroff_rsync_from_guest ($id)..." + mkdir -p $poweroff_rsync_from_guest_dest kvmx_rsync_from $poweroff_rsync_from_guest_orig $poweroff_rsync_from_guest_dest unset poweroff_rsync_from_guest_orig @@ -1405,8 +1441,8 @@ function kvmx_rsync_to { fi # Fix ~/ path - if echo $DEST | grep -q -e "^$HOME"; then - DEST="$(echo $DEST | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" + if echo "$DEST" | grep -q -e "^$HOME"; then + DEST="$(echo "$DEST" | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" fi SSH="`cat $SSHFILE`" @@ -1442,8 +1478,8 @@ function kvmx_rsync_from { fi # Fix ~/ path - if echo $ORIG | grep -q -e "^$HOME"; then - ORIG="$(echo $ORIG | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" + if echo "$ORIG" | grep -q -e "^$HOME"; then + ORIG="$(echo "$ORIG" | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" fi SSH="`cat $SSHFILE`" @@ -1474,8 +1510,8 @@ function kvmx_scp_from { fi # Fix ~/ path - if echo $ORIG | grep -q -e "^$HOME"; then - ORIG="$(echo $ORIG | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" + if echo "$ORIG" | grep -q -e "^$HOME"; then + ORIG="$(echo "$ORIG" | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" fi SSH="`cat $SSHFILE`" @@ -1506,8 +1542,8 @@ function kvmx_scp_to { fi # Fix ~/ path - if echo $DEST | grep -q -e "^$HOME"; then - DEST="$(echo $DEST | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" + if echo "$DEST" | grep -q -e "^$HOME"; then + DEST="$(echo "$DEST" | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" fi SSH="`cat $SSHFILE`" @@ -1533,17 +1569,11 @@ function kvmx_upgrade { # Initializes a new guest function kvmx_init { - FOLDER="$1" - - if [ -z "$FOLDER" ]; then - if [ -z "$VM" ]; then - VM="$(basename `pwd`)" - FOLDER="$(dirname `pwd`)/$VM" - else - FOLDER="$(pwd)/$VM" - fi + if [ -z "$1" ]; then + VM="$(basename `pwd`)" + FOLDER="$(dirname `pwd`)/$VM" else - VM="$FOLDER" + VM="$1" if [ ! -z "$2" ]; then FOLDER="$2" diff --git a/kvmx-create b/kvmx-create index c8b3992..9996be5 100755 --- a/kvmx-create +++ b/kvmx-create @@ -266,6 +266,8 @@ EOF if [ "$distro" == "debian" ]; then if [ "$version" != "sid" ] && [ "$version" != "experimental" ] && [ "$version" != "$NEXT_DEBIAN_RELEASE" ]; then echo "deb http://security.debian.org/debian-security $version-security main contrib non-free" | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null + echo "deb https://deb.debian.org/debian/ $version-updates main contrib non-free" | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null + echo "deb-src https://deb.debian.org/debian/ $version-updates main contrib non-free" | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null echo "deb-src http://security.debian.org/debian-security $version-security main contrib non-free" | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null echo "deb https://deb.debian.org/debian/ $version-backports main contrib non-free" | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null echo "deb-src https://deb.debian.org/debian/ $version-backports main contrib non-free" | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null @@ -238,6 +238,19 @@ ssh_custom="y" #ssh_custom_pubkey="/home/myhostuser/.ssh/id_rsa.pub" #ssh_custom_pubkey="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDVFmJ2UDn2dK3nHHAkHzt8F4AfrXTFiGa+guem92S/pztMGAUDjEZBYEW3mZ8ATyo4GoPZ92tkjmra0Fgv6ETIox+SPWbzzjhzbv2CQUTWvF6PEVwJbT1PTzaIVRiDYf+yX7e3Y8HcmkAi60Cxs5Xr3HLkqdi2jYKFofCm58R+HGnRv1WSurPnf7C7KQBSW7E1S2CafW9VFHhGCzezyThjN+n3bJjgYFzPxdTlWyfW1T7Yv61/fqfuara0kpZx1l5pblpgbCTT7WKRIhwj1x0QTo/qDQ6k52tffiCVyMGJKvires9yp5qT5Y+ldssBKDa8muRF/dh7/UCyxvcm3HTDjWG24Sr4r9JWbhkqF89UePlOw5j73qw4gzT7YQ38tzz2XI5weAL1OXM6qhCbOwfPXwYbB5xM4g62WZugtcCLan6Iy8hvoiRIJ1MU2ar73wunghQQ84oNIrEVezJsuZxwxVbe45ulnM7x4Hqeu6jmOutWFkdkAHsqd1E3zTOS1RURwi0TpnD+iWwD7FOA9c8B6AWP4i9XVW6BLi1waARrS3bVnOh3djc20fVsClfEDDXFg2KiTeQaAWfjLguyUmxysSiUC2pnibd1bEDtdfPlkA2jaE2nAn6Tw7Vp5zd8P1d1trLMx3YkRq5uQSPqnfQDKoYH5FPMlNTbMINLC56ijw== user@kvmx" +# Enable SSH connection persistence by using ControlMaster, ControlPath and +# ControlPersist options, as documented at ssh_config(5) +ssh_persist="y" + +# Sets SSH's ControlMaster as documented at ssh_config(5) +ssh_control_master="auto" + +# Sets SSH's ControlPath as documented at ssh_config(5) +ssh_control_path="$HOME/.ssh/kvmx-${VM}-%r@%h:%p" + +# Sets SSH's ControlPersist value as documented at ssh_config(5) +ssh_persist_seconds="0" + # Bootloader (used only during bootstrapping by kvmx-create). bootloader="grub" diff --git a/share/provision/debian/desktop-basic b/share/provision/debian/desktop-basic index 2eeaf5d..2c5ea6d 100755 --- a/share/provision/debian/desktop-basic +++ b/share/provision/debian/desktop-basic @@ -46,7 +46,10 @@ apps/metadot/metadot deps-bundle desktop-basic # Additional packages echo "Installing additional desktop-basic packages..." -$APT_INSTALL xpra lightdm firejail xsel tigervnc-viewer alsa-utils pulseaudio +$APT_INSTALL lightdm firejail xsel alsa-utils pulseaudio + +# For host-guest interfacing +$APT_INSTALL xpra tigervnc-viewer # Tor Browser launcher # Deprecated in favor of https://git.fluxo.info/utils-tor diff --git a/share/provision/debian/web-full b/share/provision/debian/web-full index 040d862..cb8f3c2 100755 --- a/share/provision/debian/web-full +++ b/share/provision/debian/web-full @@ -30,7 +30,7 @@ APT_INSTALL="sudo LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y" $DIRNAME/web-basic $HOSTNAME $DOMAIN $MIRROR # Office Suite -$APT_INSTALL libreoffice libreoffice-gtk3 gimp inkscape mat +$APT_INSTALL libreoffice libreoffice-gtk3 gimp inkscape mat2 # Luakit using stowpkg #if [ ! -x "$HOME/apps/stowpkg/tree/`uname -m`/bin/luakit" ]; then |
