2010-07-16 11:19:03 +02:00
|
|
|
#!/bin/sh
|
|
|
|
if [ $# != 1 -a $# != 2 ] ; then
|
2010-09-21 18:40:15 +02:00
|
|
|
echo 'Usage: qvm-create-default-dvm templatename|--default-template [script-name|--default-script]'
|
2010-07-16 11:19:03 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2010-09-21 18:40:15 +02:00
|
|
|
if [ "$1" = --default-template ] ; then
|
|
|
|
TEMPLATENAME=$(qvm-get-default-template)
|
|
|
|
if [ "X"$TEMPLATENAME = "X" ] ; then
|
|
|
|
echo No default template ?
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
TEMPLATENAME=$1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "X""$2" = "X""--default-script" ] ; then
|
|
|
|
SCRIPTNAME="/var/lib/qubes/vm-templates/$TEMPLATENAME"/dispvm-prerun.sh
|
|
|
|
if ! [ -f $SCRIPTNAME ] ; then
|
|
|
|
echo $SCRIPTNAME does not exist
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
SCRIPTNAME=$2
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ -d "/var/lib/qubes/vm-templates/$TEMPLATENAME" ] ; then
|
|
|
|
echo /var/lib/qubes/vm-templates/$TEMPLATENAME is not a directory
|
2010-07-16 11:19:03 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2010-09-21 18:40:15 +02:00
|
|
|
DVMTMPL="$TEMPLATENAME"-dvm
|
2011-03-23 09:36:30 +01:00
|
|
|
DVMTMPLDIR="/var/lib/qubes/appvms/$DVMTMPL"
|
|
|
|
if ! [ -d "$DVMTMPLDIR" ] ; then
|
2010-09-21 18:40:15 +02:00
|
|
|
if ! qvm-create -t "$TEMPLATENAME" -l gray "$DVMTMPL" ; then exit 1 ; fi
|
2011-03-23 09:36:30 +01:00
|
|
|
chgrp qubes "$DVMTMPLDIR" "$DVMTMPLDIR"/*
|
|
|
|
chmod 660 "$DVMTMPLDIR"/*
|
|
|
|
chmod 770 "$DVMTMPLDIR"
|
2010-07-16 11:19:03 +02:00
|
|
|
fi
|
|
|
|
if ! /usr/lib/qubes/qubes_prepare_saved_domain.sh \
|
2010-09-21 18:40:15 +02:00
|
|
|
"$DVMTMPL" "/var/lib/qubes/appvms/$DVMTMPL/dvm-savefile" $SCRIPTNAME ; then
|
2010-07-16 11:19:03 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
ROOT=/var/lib/qubes/dvmdata/savefile_root
|
|
|
|
DEFAULT=/var/lib/qubes/dvmdata/default_savefile
|
|
|
|
CURRENT=/var/run/qubes/current_savefile
|
|
|
|
SHMDIR=/dev/shm/qubes
|
|
|
|
SHMCOPY=$SHMDIR/current_savefile
|
|
|
|
rm -f $ROOT $DEFAULT $CURRENT
|
|
|
|
ln -s "/var/lib/qubes/appvms/$DVMTMPL/dvm-savefile" $DEFAULT
|
2010-09-21 18:40:15 +02:00
|
|
|
ln -s "/var/lib/qubes/vm-templates/$TEMPLATENAME/root.img" $ROOT
|
2010-07-16 11:19:03 +02:00
|
|
|
if [ -f /var/lib/qubes/dvmdata/dont_use_shm ] ; then
|
|
|
|
ln -s $DEFAULT $CURRENT
|
|
|
|
else
|
|
|
|
mkdir -m 770 $SHMDIR 2>/dev/null
|
|
|
|
chgrp qubes $SHMDIR 2>/dev/null
|
|
|
|
cp $DEFAULT $SHMCOPY || exit 1
|
|
|
|
chgrp qubes $SHMCOPY
|
|
|
|
chmod 660 $SHMCOPY
|
|
|
|
ln -s $SHMCOPY $CURRENT
|
|
|
|
fi
|