summaryrefslogtreecommitdiffstats
path: root/src/os-plugins/plugins/vmchooser/XX_vmchooser.sh
blob: 957b24e7d8a84a372041c713accf116d5fcfeb7a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright (c) 2008, 2009 - RZ Uni Freiburg
# Copyright (c) 2008..2011 - OpenSLX GmbH
#
# This program/file is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your feedback to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org
#
# script is included from init via the "." load function - thus it has all
# variables and functions available

# include default directories
. /etc/openslx.conf

CONFFILE="/initramfs/plugin-conf/vmchooser.conf"
PLUGINCONFDIR=/mnt/${OPENSLX_DEFAULT_CONFDIR}/plugins/vmchooser
BINDIR=/mnt/${OPENSLX_DEFAULT_BINDIR}
PLUGINDIR=${OPENSLX_DEFAULT_DIR}/plugin-repo/vmchooser
VIRTDIR=/mnt/${OPENSLX_DEFAULT_VIRTDIR}

if [ -e $CONFFILE ]; then
  . $CONFFILE
  if [ $vmchooser_active -ne 0 ] ; then
    [ $DEBUGLEVEL -gt 0 ] \
        && echo "vmchooser: copying stage3 configuration file ..."
    testmkd ${PLUGINCONFDIR}/loopimg
    testmkd ${PLUGINCONFDIR}/fd-loop 1777

    vmchooser_conf_dir=/mnt/etc/vmchooser
    vmchooser_conf=${vmchooser_conf_dir}/vmchooser.conf    

    testmkd ${vmchooser_conf_dir}

    [ ! -z $vmchooser_env ]     && echo "pool=${vmchooser_env}"     >> $vmchooser_conf
    [ ! -z $vmchooser_theme ]   && echo "theme=${vmchooser_theme}"  >> $vmchooser_conf
    [ ! -z $vmchooser_pvs ]     && echo "pvs=${vmchooser_pvs}"      >> $vmchooser_conf
    [ ! -z $vmchooser_xmlpath ] && echo "path=${vmchooser_xmlpath}" >> $vmchooser_conf

    vmchooser_theme_dir=/mnt/usr/local/share/vmchooser/themes
    testmkd $vmchooser_theme_dir

    cp -r /mnt/${PLUGINDIR}/themes/* $vmchooser_theme_dir

    cp $CONFFILE ${PLUGINCONFDIR}/vmchooser.conf
    ln -s ${PLUGINDIR}/run-virt.sh ${BINDIR}/run-virt.sh
    ln -s ${PLUGINDIR}/vmchooser ${BINDIR}/vmchooser
    ln -s ${PLUGINDIR}/xmlfilter.sh ${BINDIR}/xmlfilter.sh

    # setup all generic virtualization / starting stuff like the floppy image
    # loop file for exchanging information between linux and vm guest
    if modprobe ${MODPRV} loop; then
      mdev -s
    else
      : #|| error "" nonfatal
    fi
    # mount a clean tempfs (bug in UnionFS prevents loopmount to work)
    grep -qE "unionfs |aufs " /proc/mounts && \
      mount -n -o size=1500k -t tmpfs vm-loopimg ${PLUGINCONFDIR}/loopimg
    # create an empty floppy image of 1.4MByte size
    dd if=/dev/zero of=${PLUGINCONFDIR}/loopimg/fd.img count=2880 bs=512 \
      2>/dev/null
    chmod 0777 ${PLUGINCONFDIR}/loopimg/fd.img
    # use dos formatter copied into stage3
    mkdosfs ${PLUGINCONFDIR}/loopimg/fd.img >/dev/null 2>&1 #|| error
    mount -n -t msdos -o loop,umask=000 ${PLUGINCONFDIR}/loopimg/fd.img \
      ${PLUGINCONFDIR}/fd-loop
    
    if [ $vmchooser_pvs -ne 0 ]; then
        sed -i /mnt/usr/share/xsessions/default.desktop \
            -e "s,vmchooser$,vmchooser --pvs,"
    fi
    # setup more scratch space for virtual machines, if configured
    testmkd /mnt/var/lib/virt/vmscratch
    testmkd /mnt/tmp/virt
    testmkd /mnt/var/log/samba

    # enable normal users to setup the extended virtual machine redo file space
    # and image source via network block device (NBD only at the moment)
    # allow to start/stop samba on virtual devices (latter one ignores multiple
    # independent daemons) 
    cat >> /mnt/etc/sudoers << EOF
# allow to start and stop the special /tmp redo file space (RAM + NBD/NFS server RAID)
ALL ALL=NOPASSWD: /sbin/losetup /dev/loop* 
ALL ALL=NOPASSWD: /sbin/mdadm -C /dev/md0 -l linear --raid-devices=2 /dev/loop* /dev/*
ALL ALL=NOPASSWD: /opt/openslx/rootfs/usr/sbin/nbd-client * * /dev/nbd*
# allow to configure and start/stop samba services
ALL ALL=NOPASSWD: /opt/openslx/rootfs/bin/sed -i /etc/*/smb.conf -e *
ALL ALL=NOPASSWD: /usr/sbin/nmbd -s /etc/*/smb.conf
ALL ALL=NOPASSWD: /usr/sbin/smbd -s /etc/*/smb.conf
ALL ALL=NOPASSWD: /opt/openslx/rootfs/usr/bin/killall nmbd smbd
EOF

    # finished ...
    [ $DEBUGLEVEL -gt 0 ] && echo "done with 'vmchooser' os-plugin ..."
  fi
fi