The following are two very alpha version scripts to automate the execution of the VDD VMs. In details: 1. the first one is to launch the desired VM and desktop environment, exploiting the Xephyr functionality; 2. the second one is to create, mount and activate the shared (encrypted or not) per user volume.
1. Launch Script
#!/bin/sh
# *************************************************************** # Copyright notice # # (c) 2009 Binario Etico Soc. Coop. info(@)binarioetico.org # All rights reserved # # This script is part of the VDD-Project www.vdd-project.org. This script is # free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # The GNU General Public License can be found at # http://www.gnu.org/copyleft/gpl.html # # This script is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # This copyright notice MUST APPEAR in all copies of the script! # Author: Fabrizio Nasti fabrizio.nasti(@)binarioetico.org # ***************************************************************
# This script is intended to be executed by a normal user on a LTSP thin client connected to the VDD/LTSP server (XEN # Dom0), to launch: # 1. the xnesting (Xephyr) # 2. the desired virtual machine (DomU) and the desired Desktop Environment
# The script accepts two arguments from command-line VM=$1 # the desired remote VM hostname (lennyvm, jauntyvm, centos5vm, ecc.) DE=$2 # the desired DE launch command (startkde, gnome-session, xfce4-session)
# We probably will use some variables set by the in process web GUI (commented for now) # MOD: Read env variables from a file #source /var/www/$USER/$USER_env
# Set the X channel to be used first by Xephyr and then by export DISPLAY XCH=$[`cat /root/Xephyr_offset` +1]
# Exclude the use of XCH 10 and 11 (i don't know why but they don't work) if [ `echo $XCH` -eq 10 ]; then XCH=$[$XCH +2] fi
if [ `echo $XCH` -eq 11 ]; then XCH=$[$XCH +1] fi
# Check if a Xephyr process is using the set X channel (XCH) while (ps axf | grep "Xephyr" | grep :$XCH 1> /dev/null); do XCH=$[$XCH +1] if [ `echo $XCH` -eq 10 ]; then XCH=$[$XCH +2] fi if [ `echo $XCH` -eq 11 ]; then XCH=$[$XCH +1] fi done
# Launch Xephyr on XCH in fullscreen mode and put it in background Xephyr -ac :$XCH -fullscreen &> /dev/null &
# MOD: Get the Xephyr PID e write it in an apache chroot file XEPHYR_PID=$! if [ -d /var/www/$USER ]; then echo XEPHYR_PID=$XEPHYR_PID > /var/www/$USER/vm_$XCH else sudo mkdir -m 757 /var/www/$USER && echo XEPHYR_PID=$XEPHYR_PID > /var/www/$USER/vm_$XCH fi
# Update the first free X channel to be used (offset) echo $XCH > /root/Xephyr_offset
# When XCH get 50 re-set the offset to 0 if [ "$XCH" -ge "50" ]; then echo 0 > /root/Xephyr_offset fi
# Export custom env variables. They will be passed through ssh to the desired VM (according with # local-server /etc/ssh/ssh_config and remote-virtual machine /etc/ssh/sshd_config) export XCH=$XCH export DE=$DE
# the USER variable is read from standard local environment
# Export desired VM DISPLAY towards the LTSP thin-client (id-est the server) and start the desired # desktop environment (DE)
ssh $USER@$VM 'export DISPLAY=192.168.108.21:$XCH && $DE' &> /dev/null &
# MOD: Write the script variables in an apache chroot file echo VM=$VM >> /var/www/$USER/vm_$XCH echo DE=$DE >> /var/www/$USER/vm_$XCH echo XCH=$XCH >> /var/www/$USER/vm_$XCH # If everything went fine exit without errors exit 0
2. Privacy/Encryption/Share Script
#!/bin/sh
# *************************************************************** # Copyright notice # # (c) 2009 Binario Etico Soc. Coop. info(@)binarioetico.org # All rights reserved # # This script is part of the VDD-Project www.vdd-project.org. This script is # free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # The GNU General Public License can be found at # http://www.gnu.org/copyleft/gpl.html # # This script is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # This copyright notice MUST APPEAR in all copies of the script! # Author: Fabrizio Nasti fabrizio.nasti(@)binarioetico.org # ***************************************************************
VG=serv1
# Read env variables from a file (in particular the crypt/non-crypt user choice) source /var/www/$USER/$USER_env
# For testing purpose, comment the above line and uncomment the following # CRYPT=1
# Check if the encrypted device is already existing if [ -e /dev/$VG/"$USER"_enc ]; then echo encrypted device is already existing
# Check if the shared folder is already existing; if not, create it. if [ -e /home/$USER/share ]; then echo The shared folder is already existing else echo Creating the shared folder mkdir /home/$USER/share fi
# Check if the share is already active; if not active it. if [ -e /var/lib/samba/usershare/"$USER"_share ]; then echo The share is already active else echo Activating the share net usershare add "$USER"_share /home/$USER/share "$USER share" "$USER":F fi
# Mount the encrypted volume and change the ownership of the shared folder. sudo mount.crypt /dev/$VG/"$USER"_enc /home/$USER/share sudo chown -R $USER.$USER /home/$USER/share fi
# Check if the non-encrypted device is already existing if [ -e /dev/$VG/$USER ]; then echo Non-encrypted device is already existing
# Check if the shared folder is already existing; if not, create it. if [ -e /home/$USER/share ]; then echo The shared folder is already existing else echo Creating the shared folder mkdir /home/$USER/share fi
# Check if the share is already active; if not, active it. if [ -e /var/lib/samba/usershare/"$USER"_share ]; then echo The share is already active else echo Activating the share net usershare add "$USER"_share /home/$USER/share "$USER share" "$USER":F fi
# Mount the non-encrypted volume and change the ownership of the shared folder. sudo mount /dev/$VG/$USER /home/$USER/share sudo chown -R $USER.$USER /home/$USER/share fi
# Check if neither encrypted or non-encrypted device is existing if [ ! -e /dev/$VG/"$USER"* ]; then echo "Device doesn't exist"
# If the user is asking for an ENCRYPTED SHARE, create the encrypted volume, the filesystem on it, the shared # folder if necessary and activate the share if necessary. if CRYPT=1; then echo Creating encrypted device sudo lvcreate -n "$USER"_enc -L 1G --addtag "$USER"_enc $VG sudo cryptsetup --verbose -c aes-cbc-essiv:sha256 --verify-passphrase luksFormat /dev/$VG/"$USER"_enc sudo cryptsetup luksOpen /dev/$VG/"$USER"_enc "$USER"_enc echo Creating filesystem sudo mke2fs -j /dev/mapper/"$USER"_enc [ -e /dev/$VG/"$USER"_enc ] && [ ! -e /home/$USER/share ] && mkdir /home/$USER/share if [ -e /var/lib/samba/usershare/"$USER"_share ]; then echo The share is already active else echo Activating the share net usershare add "$USER"_share /home/$USER/share "$USER share" "$USER":F fi sudo cryptsetup luksClose "$USER"_enc
# Mount the encrypted volume and change the ownership of the shared folder. sudo mount.crypt /dev/$VG/"$USER"_enc /home/$USER/share sudo chown -R $USER.$USER /home/$USER/share # If the user is asking for a NON-ENCRYPTED SHARE, create the volume, the filesystem on it, the shared folder if # necessary and activate the share if necessary. else echo Creating non-encrypted device sudo lvcreate -n $USER -L 1G --addtag $USER $VG echo Creating filesystem sudo mke2fs -j /dev/mapper/$USER [ -e /dev/$VG/$USER ] && [ ! -e /home/$USER/share ] &&
mkdir /home/$USER/share if [ -e /var/lib/samba/usershare/"$USER"_share ]; then echo The share is already active else echo Activating the share net usershare add "$USER"_share /home/$USER/share "$USER share" "$USER":F fi
# Mount the encrypted volume and change the ownership of the shared folder. sudo mount /dev/$VG/$USER /home/$USER/share sudo chown -R $USER.$USER /home/$USER/share fi
fi
# If everything went fine exit without errors exit 0
|