The Uni3-Terminus16.psf.gz font is shipped by console-setup-linux nowadays
[grml-autoconfig.git] / autoconfig.functions
index 467c41e..b7aaee0 100755 (executable)
@@ -13,12 +13,10 @@ KERNEL="$(uname -r)"
 ARCH="$(uname -m)"
 umask 022
 
-# old linuxrc version:
-[ -d /cdrom ]      && export LIVECD_PATH=/cdrom
-# initramfs layout until around December 2012:
-[ -d /live/image ] && export LIVECD_PATH=/live/image
-# initramfs layout since around December 2012:
-[ -d /lib/live/mount/medium ] && export LIVECD_PATH=/lib/live/mount/medium
+# initramfs layout since December 2012, backwards compatibility:
+[ -d /lib/live/mount/medium ] && export LIVECD_PATH='/lib/live/mount/medium'
+# initramfs layout since December 2018:
+[ -d /run/live/medium ] && export LIVECD_PATH='/run/live/medium'
 
 # Ignore these signals in non-interactive mode: INT, TERM, SEGV
 [ -z "$PS1" ] && trap "" 2 3 11
@@ -261,7 +259,7 @@ config_language(){
         if [ -r /usr/share/consolefonts/Uni3-Terminus16.psf.gz ] ; then
           CONSOLEFONT='Uni3-Terminus16'
         else
-          ewarn "/usr/share/consolefonts/Uni3-Terminus16.psf.gz not available. Please upgrade package console-terminus." ; eend 1
+          ewarn "/usr/share/consolefonts/Uni3-Terminus16.psf.gz not available. Please upgrade package console-setup-linux." ; eend 1
         fi
         if ! hasfb ; then
           CONSOLEFONT='Lat15-Terminus16'
@@ -545,7 +543,8 @@ config_kernel(){
 # }}}
 
 # {{{ secure boot
-config_secureboot(){
+# helper function to check whether we're running under (enabled) Secure Boot
+running_under_secureboot() {
   # systemd does this for us, but if we are not running under systemd then mokutil
   # doesn't work as needed as it relies on /sys/firmware/efi/efivars (while
   # /sys/firmware/efi/vars would exist)
@@ -558,20 +557,28 @@ config_secureboot(){
   if [ -x /usr/bin/mokutil ] ; then
     local secstate=$(mokutil --sb-state 2>/dev/null) # "SecureBoot enabled"
     if [ -n "$secstate" ] ; then
-      einfo "SecureBoot is enabled" ; eend 0
+      return 0
     else
-      einfo "SecureBoot not detected" ; eend 0
+      return 1
     fi
   else
     if modprobe efivars &>/dev/null ; then
       if od -An -t u1 /sys/firmware/efi/vars/SecureBoot-*/data 2>/dev/null | grep -q 1 ; then
-        einfo "SecureBoot is enabled" ; eend 0
+        return 0
       else
-        einfo "SecureBoot not detected" ; eend 0
+        return 1
       fi
     fi
   fi
 }
+
+config_secureboot(){
+  if running_under_secureboot ; then
+      einfo "SecureBoot is enabled" ; eend 0
+  else
+      einfo "SecureBoot not detected" ; eend 0
+  fi
+}
 # }}}
 
 # {{{ timezone
@@ -1715,12 +1722,18 @@ config_lvm(){
           fi
           eend 0
           if checkbootparam 'lvm' ; then
-             einfo "Bootoption LVM found. Searching for logical volumes and enabling them:"
              if $SYSTEMD ; then
-               service_wrapper lvm2-lvmetad start
-               vgchange -ay
-               eend $?
+               einfo "Bootoption LVM found, enabling related services."
+               if [ -r /etc/init.d/lvm2-lvmetad ] ; then
+                 service_wrapper lvm2-lvmetad start ; eend $?
+               fi
+               if [ -r /etc/init.d/lvm2-lvmpolld ] ; then
+                 service_wrapper lvm2-lvmpolld start ; eend $?
+               fi
+               einfo "Searching for logical volumes and enabling them:"
+               vgchange -ay ; eend $?
              else
+               einfo "Bootoption LVM found. Searching for logical volumes and enabling them:"
                service_wrapper lvm2 start ; eend $?
              fi
           fi
@@ -1843,16 +1856,22 @@ fi # checkbootparam "BOOT_IMAGE=debian2hd
 
 # {{{ virtualbox shared folders
 config_virtualbox_shared_folders() {
-if $VIRTUALBOX ; then
-  einfo "VirtualBox detected, trying to set up Shared Folders."
-  if ! modinfo vboxsf &>/dev/null ; then
-    ewarn "vboxsf driver not present, not setting up VirtualBox Shared Folders."
-    eend 0
-  elif ! [ -x /usr/sbin/VBoxService ] ; then
-    ewarn "virtualbox-guest-utils not installed, not setting up VirtualBox Shared Folders."
-    eend 0
+  if ! $VIRTUALBOX ; then
+    return
+  fi
+
+  if checkbootparam 'novboxsf' ; then
+    ewarn "Skipping VirtualBox Shared Folders setup as requested on boot commandline." ; eend 0
   else
-    eindent
+    einfo "VirtualBox detected, trying to set up Shared Folders."
+    if ! modinfo vboxsf &>/dev/null ; then
+      ewarn "vboxsf driver not present, not setting up VirtualBox Shared Folders."
+      eend 0
+    elif ! [ -x /usr/sbin/VBoxService ] ; then
+      ewarn "virtualbox-guest-utils not installed, not setting up VirtualBox Shared Folders."
+      eend 0
+    else
+      eindent
 
       einfo "Loading vboxsf driver."
       lsmod | grep -q vboxsf || modprobe vboxsf
@@ -1865,8 +1884,8 @@ if $VIRTUALBOX ; then
 
       config_userfstab
 
-      einfo "Adding $fstabuser to group vboxsf."
-      adduser grml vboxsf &>/dev/null
+      einfo "Adding user ${fstabuser:-grml} to group vboxsf."
+      adduser "${fstabuser:-grml}" vboxsf >>"${DEBUG}" 2>&1
       eend $?
 
       einfo "Starting VBoxService."
@@ -1878,7 +1897,7 @@ if $VIRTUALBOX ; then
         vbautomation="$(getbootparam 'vbautomation' 2>>$DEBUG)"
       fi
 
-      if ! VBoxControl sharedfolder list | egrep -q "^[0-9]+ - ${vbautomation}$" ; then
+      if ! VBoxControl sharedfolder list | egrep -q "^[0-9]+ - ${vbautomation}(\s+|$)" ; then
         ewarn "No automount shared folder '$vbautomation' available"
         eend 0
       else
@@ -1927,9 +1946,36 @@ if $VIRTUALBOX ; then
         fi
       fi
 
-    eoutdent
+      eoutdent
+    fi
   fi
-fi
+}
+# }}}
+
+# {{{ VirtualBox application
+config_virtualbox_setup() {
+  if checkbootparam 'novbox' ; then
+    ewarn "Skipping VirtualBox setup as requested on boot commandline." ; eend 0
+    return
+  fi
+
+  if ! [ -x /usr/bin/VBox ] ; then
+    return
+  fi
+
+  if running_under_secureboot ; then
+    ewarn "VirtualBox service can not be started as running under enabled Secure Boot." ; eend 0
+    return
+  fi
+
+  einfo "VirtualBox service detected, trying to set up."
+  service_wrapper vboxdrv restart >>"${DEBUG}" 2>&1 ; eend $?
+
+  config_userfstab
+
+  einfo "Adding user ${fstabuser:-grml} to group vboxusers."
+  adduser "${fstabuser:-grml}" vboxusers >>"${DEBUG}" 2>&1
+  eend $?
 }
 # }}}