core-admin/appvm/qubes_core

110 lines
2.7 KiB
Plaintext
Raw Normal View History

#!/bin/sh
#
# chkconfig: 345 90 90
# description: Executes Qubes core scripts at VM boot
#
# Source function library.
. /etc/rc.d/init.d/functions
possibly_run_save_script()
{
ENCODED_SCRIPT=$(xenstore-read qubes_save_script)
if [ -z "$ENCODED_SCRIPT" ] ; then return ; fi
echo $ENCODED_SCRIPT|perl -e 'use MIME::Base64 qw(decode_base64); local($/) = undef;print decode_base64(<STDIN>)' >/tmp/qubes_save_script
chmod 755 /tmp/qubes_save_script
Xorg -config /etc/X11/xorg-preload-apps.conf :0 &
sleep 2
DISPLAY=:0 su - user -c /tmp/qubes_save_script
killall Xorg
}
start()
{
echo -n $"Executing Qubes Core scripts:"
if ! [ -x /usr/bin/xenstore-read ] ; then
echo "ERROR: /usr/bin/xenstore-read not found!"
exit 1
fi
if xenstore-read qubes_save_request 2>/dev/null ; then
ln -sf /home_volatile /home
possibly_run_save_script
2010-06-28 18:18:41 +02:00
touch /etc/this_is_dvm
2010-06-02 15:50:22 +02:00
dmesg -c >/dev/null
free | grep Mem: |
(read a b c d ; xenstore-write device/qubes_used_mem $c)
# we're still running in DispVM template
echo "Waiting for save/restore..."
# WARNING: Nergalism!
# Apparently it has been determined that DomU kernel
# dmesg's "using vcpu" after restore
2010-06-02 15:50:22 +02:00
while ! dmesg -c | grep "using vcpu" ; do usleep 10 ; done
# we're now after restore in a new instance of a DispVM
# ... wait until qubes_restore.c (in Dom0) recreates VM-specific keys
2010-06-02 15:50:22 +02:00
while ! xenstore-read qubes_vm_type 2>/dev/null ; do
usleep 10
done
echo Back to life.
fi
name=$(/usr/bin/xenstore-read name)
hostname $name
ip=$(/usr/bin/xenstore-read qubes_ip)
netmask=$(/usr/bin/xenstore-read qubes_netmask)
gateway=$(/usr/bin/xenstore-read qubes_gateway)
secondary_dns=$(/usr/bin/xenstore-read qubes_secondary_dns)
if [ x$ip != x ]; then
/sbin/ifconfig eth0 $ip netmask $netmask up
/sbin/route add default gw $gateway
echo "nameserver $gateway" > /etc/resolv.conf
echo "nameserver $secondary_dns" >> /etc/resolv.conf
fi
2010-06-18 16:21:04 +02:00
2010-06-02 15:50:22 +02:00
if [ -e /dev/xvdb ] ; then
mount /rw
2010-06-18 16:21:04 +02:00
2010-06-02 15:50:22 +02:00
if ! [ -d /rw/home ] ; then
echo
echo "--> Virgin boot of the VM: Linking /home to /rw/home"
mv /home /home.orig
mkdir -p /rw/config
mkdir -p /rw/home
ln -s /rw/home/ /home
cp -a /home.orig/user /home
touch /rw/config/rc.local
rm -fr /home.orig
touch /var/lib/qubes/first_boot_completed
mv /usr/local /usr/local.orig
ln -s /rw/usrlocal /usr/local
cp -a /usr/local.orig /rw/usrlocal
2010-06-02 15:50:22 +02:00
fi
fi
[ -x /rw/config/rc.local ] && /rw/config/rc.local
success
echo ""
return 0
}
stop()
{
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo $"Usage: $0 {start|stop}"
exit 3
;;
esac
exit $RETVAL