DVM: make qvm-get-default-template use the default template, if asked
Via options --default-template and --default-script
This commit is contained in:
parent
c0cac005ec
commit
c22a6ebb84
39
dom0/qvm-tools/qvm-get-default-template
Executable file
39
dom0/qvm-tools/qvm-get-default-template
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/python2.6
|
||||
#
|
||||
# The Qubes OS Project, http://www.qubes-os.org
|
||||
#
|
||||
# Copyright (C) 2010 Joanna Rutkowska <joanna@invisiblethingslab.com>
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
#
|
||||
|
||||
from qubes.qubes import QubesVmCollection
|
||||
from optparse import OptionParser;
|
||||
|
||||
def main():
|
||||
qvm_collection = QubesVmCollection()
|
||||
qvm_collection.lock_db_for_reading()
|
||||
qvm_collection.load()
|
||||
qvm_collection.unlock_db()
|
||||
netvm = qvm_collection.get_default_template_vm()
|
||||
if netvm is None:
|
||||
print ""
|
||||
else:
|
||||
print netvm.name
|
||||
|
||||
|
||||
|
||||
main()
|
@ -1,18 +1,38 @@
|
||||
#!/bin/sh
|
||||
if [ $# != 1 -a $# != 2 ] ; then
|
||||
echo Usage: qvm-create-default-dvm templatename [script-name]
|
||||
echo 'Usage: qvm-create-default-dvm templatename|--default-template [script-name|--default-script]'
|
||||
exit 1
|
||||
fi
|
||||
if ! [ -d "/var/lib/qubes/vm-templates/$1" ] ; then
|
||||
echo /var/lib/qubes/vm-templates/$1 is not a directory
|
||||
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
|
||||
exit 1
|
||||
fi
|
||||
DVMTMPL="$1"-dvm
|
||||
DVMTMPL="$TEMPLATENAME"-dvm
|
||||
if ! [ -d "/var/lib/qubes/appvms/$DVMTMPL" ] ; then
|
||||
if ! qvm-create -t "$1" -l gray "$DVMTMPL" ; then exit 1 ; fi
|
||||
if ! qvm-create -t "$TEMPLATENAME" -l gray "$DVMTMPL" ; then exit 1 ; fi
|
||||
fi
|
||||
if ! /usr/lib/qubes/qubes_prepare_saved_domain.sh \
|
||||
"$DVMTMPL" "/var/lib/qubes/appvms/$DVMTMPL/dvm-savefile" $2 ; then
|
||||
"$DVMTMPL" "/var/lib/qubes/appvms/$DVMTMPL/dvm-savefile" $SCRIPTNAME ; then
|
||||
exit 1
|
||||
fi
|
||||
ROOT=/var/lib/qubes/dvmdata/savefile_root
|
||||
@ -22,7 +42,7 @@ SHMDIR=/dev/shm/qubes
|
||||
SHMCOPY=$SHMDIR/current_savefile
|
||||
rm -f $ROOT $DEFAULT $CURRENT
|
||||
ln -s "/var/lib/qubes/appvms/$DVMTMPL/dvm-savefile" $DEFAULT
|
||||
ln -s "/var/lib/qubes/vm-templates/$1/root.img" $ROOT
|
||||
ln -s "/var/lib/qubes/vm-templates/$TEMPLATENAME/root.img" $ROOT
|
||||
if [ -f /var/lib/qubes/dvmdata/dont_use_shm ] ; then
|
||||
ln -s $DEFAULT $CURRENT
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user