#!/bin/sh #------------------------------------------------------------------------------- # /var/install/bin/xen-fli4l-config - menu script for editing fli4l config # # Creation: 03.11.05 fw # Last Update: $Id$ # # $1: Filename of configuration file without extension # # Copyright (c) 2005 Fabian Wolter # # This program 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. #------------------------------------------------------------------------------- extension=".txt" fli4lconfpath=/home/fli4l fli4lbuildpath=/home/fli4l editor="/var/install/bin/edit-conf.cui" xenconf=/etc/xen/xm . /var/install/include/eislib . /etc/config.d/xen checkIfVMExists () { local idx local name exists="no" idx=1 while [ $idx -le $XEN_VM_N ] do eval name='$XEN_VM_'$idx'_NAME' if [ "$name" = "$1" ] then exists="yes" break fi idx=`expr $idx + 1` done } checkIfVMIsUp () { if xm list | grep -q $1 then isUp="yes" else isUp="no" fi } checkIfVMIsBuilt () { local idx local name isBuilt="no" idx=1 while [ $idx -le $XEN_VM_N ] do eval name='$XEN_VM_'$idx'_NAME' if [ -f $fli4lbuildpath/config.$name/build/rc.cfg ] then isBuilt="yes" break fi idx=`expr $idx + 1` done } idx2name () { idx=1 while [ $idx -le $XEN_VM_N ] do eval name='$XEN_VM_'$idx'_NAME' if [ "$idx" = "$1" ] then break fi idx=`expr $idx + 1` done } isfli4l () { if ls $fli4lconfpath/config.$1 2>/dev/null >&2 then return 0 else return 1 fi } echo "Checking if xend is running ..." if ! /etc/init.d/xen status then /etc/init.d/xen startxend fi while [ 1 ] do clrhome mecho -info "List Xen domains" echo techo begin 4 7 50 techo -info row no. booted name if [ $XEN_VM_N -gt 0 ] then idx=1 while [ $idx -le $XEN_VM_N ] do eval name='$XEN_VM_'$idx'_NAME' checkIfVMExists $name # returns $exists checkIfVMIsUp $name # returns $isUp if [ "$exists" = "no" ] then configured="no" isUp="no" else configured="yes" fi techo row $idx $isUp $name idx=`expr $idx + 1` done else techo row "" "" "No fli4l domains created, yet" techo row "" "" "go to \"Edit Xen Configuration\" in the main menu" fi techo end echo echo echo -n "Enter command ([0-9] to configure the domain, ENTER=Return): " read domainid case "$domainid" in "") break ;; [1-9] | [1-9][0-9] | [1-9][0-9][0-9]) while [ 1 ] do clrhome sh /var/install/config.d/xen.sh idx2name $domainid # returns $name checkIfVMExists $name # returns $exists checkIfVMIsUp $name # returns $isUp checkIfVMIsBuilt $name # returns $isBuilt mecho -info "Management for Xen domain $name" echo echo -n "Status: " if [ "$exists" = "no" ] then mecho -warn "You have to configure this domain in Xen main configuration!" mecho -warn "Set XEN_VM_n_NAME=$name" elif [ "$isUp" = "yes" ] then mecho -info "Domain is running" else mecho -warn "Domain is not running" fi echo if [ "$isBuilt" = "no" ] then echo "Domain is not built!" mecho -warn "You have to run mkfli4l" fi if isfli4l $name then techo begin 4 30 techo -info row No. Filename idx=1 for conffile in $fli4lconfpath/config.$name/*.txt do techo row $idx `basename $conffile` eval 'conf_'$idx'='$conffile idx=`expr $idx + 1` done techo end fi echo echo echo "Please enter command" if [ "$isBuilt" = "yes" ] then if [ "$isUp" = "yes" ] then echo " [s]hutdown," echo "s[u]spend, " echo " [c]onnect," echo " [k]ill," echo " [r]eboot," else echo " [b]oot," echo "b[o]ot & connect," fi fi echo " [d]elete configuration," if isfli4l $name then echo " run [m]kfli4l," echo -n " [0-9] to edit configuration file, ENTER=Return: " else echo -n " ENTER=Return: " fi read cmd case "$cmd" in "") break ;; "m") mkfli4lError=0 cd $fli4lbuildpath if sh mkfli4l.sh config.$name then checkIfVMExists $name # exists cd $fli4lbuildpath/config.$name/build mkdir tmp.$$ cd tmp.$$ tar xzf ../rootfs.img ln -s usr/local/bin/busybox init find . | sudo cpio --quiet -o -H newc | gzip -9 > ../rootfs.img.cpio cd .. rm -R tmp.$$ gzip -9 rootfs.img.cpio mv rootfs.img.cpio.gz rootfs.img.cpio if [ "$exists" = "yes" ] then mecho -info "You can disconnect from the virtual machine by pressing Ctrl-]" echo "(On german keyboards typically Strg-AltGr-9, PuTTY Strg-+)" if xm list | grep -q $name then if /var/install/bin/ask "Reboot & connect to Xen domain now" "y" then xm shutdown $name xm console $name xm create -c $xenconf$name fi else if /var/install/bin/ask "Boot & connect to Xen domain now" "y" then if ! /etc/init.d/xen netstatus then /etc/init.d/xen startnet fi xm create -c $xenconf$name fi fi fi else mkfli4lError=1 fi if [ $mkfli4lError -eq 1 ] then mecho -error "The build of fli4l returned an error!" fi /var/install/bin/anykey ;; "r") if [ "$exists" = "no" ] then mecho -error "You have to configure this xen domain in the xen configuration first!" else echo "Rebooting $name ..." xm shutdown --reboot $name fi /var/install/bin/anykey ;; "s") if [ "$exists" = "no" ] then mecho -error "You have to configure this xen domain in the xen configuration first!" else echo "Shutting down $name ..." xm shutdown $name fi /var/install/bin/anykey ;; "u") if [ "$exists" = "no" ] then mecho -error "You have to configure this xen domain in the xen configuration first!" else echo "Suspending domain $name ..." xm pause $name fi /var/install/bin/anykey ;; "k") if [ "$exists" = "no" ] then mecho -error "You have to configure this xen domain in the xen configuration first!" else echo "Destroying domain $name ..." xm destroy $name fi /var/install/bin/anykey ;; "b") if [ "$exists" = "no" ] then mecho -error "You have to configure this xen domain in the xen configuration first!" else echo "Booting $name ..." xm create $xenconf$name fi /var/install/bin/anykey ;; "c") if [ "$exists" = "no" ] then mecho -error "You have to configure this xen domain in the xen configuration first!" else mecho -info "You can disconnect from this domain by pressing Ctrl-]" xm console $name fi ;; "o") if [ "$exists" = "no" ] then mecho -error "You have to configure this xen domain in the xen configuration first!" else mecho -info "You can disconnect from this virtual machine by pressing Ctrl-]" echo "(On german keyboards typically Strg-AltGr-9, PuTTY Strg-+)" anykey xm create -c $xenconf$name fi /var/install/bin/anykey ;; "d") if /var/install/bin/ask "Do you really want to delete all configuration and built files of the domain '$name'" "n" then echo mecho -info "Deleting $name ..." rm -fvr $fli4lbuildpath/build.$name rm -fvr $fli4lconfpath/config.$name /var/install/bin/anykey break fi ;; [1-9] | [1-9][0-9] | [1-9][0-9][0-9]) eval 'conffile=$conf_'$cmd confbasename=`basename $conffile` confname=`echo $confbasename | sed 's/\.txt//'` cd $fli4lconfpath $editor -c -m \ --config-base=config.$name \ --check-base=check \ --default-base=config \ --default-ext=txt \ $confname ;; esac done ;; esac done