summaryrefslogtreecommitdiffstats
path: root/remote/modules/vbox/data/opt/openslx/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'remote/modules/vbox/data/opt/openslx/scripts')
-rwxr-xr-xremote/modules/vbox/data/opt/openslx/scripts/systemd-vbox_env291
1 files changed, 24 insertions, 267 deletions
diff --git a/remote/modules/vbox/data/opt/openslx/scripts/systemd-vbox_env b/remote/modules/vbox/data/opt/openslx/scripts/systemd-vbox_env
index 8bdfc515..a69719ac 100755
--- a/remote/modules/vbox/data/opt/openslx/scripts/systemd-vbox_env
+++ b/remote/modules/vbox/data/opt/openslx/scripts/systemd-vbox_env
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/ash
# -----------------------------------------------------------------------------
# Copyright (c) 2007..2013 - RZ Uni FR
# Copyright (c) 2007..2013 - OpenSLX GmbH
@@ -19,271 +19,28 @@ export PATH="$PATH":/opt/openslx/bin:/opt/openslx/sbin:/opt/openslx/usr/bin:/opt
VBOX_CONF_DIR=/opt/openslx/etc/vbox
VBOXMANAGE=$(which vboxmanage)
-
-for wait in 1 1 2 2 3 end; do
- grep '^SLX_DNS' /opt/openslx/config > /dev/null && break
- [ "$wait" == "end" ] && echo "No DNS config found, using google dns" && break
- echo "Waiting for DNS config.."
- sleep "$wait"
+# load required Vbox modules
+for module in vboxdrv.ko vboxnetadp.ko vboxnetflt.ko vboxpci.ko ; do
+ insmod /lib/modules/vbox/${module} || slxlog "vbox-systemd" "Loading of ${module} failed."
done
-#source config file
-. /opt/openslx/config
-# . ${VMWARE_CONF_DIR}/vmware.conf
-. ${VBOX_CONF_DIR}/vbox.conf
-
-vm_dhcpd() {
-
- #from plugins/vmware/init-hooks/60-have-servconfig/vm-dhcpd.sh
-
- # read the DNS configuration and if available set WPAD configuration
- [ -z "${SLX_DNS}" ] && SLX_DNS="8.8.8.8"
- [ -n "${wpad}" ] && wpad_config="option wpad ${wpad}"
-
- # configuring dhcpd stub for virtual networks
-cat > ${VMWARE_CONF_DIR}/udhcpd.conf << EOF
-# general udhcpd configuration file for virtual machines written by $0
-
-# start and end of the IP lease block
-start CNETWORK.20
-end CNETWORK.100
-
-# interface that udhcpd will use
-interface NWIF
-
-# how long an offered address is reserved (leased) in seconds
-offer_time 6000
-
-# location of the leases file
-lease_file LEASEFILE
-
-# location of the pid file
-pidfile PIDFILE
-
-option dns ${SLX_DNS}
-option subnet 255.255.255.0
-option router CNETWORK.1
-option wins CNETWORK.10
-option domain virtual.site ${domain_name}
-${wpad_config}
-
-# additional options known to udhcpd
-#subnet #timezone
-#router #timesvr
-#namesvr #dns
-#logsvr #cookiesvr
-#lprsvr #bootsize
-#domain #swapsvr
-#rootpath #ipttl
-#mtu #broadcast
-#wins #lease
-#ntpsrv #tftp
-#bootfile #wpad
-EOF
-
-}
-
-setup_network() {
- #from plugins/vmware/XX_vmware.sh
-
- mkdir -p /tmp/virt/vmware -m 1777
- mkdir -p /dev/shm/vmware -m 1777
- mkdir -p /var/run/vmware -m 1777
- mkdir -p /etc/vmware/udhcpd
-
- # variable might contain ",NAT" which is to be taken off
- if [ -n "$vmnet1" ] ; then
- local vmip=${vmnet1%/*} # x.x.x.x/yy => 'x.x.x.x'">
- local vmsub=$(echo $vmip |sed 's,\(.*\)\..*,\1,') # x.x.x.x => x.x.x
- # setting up the udhcpd configuration
- sed -e "s,NWIF,vmnet1,;s,/misc/,/vmware/," \
- -e "s,CNETWORK,$vmsub,;s,PIDFILE,/var/run/vmware/udhcpd-vmnet1.pid," \
- -e "s,LEASEFILE,/var/run/vmware/udhcpd-vmnet1.leases," \
- ${VMWARE_CONF_DIR}/udhcpd.conf >/etc/vmware/udhcpd/udhcpd-vmnet1.conf
- # setting the base samba configuration if available
- if [ -f /etc/openslx/vmchooser/smb.conf \
- -a -f /usr/sbin/smbd ] ; then
- sed -e "s#NWIF#vmnet1,vmnet8#;s,PIDDIR,/var/run/vmware," \
- ${VMCHOOSER_CONF_DIR}/smb.conf \
- >/etc/vmware/smb.conf
- fi
- fi
-
- # vmware nat interface configuration
- if [ -n "$vmnet8" ] ; then
- local vmnet8ip=${vmnet8%/*}
- local vmpx=${vmnet8#*/}
- local vmsub=$(echo $vmnet8ip |sed 's,\(.*\)\..*,\1,') # x.x.x.x => x.x.x">
- # vmip is user for vmnet8 device
- # vmnet is user for config files nat.conf/dhcp
- local vmip="${vmsub}.1"
- local vmnet="${vmsub}.2"
- # setting up the udhcpd configuration
- sed -e "s,NWIF,vmnet8,;s,/misc/,/vmware/," \
- -e "s,CNETWORK,$vmsub,;s,PIDFILE,/var/run/vmware/udhcpd-vmnet8.pid," \
- -e "s,LEASEFILE,/var/run/vmware/udhcpd-vmnet8.leases," \
- ${VMWARE_CONF_DIR}/udhcpd.conf >/etc/vmware/udhcpd/udhcpd-vmnet8.conf
- # might be not needed any more ...
- echo -e "# Linux NAT configuration file" \
- > /etc/vmware/nat.conf
- echo -e "[host]" \
- >> /etc/vmware/nat.conf
- echo -e "ip = $vmnet/$vmpx" \
- >> /etc/vmware/nat.conf
- echo -e "device = /dev/vmnet8" \
- >> /etc/vmware/nat.conf
- echo -e "activeFTP = 1" \
- >> /etc/vmware/nat.conf
- echo -e "[udp]" \
- >> /etc/vmware/nat.conf
- echo -e "timeout = 60" \
- >> /etc/vmware/nat.conf
- echo -e "[incomingtcp]" \
- >> /etc/vmware/nat.conf
- echo -e "[incomingudp]" \
- >> /etc/vmware/nat.conf
- echo "00:50:56:F1:30:50" > /etc/vmware/vmnet-natd-8.mac
- fi
-
- ############################################################################
- # vmware stuff second part: setting up the environment
- # make udhcpd more silent
- touch /var/run/vmware/udhcpd-vmnet1.leases \
- /var/run/vmware/udhcpd-vmnet8.leases
-
- # create the needed devices which effects all vmware options
- # they are not created automatically via module load
- for i in "/dev/vmnet0 c 119 0" "/dev/vmnet1 c 119 1" \
- "/dev/vmnet8 c 119 8" "/dev/vmmon c 10 165"; do
- mknod $i
- done
-
- chmod 0700 /dev/vmnet*
-}
-
-adapt_tmpfs() {
- # from plugins/vmware/init-hooks/80-after-plugins/adapt-tmpfs.sh
- # Init hook to adapt the tmpfs size for VMware/Player
- # (should be kept identical to the files of virtualbox plugin)
- #############################################################################
-
- # adapt tmpfs size (overbook)
- case $(grep tmpfs /proc/mounts) in
- */tmp*)
- mount -o remount,size=175% /tmp
- ;;
- */uniontmp*)
- mount -o remount,size=175% /uniontmp
- ;;
- esac
-}
-
-#from /etc/init.d/vmware-env
-
-#functions: helper functions
-tempdir () {
- # Create a special tempfs directory
- mkdir -m 1777 -p /tmp/vmware
- # Don't mount special tempfs, when using local harddrive for /tmp
- [ ! -n "$(cat /proc/mounts |grep ' /tmp '|grep '/dev/sd')" ] \
- && mount -t tmpfs -o size=180%,mode=1777 tmpfs /tmp/vmware
-}
-
-load_modules () {
- # VMplayer common stuff
- insmod /lib/modules/vbox/vboxdrv.ko
- insmod /lib/modules/vbox/vboxnetadp.ko
- insmod /lib/modules/vbox/vboxnetflt.ko
- insmod /lib/modules/vbox/vboxpci.ko
-}
-
-unload_modules () {
- rmmod vboxpci vboxnetflt vboxnetadp vboxdrv
-}
-
-vmnetif () {
-# let point the path directly to the directory where the binary lives
-location="/usr/bin"
-if [ -n "$vmnet0" ] ; then
- # the path might be directly point to the plugin dir
- $location/vmnet-bridge -d /var/run/vmnet-bridge-0.pid -n 0
-fi
-if [ -n "$vmnet1" ] ; then
- $location/vmnet-netifup -d /var/run/vmnet-netifup-vmnet1.pid \
- /dev/vmnet1 vmnet1
- ip addr add $vmnet1 dev vmnet1
- ip link set vmnet1 up
- if [ -n "$vmnet1nat" ] ; then
- echo "1" >/proc/sys/net/ipv4/conf/vmnet1/forwarding
- echo "1" >/proc/sys/net/ipv4/conf/br0/forwarding 2>/dev/null
- fi
- /opt/openslx/usr/sbin/udhcpd \
- -S /etc/vmware/udhcpd/udhcpd-vmnet1.conf
-fi
-if [ -n "$vmnet8" ] ; then
- $location/vmnet-netifup -d /var/run/vmnet-netifup-vmnet8.pid \
- /dev/vmnet8 vmnet8
- ip addr add $vmnet8 dev vmnet8
- ip link set vmnet8 up
- echo "1" >/proc/sys/net/ipv4/conf/vmnet8/forwarding
- echo "1" >/proc/sys/net/ipv4/conf/br0/forwarding 2>/dev/null
- iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE
- # /etc/vmware/vmnet-natd-8.mac simply contains a mac like 00:50:56:F1:30:50
- $location/vmnet-natd -d /var/run/vmnet-natd-8.pid \
- -m /etc/vmware/vmnet-natd-8.mac -c /etc/vmware/nat.conf # or logfile
- /opt/openslx/usr/sbin/udhcpd \
- -S /etc/vmware/udhcpd/udhcpd-vmnet8.conf
-fi
-
-}
-
-vmblock () {
-# let point the path directly to the directory where the binary lives
- /usr/bin/vmware-usbarbitrator
-}
-
-
-
-case "$1" in
- start)
- #start: defines start function for initscript
- # vm_dhcpd
- # setup_network
- # adapt_tmpfs
- # hack to access the first serial/parallel port
- # chmod a+rw /dev/ttyS0
- # chmod a+rw /dev/parport0
- # tempdir
- load_modules
- # vmnetif
- # vmblock
- ;;
- stop)
- # stop: defines stop function for initscript
- # killall vmnet-netifup vmnet-natd vmnet-bridge vmware vmplayer \
- # vmware-tray vmnet-dhcpd
- # might take a while until all services are shut down
- # sleep 1
- # umount -l /tmp/vmware 2>/dev/null
- unload_modules
- ;;
- restart)
- #restart: defines restart function for initscript
- $0 stop && $0 start
- ;;
-
- status)
- #status: defines status function for initscript
- echo "Listing loaded kernel modules:"
- lsmod | grep vbox
- echo "Running VMs:"
- $VBOXMANAGE list vms
- ;;
- *)
- #usage: defines usage function for initscript
- ## print out usage
- echo "Usage: $0 {start, stop, restart, status}" >&2
- exit 1
- ;;
-esac
-
+# unload modules if proper systemd shutdown is provided
+#unload_modules () {
+# rmmod vboxpci vboxnetflt vboxnetadp vboxdrv
+#}
+
+mknod -m 0660 /dev/vboxdrv c 10 59
+chown root:vboxusers /dev/vboxdrv
+
+
+# pretty dumb you can just create host-only interfaces, but not assign a specific
+# name/number
+vboxmanage hostonlyif create
+ip link set dev vboxnet0 up
+brctl addif br0 vboxnet0
+vboxmanage hostonlyif create
+ip link set dev vboxnet1 up
+brctl addif nat1 vboxnet1
+vboxmanage hostonlyif create
+ip link set dev vboxnet2 up
+brctl addif vsw2 vboxnet2