X-Git-Url: http://git.grml.org/?p=grml-autoconfig.git;a=blobdiff_plain;f=autoconfig.functions;h=48bf32ce5b72ebecddb16b9862abf1a8f98dab7b;hp=802db3894627721e837bedf9454168f5b75e7908;hb=HEAD;hpb=2b9d1d5a109a4802953d46aaa49269b61753376c diff --git a/autoconfig.functions b/autoconfig.functions index 802db38..3bab753 100755 --- a/autoconfig.functions +++ b/autoconfig.functions @@ -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 @@ -31,17 +29,22 @@ fi service_wrapper() { if [ "$#" -lt 2 ] ; then - echo "Usage: service_wrapper " >&2 + echo "Usage: service_wrapper [background]" >&2 return 1 fi local service="$1" local action="$2" + local background="$3" if $SYSTEMD ; then systemctl "$action" "$service" else - /etc/init.d/"$service" "$action" + if [ "${background:-}" = "background" ] ; then + /etc/init.d/"$service" "$action" & + else + /etc/init.d/"$service" "$action" + fi fi } @@ -181,13 +184,18 @@ KVM=false VIRTUALBOX=false VMWARE=false -if vmware-detect &>/dev/null; then +if virt-what 2>/dev/null | grep -q 'vmware' || \ + imvirt 2>/dev/null | grep -iq "vmware" ; then VIRTUAL=true; VMWARE=true; VIRTUAL_ENV='VMware' -elif [ "$(virt-what 2>/dev/null)" = "kvm" ] || \ - [ "$(imvirt 2>/dev/null)" = "KVM" ] ; then +fi + +if virt-what 2>/dev/null | grep -q 'kvm' || \ + [ "$(imvirt 2>/dev/null)" = "KVM" ] ; then VIRTUAL=true; KVM=true; VIRTUAL_ENV='KVM' -elif [ "$(virt-what 2>/dev/null)" = "virtualbox" ] || \ - [ "$(imvirt 2>/dev/null)" = "VirtualBox" ] ; then +fi + +if virt-what 2>/dev/null | grep -q 'virtualbox' || \ + [ "$(imvirt 2>/dev/null)" = "VirtualBox" ] ; then VIRTUAL=true; VIRTUALBOX=true; VIRTUAL_ENV='VirtualBox' fi # }}} @@ -201,46 +209,12 @@ else fi # }}} -# {{{ debug -config_debug(){ - checkbootparam 'debug' && BOOTDEBUG="yes" - checkbootparam "BOOT_IMAGE=debug" && BOOTDEBUG="yes" - - rundebugshell(){ - if [ -n "$BOOTDEBUG" ]; then - einfo "Starting intermediate shell stage $stage as requested by \"debug\" option." - if [ grep -q "debug=noscreen" "$CMDLINE" ] ; then - einfo "Notice that the shell does not provide job handling: ctrl-z, bg and fg won't work!" - einfo "Just exit the shell to continue boot process..." - /bin/zsh - else - eindent - if [ -r /etc/grml/screenrc ] ; then - einfo "Starting GNU screen to be able to use a full featured shell environment." - einfo "Just exit the shells (and therefore screen) to continue boot process..." - /bin/zsh -c "screen -c /etc/grml/screenrc" - else - einfo "Notice that the shell does not provide job handling: ctrl-z, bg and fg won't work!" - einfo "Just exit the shell to continue boot process..." - /bin/zsh - fi - eoutdent - fi - fi - } -} -# }}} - # {{{ log config_log(){ if checkbootparam 'log' || checkbootparam 'debug' ; then export DEBUG="/tmp/grml.log.`date +%Y%m%d`" - touch $DEBUG - einfo "Bootparameter log found. Log files: ${DEBUG} and /var/log/boot" - eindent - einfo "Starting bootlogd." # known to be *very* unreliable :( - bootlogd -r -c >>$DEBUG 2>&1 ; eend $? - eoutdent + touch "${DEBUG}" + einfo "Bootparameter log found, debug log file from grml-autoconfig available at '${DEBUG}'" else DEBUG="/dev/null" fi @@ -250,165 +224,190 @@ fi ### {{{ language configuration / localization config_language(){ - einfo "Activating language settings:" - eindent + einfo "Activating language settings:" + eindent - # people can specify $LANGUAGE and $CONSOLEFONT in a config file - [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig + # people can specify $LANGUAGE and $CONSOLEFONT in a config file + [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig - # check for bootoption which overrides config from /etc/grml/autoconfig - BOOT_LANGUAGE="$(getbootparam 'lang' 2>>$DEBUG)" - [ -n "$BOOT_LANGUAGE" ] && LANGUAGE="$BOOT_LANGUAGE" + # check for bootoption which overrides config from /etc/grml/autoconfig + BOOT_LANGUAGE="$(getbootparam 'lang' 2>>$DEBUG)" + [ -n "$BOOT_LANGUAGE" ] && LANGUAGE="$BOOT_LANGUAGE" - # set default to 'en' in live-cd mode iff $LANGUAGE is not set yet - if [ -z "$INSTALLED" ] ; then + # set default to 'en' in live-cd mode iff $LANGUAGE is not set yet + if [ -z "$INSTALLED" ] ; then [ -n "$LANGUAGE" ] || LANGUAGE='en' - fi + fi - if [ -x /usr/sbin/grml-setlang ] ; then - # if bootoption lang is used update /etc/default/locale accordingly - if [ -n "$BOOT_LANGUAGE" ] ; then - /usr/sbin/grml-setlang "$LANGUAGE" - # otherwise default to lang=en - else - /usr/sbin/grml-setlang "en" - fi - fi + if [ -x /usr/sbin/grml-setlang ] ; then + # if bootoption lang is used update /etc/default/locale accordingly + if [ -n "$BOOT_LANGUAGE" ] ; then + /usr/sbin/grml-setlang "$LANGUAGE" + # otherwise default to lang=en + else + /usr/sbin/grml-setlang "en" + fi + fi - # set console font - if [ -z "$CONSOLEFONT" ] ; then - if ! checkbootparam 'nodefaultfont' >>$DEBUG 2>&1 ; then - if [ -r /usr/share/consolefonts/Uni3-Terminus16.psf.gz ] ; then + if ! $SYSTEMD ; then + # set console font + if [ -z "$CONSOLEFONT" ] ; then + if ! checkbootparam 'nodefaultfont' >>$DEBUG 2>&1 ; then + 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 - fi - if ! hasfb ; then + else + 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' - fi + fi + fi fi - fi + fi # not running systemd - # export it now, so error messages get translated, too - [ -r /etc/default/locale ] && . /etc/default/locale - export LANG LANGUAGE - - # configure keyboard layout, read in already set values first: - [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard - - # now allow keyboard override by boot commandline for later use: - KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)" - [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD" - # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead: - [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys - [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys - - # modify /etc/sysconfig/keyboard only in live-cd mode: - if [ -z "$INSTALLED" ] ; then - - local LANGUAGE="$BOOT_LANGUAGE" - . /etc/grml/language-functions - # allow setting xkeyboard explicitly different than console keyboard - KXKEYBOARD="$(getbootparam 'xkeyboard' 2>>$DEBUG)" - if [ -n "$KXKEYBOARD" ]; then - XKEYBOARD="$KXKEYBOARD" - KDEKEYBOARD="$KXKEYBOARD" - elif [ -n "$KKEYBOARD" ]; then - XKEYBOARD="$KKEYBOARD" - KDEKEYBOARD="$KKEYBOARD" - fi + # export it now, so error messages get translated, too + [ -r /etc/default/locale ] && . /etc/default/locale + export LANG LANGUAGE - # duplicate of previous code to make sure /etc/grml/language-functions - # does not overwrite our values.... - # now allow keyboard override by boot commandline for later use: - KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)" - [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD" - # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead: - [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys - [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys - - # write keyboard related variables to file for later use - [ -d /etc/sysconfig ] || mkdir /etc/sysconfig - if ! [ -e /etc/sysconfig/keyboard ] ; then - echo "KEYTABLE=\"$KEYTABLE\"" > /etc/sysconfig/keyboard - echo "XKEYBOARD=\"$XKEYBOARD\"" >> /etc/sysconfig/keyboard - echo "KDEKEYBOARD=\"$KDEKEYBOARD\"" >> /etc/sysconfig/keyboard - echo "KDEKEYBOARDS=\"$KDEKEYBOARDS\"" >> /etc/sysconfig/keyboard - fi - fi + if $SYSTEMD ; then + local KEYBOARD + KEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)" + [ -n "$KEYBOARD" ] || KEYBOARD="$LANGUAGE" + # "symbols/en" doesn't exist, so rewrite to "us" + [[ "$KEYBOARD" == 'en' ]] && KEYBOARD="us" + + if [ -r /etc/default/keyboard ] ; then + sed -i "s/^XKBLAYOUT=.*/XKBLAYOUT=\"$KEYBOARD\"/" /etc/default/keyboard + + case "$KEYBOARD" in + de|at) + sed -i "s/^XKBVARIANT=.*/XKBVARIANT=\"nodeadkeys\"/" /etc/default/keyboard + ;; + esac - [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard + fi + service_wrapper console-setup restart >>$DEBUG 2>&1 ; eend $? + else # not running systemd, keeing for backwards compatibility: + # configure keyboard layout, read in already set values first: + [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard + + # now allow keyboard override by boot commandline for later use: + KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)" + [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD" + # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead: + [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys + [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys + + # modify /etc/sysconfig/keyboard only in live-cd mode: + if [ -z "$INSTALLED" ] ; then + + local LANGUAGE="$BOOT_LANGUAGE" + . /etc/grml/language-functions + # allow setting xkeyboard explicitly different than console keyboard + KXKEYBOARD="$(getbootparam 'xkeyboard' 2>>$DEBUG)" + if [ -n "$KXKEYBOARD" ]; then + XKEYBOARD="$KXKEYBOARD" + KDEKEYBOARD="$KXKEYBOARD" + elif [ -n "$KKEYBOARD" ]; then + XKEYBOARD="$KKEYBOARD" + KDEKEYBOARD="$KKEYBOARD" + fi - # activate unicode console if running within utf8 environment - if [ -r /etc/default/locale ] ; then - if grep -q "LANG=.*UTF" /etc/default/locale ; then - einfo "Setting up unicode environment." - unicode_start >>$DEBUG 2>&1 ; eend $? + # duplicate of previous code to make sure /etc/grml/language-functions + # does not overwrite our values.... + # now allow keyboard override by boot commandline for later use: + KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)" + [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD" + # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead: + [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys + [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys + + # write keyboard related variables to file for later use + [ -d /etc/sysconfig ] || mkdir /etc/sysconfig + if ! [ -e /etc/sysconfig/keyboard ] ; then + echo "KEYTABLE=\"$KEYTABLE\"" > /etc/sysconfig/keyboard + echo "XKEYBOARD=\"$XKEYBOARD\"" >> /etc/sysconfig/keyboard + echo "KDEKEYBOARD=\"$KDEKEYBOARD\"" >> /etc/sysconfig/keyboard + echo "KDEKEYBOARDS=\"$KDEKEYBOARDS\"" >> /etc/sysconfig/keyboard + fi fi - fi - # Set default keyboard before interactive setup - if [ -n "$KEYTABLE" ] ; then - einfo "Running loadkeys for ${WHITE}${KEYTABLE}${NORMAL} in background" - loadkeys -q $KEYTABLE & - eend $? - fi + [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard + fi - # we have to set up all consoles, therefore loop it over all ttys: - NUM_CONSOLES=$(fgconsole --next-available 2>/dev/null) - if [ -n "$NUM_CONSOLES" ] ; then - NUM_CONSOLES=$(expr ${NUM_CONSOLES} - 1) - [ ${NUM_CONSOLES} -eq 1 ] && NUM_CONSOLES=6 - fi - CUR_CONSOLE=$(fgconsole 2>/dev/null) - if [ -x "$(which setfont)" ] ; then - use_setfont=true - elif [ -x "$(which consolechars)" ] ; then - use_consolechars=true - else - eerror "Neither setfont nor consolechars tool present, can not set font." - eend 1 - return 1 - fi + if ! $SYSTEMD ; then + # we have to set up all consoles, therefore loop it over all ttys: + NUM_CONSOLES=$(fgconsole --next-available 2>/dev/null) + if [ -n "$NUM_CONSOLES" ] ; then + NUM_CONSOLES=$(expr ${NUM_CONSOLES} - 1) + [ ${NUM_CONSOLES} -eq 1 ] && NUM_CONSOLES=6 + fi + CUR_CONSOLE=$(fgconsole 2>/dev/null) + + if [ -x "$(which setfont)" ] ; then + use_setfont=true + elif [ -x "$(which consolechars)" ] ; then + use_consolechars=true + else + eerror "Neither setfont nor consolechars tool present, can not set font." + eend 1 + return 1 + fi - if [ -n "$CHARMAP" ] ; then - einfo "Setting font to ${CHARMAP}" - RC=0 - for vc in $(seq 0 ${NUM_CONSOLES}) ; do + if [ -n "$CHARMAP" ] ; then + einfo "Setting font to ${CHARMAP}" + RC=0 + for vc in $(seq 0 ${NUM_CONSOLES}) ; do if $use_setfont ; then setfont -C /dev/tty${vc} $CHARMAP ; RC=$? elif $use_consolechars ; then consolechars --tty=/dev/tty${vc} -m ${CHARMAP} ; RC=$? fi - done - if [ -n "$CUR_CONSOLE" ] ; then - [ "$CUR_CONSOLE" != "serial" ] && chvt $CUR_CONSOLE + done + if [ -n "$CUR_CONSOLE" ] ; then + [ "$CUR_CONSOLE" != "serial" ] && chvt $CUR_CONSOLE + fi + eend $RC fi - eend $RC - fi - if checkbootparam 'noconsolefont' ; then - ewarn "Skipping setting console font as requested on boot commandline." ; eend 0 - else - if [ -n "$CONSOLEFONT" ] ; then - einfo "Setting font to ${CONSOLEFONT}" - RC=0 - for vc in $(seq 0 ${NUM_CONSOLES}) ; do - if $use_setfont ; then - setfont -C /dev/tty${vc} ${CONSOLEFONT} ; RC=$? - elif $use_consolechars ; then - consolechars --tty=/dev/tty${vc} -f ${CONSOLEFONT} ; RC=$? - fi - done - if [ -n "$CUR_CONSOLE" ] ; then + if checkbootparam 'noconsolefont' ; then + ewarn "Skipping setting console font as requested on boot commandline." ; eend 0 + else + if [ -n "$CONSOLEFONT" ] ; then + einfo "Setting font to ${CONSOLEFONT}" + RC=0 + for vc in $(seq 0 ${NUM_CONSOLES}) ; do + if $use_setfont ; then + setfont -C /dev/tty${vc} ${CONSOLEFONT} ; RC=$? + elif $use_consolechars ; then + consolechars --tty=/dev/tty${vc} -f ${CONSOLEFONT} ; RC=$? + fi + done + if [ -n "$CUR_CONSOLE" ] ; then [ "$CUR_CONSOLE" != "serial" ] && chvt $CUR_CONSOLE - fi - eend $RC + fi + eend $RC + fi fi - fi - eoutdent + # Set default keyboard before interactive setup + if [ -n "$KEYTABLE" ] ; then + einfo "Running loadkeys for ${WHITE}${KEYTABLE}${NORMAL} in background" + loadkeys -q $KEYTABLE & + eend $? + fi + + # activate unicode console if running within utf8 environment + if [ -r /etc/default/locale ] ; then + if grep -q "LANG=.*UTF" /etc/default/locale ; then + einfo "Setting up unicode environment." + unicode_start ; eend $? + fi + fi + fi # not running systemd + + eoutdent } # }}} @@ -540,6 +539,44 @@ config_kernel(){ } # }}} +# {{{ secure boot +# 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) + if ! $SYSTEMD ; then + if modprobe efivarfs &>/dev/null ; then + mount -t efivarfs efivarfs /sys/firmware/efi/efivars + fi + fi + + if [[ -x "$(command -v mokutil)" ]] ; then + if mokutil --sb-state 2>/dev/null | grep -q 'SecureBoot enabled' ; then + return 0 + else + return 1 + fi + else + if modprobe efivarfs &>/dev/null ; then + if od -An -t u1 /sys/firmware/efi/vars/SecureBoot-*/data 2>/dev/null | grep -q 1 ; then + return 0 + else + 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 config_timezone(){ # don't touch the files if running from harddisk: @@ -569,6 +606,11 @@ config_timezone(){ # activate serial console {{{ config_console(){ if checkbootparam 'console'; then + # this hack is no longer necessary with systemd + if $SYSTEMD ; then + return + fi + local line local ws ws=' ' @@ -742,7 +784,8 @@ fi # {{{ Start brltty config_brltty() { if checkbootparam 'brltty' ; then - [ -x /lib/brltty/brltty.sh ] && /lib/brltty/brltty.sh + einfo "Starting brltty service as requested on boot commandline." + service_wrapper brltty start ; eend $? fi } # }}} @@ -862,76 +905,23 @@ fi # -z $INSTALLED # {{{ CPU-detection config_cpu(){ -if checkbootparam 'nocpu'; then - ewarn "Skipping CPU detection as requested on boot commandline." ; eend 0 - return 0 -fi - -if [[ $(grep -c processor /proc/cpuinfo) -gt 1 ]] ; then - einfo "Found CPU:" - CPU=$(awk -F: '/^processor/{printf " Processor"$2" is"};/^model name/{printf $2};/^vendor_id/{printf vendor};/^cpu MHz/{printf " %dMHz",int($2)};/^cache size/{printf ","$2" Cache"};/^$/{print ""}' /proc/cpuinfo 2>>$DEBUG) - echo $CPU | sed 's/ \{1,\}/ /g' - eend 0 -else - einfo "Found CPU: `awk -F: '/^processor/{printf " Processor"$2" is"};/^model name/{printf $2};/^vendor_id/{printf vendor};/^cpu MHz/{printf " %dMHz",int($2)};/^cache size/{printf ","$2" Cache"};/^$/{print ""}' /proc/cpuinfo 2>>$DEBUG` " ; eend 0 -fi - -# no cpufreq setup inside VirtualBox -if $VIRTUALBOX ; then - einfo 'Virtual Box detected, skipping cpufreq setup.' ; eend 0 - return 0 -fi + if checkbootparam 'nocpu'; then + ewarn "Skipping CPU detection as requested on boot commandline." ; eend 0 + return 0 + fi -if ! [ -x /etc/init.d/loadcpufreq ] ; then - ewarn "loadcpufreq init script not available, ignoring cpu frequency scaling." - eend 0 - return 0 -else - einfo "Trying to set up cpu frequency scaling:" - eindent - SKIP_CPU_GOVERNOR='' - LOADCPUFREQ=$(mktemp) - /etc/init.d/loadcpufreq start >"$LOADCPUFREQ" 2>&1 ; RC=$? - if grep -q FATAL "$LOADCPUFREQ" ; then - eindent - SKIP_CPU_GOVERNOR=1 - oldIFS="$IFS" - IFS=" -" - for line in $(grep FATAL "$LOADCPUFREQ" | sed 's/.*FATAL: //; s/ (.*)//') ; do - eerror "$line" ; eend $RC - done - IFS="$oldIFS" - eoutdent - elif grep -q done "$LOADCPUFREQ" ; then - MODULE=$(grep done "$LOADCPUFREQ" | sed 's/.*done (\(.*\))./\1/') - if [ -n "$MODULE" -a "$MODULE" != none ]; then - einfo "Loading cpufreq kernel module $MODULE" ; eend 0 - else - SKIP_CPU_GOVERNOR=1 - ewarn "Could not find an appropriate kernel module for cpu frequency scaling." ; eend 1 - fi - fi + if ! [ -x "$(which lscpu)" ] ; then + ewarn "Skipping CPU detection due to lack of lscpu."; eend 0 + return 0 + fi - rm -f "$LOADCPUFREQ" + local cpu_info num_cpus - if [ -z "$SKIP_CPU_GOVERNOR" ] ; then - if [ -r /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors ] ; then - if ! grep -q ondemand /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors ; then - einfo "Ondemand governor not available for CPU(s), not modifying governor configuration" - else - einfo "Setting ondemand governor" - RC=0 - for file in $(find /sys/devices/system/cpu/ -name scaling_governor 2>/dev/null) ; do - echo ondemand > $file || RC=1 - done - eend $RC - fi - fi - fi + cpu_info="$(lscpu | sed -n '/^Model name:/s/[^:]*:\s*//p')" + num_cpus=$(grep -c processor /proc/cpuinfo) - eoutdent -fi + einfo "Found ${num_cpus} CPU(s): ${cpu_info}" + eend 0 } # }}} @@ -966,8 +956,9 @@ if checkbootparam 'ssh' ; then fi einfo "Starting secure shell server in background for root and user $localuser" + service_wrapper haveged start >>$DEBUG 2>>$DEBUG service_wrapper rmnologin start >>$DEBUG 2>>$DEBUG - service_wrapper ssh start >>$DEBUG 2>>$DEBUG & + service_wrapper ssh start background >>$DEBUG 2>>$DEBUG eend $? fi @@ -1111,83 +1102,82 @@ fi # {{{ Sound config_mixer () { - if ! [ -x /usr/bin/amixer ] ; then - eerror "amixer binary not available. Can not set sound volumes therefore." - eend 1 - else - if ! [ -r /proc/asound/cards ] ; then - ewarn "No soundcard present, skipping mixer settings therefore." - eend 0 - return + if ! [ -x /usr/bin/amixer ] ; then + logger -t grml-autoconfig "amixer binary not available" + return + fi + + if ! [ -r /proc/asound/cards ] ; then + ewarn "No soundcard present, skipping mixer settings therefore." + eend 0 + return + fi + + for card in $(cat /proc/asound/cards| grep -e '^\s*[0-9]' | awk '{print $1}') ; do + einfo "Configuring soundcard \"$(awk -F\[ '/^ *'$card' \[/{ FS=" "; $0=$2; print $1}' < /proc/asound/cards)\"" + eindent + + if checkbootparam 'vol' ; then + VOL="$(getbootparam 'vol' 2>>$DEBUG)" + if [ -z "$VOL" ] ; then + eerror "Bootoption vol found but no volume level/parameter given. Using defaults (75%)." + VOL='75' + eend 1 fi + else + VOL='75' + fi - for card in $(cat /proc/asound/cards| grep -e '^\s*[0-9]' | awk '{print $1}') ; do - einfo "Configuring soundcard \"$(awk -F\[ '/^ *'$card' \[/{ FS=" "; $0=$2; print $1}' < /proc/asound/cards)\"" - eindent + if checkbootparam 'nosound' ; then + einfo "Muting sound devices on request." + ERROR=$(amixer -q set Master mute) + RC=$? + if [ -n "$ERROR" ] ; then + eindent + eerror "Problem muting sound devices: $ERROR" + eoutdent + fi + eend $RC + elif [ -z "$INSTALLED" ] ; then + einfo "Setting mixer volumes to level ${WHITE}${VOL}${NORMAL}." - if checkbootparam 'vol' ; then - VOL="$(getbootparam 'vol' 2>>$DEBUG)" - if [ -z "$VOL" ] ; then - eerror "Bootoption vol found but no volume level/parameter given. Using defaults (75%)." - VOL='75' - eend 1 - fi - else - VOL='75' - fi - - if checkbootparam 'nosound' ; then - einfo "Muting sound devices on request." - ERROR=$(amixer -q set Master mute) - RC=$? - if [ -n "$ERROR" ] ; then - eindent - eerror "Problem muting sound devices: $ERROR" - eoutdent - fi - eend $RC - elif [ -z "$INSTALLED" ] ; then - einfo "Setting mixer volumes to level ${WHITE}${VOL}${NORMAL}." + if checkbootparam 'micvol' ; then + MICVOL="$(getbootparam 'micvol' 2>>$DEBUG)" + einfo "Setting microphone to ${WHITE}${MICVOL}${NORMAL}." + else + MICVOL=0 + fi - if checkbootparam 'micvol' ; then - MICVOL="$(getbootparam 'micvol' 2>>$DEBUG)" - einfo "Setting microphone to ${WHITE}${MICVOL}${NORMAL}." - else - MICVOL=0 - fi + CONTROLS=$(amixer -c $card scontrols | awk -F"Simple mixer control " '{print $2}') + IFSOLD=${IFS:-} + IFS=$'\n' + for CONTROL in ${=CONTROLS} ; do + # such devices can not be controlled with amixer ... unmute + [[ "$CONTROL" == *Console* ]] && continue - CONTROLS=$(amixer -c $card scontrols | awk -F"Simple mixer control " '{print $2}') - IFSOLD=${IFS:-} - IFS=' -' - for CONTROL in ${=CONTROLS} ; do - # such devices can not be controlled with amixer ... unmute - [[ "$CONTROL" == *Console* ]] && continue - - if ! echo "${CONTROL}" | grep -q -i "mic" ; then - if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*pswitch' ; then - amixer -c $card -q set "${CONTROL}" unmute - fi - if amixer -c $card sget "${CONTROL}" | grep -q -P 'Capabilities:.*(pvolume| volume)' ; then - amixer -c $card -q set "${CONTROL}" "${VOL}"% - fi - fi + if ! echo "${CONTROL}" | grep -q -i "mic" ; then + if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*pswitch' ; then + amixer -c $card -q set "${CONTROL}" unmute + fi + if amixer -c $card sget "${CONTROL}" | grep -q -P 'Capabilities:.*(pvolume| volume)' ; then + amixer -c $card -q set "${CONTROL}" "${VOL}"% + fi + fi - if [ ${MICVOL} -ne 0 ] ; then - if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*cswitch' ; then - amixer -c $card -q set "${CONTROL}" unmute - fi - if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*cvolume' ; then - amixer -c $card -q set "${CONTROL}" $MICVOL% - fi - eend $? - fi - done - IFS=$IFSOLD - fi # checkbootparam 'nosound' - eoutdent + if [ ${MICVOL} -ne 0 ] ; then + if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*cswitch' ; then + amixer -c $card -q set "${CONTROL}" unmute + fi + if amixer -c $card sget "${CONTROL}" | grep -q 'Capabilities:.*cvolume' ; then + amixer -c $card -q set "${CONTROL}" $MICVOL% + fi + eend $? + fi done - fi + IFS=$IFSOLD + fi # checkbootparam 'nosound' + eoutdent + done } # }}} @@ -1197,7 +1187,7 @@ config_syslog(){ ewarn "Not starting syslog daemon as requested on boot commandline." ; eend 0 else einfo "Starting rsyslog in background." - service_wrapper rsyslog start >>$DEBUG & + service_wrapper rsyslog start >>$DEBUG eend 0 fi } @@ -1205,18 +1195,17 @@ config_syslog(){ # {{{ gpm config_gpm(){ - if checkbootparam 'nogpm'; then - ewarn "Not starting GPM as requested on boot commandline." ; eend 0 - else - if ! [ -r /dev/input/mice ] ; then + if checkbootparam 'nogpm'; then + ewarn "Not starting GPM as requested on boot commandline." ; eend 0 + else + if ! [ -r /dev/input/mice ] ; then eerror "No mouse found - not starting GPM." ; eend 1 - else + else einfo "Starting gpm in background." - service_wrapper gpm start >>$DEBUG & - # ( while [ ! -e /dev/psaux ]; do sleep 5; done; /etc/init.d/gpm start >>$DEBUG ) & + service_wrapper gpm start background >>$DEBUG eend 0 - fi - fi + fi + fi } # }}} @@ -1234,7 +1223,7 @@ config_services(){ service_wrapper "${service}" start >>$DEBUG else einfo "Starting service ${service} in background." - service_wrapper "${service}" start >>$DEBUG & + service_wrapper "${service}" start background >>$DEBUG fi done eend $? @@ -1305,42 +1294,9 @@ config_netscript() { } # }}} -# {{{ stats -config_stats() { - if ! checkbootparam 'nostats' ; then - BASE_URL="http://stats.grml.org/report/" - ACTION_NAME=Boot - - HOST_ID=$(cat /proc/sys/kernel/random/boot_id) - - grep -q " lm " /proc/cpuinfo && HAS_64BIT="1" || HAS_64BIT="0" - DATE_STRING=$(date +'h=%H&m=%M&s=%S') - [ -e /etc/grml_version ] && VERSION=$(cat /etc/grml_version) || \ - VERSION=$(lsb_release -d | awk -F: '{gsub(/^[ \t]+/, "", $2); print $2}') - - PARAMS="$( echo "$CMDLINE" | sed -e 's/=[^ ]*/=x/g' | tr " " "\n"|sort|tr "\n" " " )" - - echo "$CMDLINE" | grep -q -e "fetch" -e "nfsroot" && BOOT="remote" - [ -z "$BOOT" ] && BOOT="local" - - ADDITIONAL_PARAMS="" - ( [ -n "$COLUMNS" ] && [ -n "$LINES" ] ) && \ - ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS&res=$((COLUMNS * 8))x$((LINES * 16))" - - URI='$BASE_URL?action=${ACTION_NAME}\&$DATE_STRING\&unique_id=${HOST_ID}\&support_64bit=$HAS_64BIT\&version=$VERSION\&bootup=$BOOT\¶ms=$PARAMS$ADDITIONAL_PARAMS' - - get_remote_file "$URI" "/dev/null" >/dev/null 2>&1 &! - fi -} -# }}} - # {{{ start X window system via grml-x config_x_startup(){ - if $SYSTEMD ; then - ewarn "The startx boot option isn't yet supported via systemd, sorry." ; eend 0 - return - fi # make sure we start X only if startx is used *before* a nostartx option # so it's possible to disable automatic X startup using nostart @@ -1355,17 +1311,25 @@ if checkbootparam 'startx' && ! echo "$CMDLINE" | grep -q 'startx.*nostartx' ; t fi einfo "Setting up and invoking grml-x ${WINDOWMANAGER}. Just exit X windows system to get full featured consoles." config_userlocal - cat>|/etc/init.d/xstartup< /var/run/grml-x/window-manager + fi + chvt 7 + return + fi + cat>|/etc/init.d/startx</dev/tty6 2>\&1 /dev/tty6 2>\&1 /dev/tty6 2>&1 < /dev/tty6' >> /etc/inittab + echo '6:2345:respawn:/bin/zsh --login -c "/etc/init.d/startx ; /usr/share/grml-scripts/run-welcome" >/dev/tty6 2>&1 < /dev/tty6' >> /etc/inittab fi /sbin/telinit q ; eend $? @@ -1448,7 +1412,7 @@ else else eindent einfo "debs, config, scripts are read from $DCSDEVICE." ; eend 0 - DCSDIR="$(< /proc/mounts awk -v DCSDEV=$DCSDEVICE '{if ($1 == DCSDEV) { print $2 }}')" + DCSDIR="$(< /proc/mounts awk -v DCSDEV=$DCSDEVICE '{if ($1 == DCSDEV) { print $2; exit }}')" if [ -n "$DCSDIR" ]; then ewarn "$DCSDEVICE already mounted on $DCSDIR"; eend 0 else @@ -1623,15 +1587,18 @@ config_swraid(){ if ! checkbootparam 'swraid' ; then eindent - einfo "Just run 'Start mdadm-raid' to assemble md arrays or boot using 'swraid' as bootoption for autostart." + if $SYSTEMD ; then + einfo "Just run 'mdadm --assemble --scan' to assemble md arrays or boot using 'swraid' as bootoption for autostart." + else + einfo "Just run 'Start mdadm-raid' to assemble md arrays or boot using 'swraid' as bootoption for autostart." + fi eoutdent else einfo "Bootoption swraid found. Searching for software RAID arrays:" eindent IFSOLD=${IFS:-} - IFS=' -' - for line in $(mdadm --assemble --scan --auto=yes --symlink=no 2>&1) ; do + IFS=$'\n' + for line in $(mdadm --assemble --scan 2>&1) ; do case $line in *'No arrays found'*) ewarn "$line" ; eend 0 @@ -1651,8 +1618,7 @@ config_swraid(){ ewarn "No active arrays found" ; eend 0 else IFSOLD=${IFS:-} - IFS=' -' + IFS=$'\n' for line in $(grep '^md[0-9]' /proc/mdstat) ; do einfo "active arrays: $line" ; eend 0 done @@ -1667,76 +1633,6 @@ config_swraid(){ } # }}} -# {{{ dmraid -config_dmraid(){ - [ -n "$INSTALLED" ] && return 0 - - if checkbootparam 'nodmraid' ; then - ewarn "Skipping dmraid code as requested on boot commandline." ; eend 0 - return 0 - fi - - if ! [ -x /sbin/dmraid ] ; then - eerror "dmraid not available, can not execute it." ; eend 1 - return - fi - - dmraid_wrapper() { - # usage: dmraid_wrapper - [ -n "$1" ] || return 1 - - IFSOLD=${IFS:-} - IFS=' -' - eindent - - for line in $(dmraid $1 ; echo errcode:$?); do - case $line in - *'no block devices found'*) - einfo "No block devices found" ; eend 0 - break - ;; - *'no raid disks'*) - einfo "No active dmraid devices found" ; eend 0 - break - ;; - errcode:0) - eend 0; - ;; - errcode:1) - eend 1 - ;; - *) - einfo "$line" - ;; - esac - done - - eoutdent - IFS=$IFSOLD - } - - if checkbootparam 'dmraid' ; then - local ACTION="$(getbootparam 'dmraid' 2>>$DEBUG)" - if [ "$ACTION" = "off" ] ; then - # Deactivates all active software RAID sets: - einfo "Deactivating present dmraid sets (as requested via dmraid=off):" - dmraid_wrapper -an - else - # Activate all software RAID sets discovered: - einfo "Activating present dmraid sets (as requested via dmraid):" - dmraid_wrapper -ay - fi - - return - fi - - # by default (no special bootoptions) discover all software RAID devices: - einfo "Searching for any present dmraid sets:" - dmraid_wrapper -r -} -# }}} - # {{{ LVM (Logical Volumes) config_lvm(){ [ -n "$INSTALLED" ] && return 0 @@ -1750,11 +1646,27 @@ config_lvm(){ if lvdisplay 2>&1 | grep -v 'No volume groups found' >/dev/null 2>&1 ; then einfo "You seem to have logical volumes (LVM) on your system." eindent - einfo "Just run 'Start lvm2' to activate them or boot using 'lvm' as bootoption for autostart." + if $SYSTEMD ; then + einfo "Just run 'Start lvm2-pvscan@name' to activate LV or VG 'name' or boot using 'lvm' as bootoption for autostart." + else + einfo "Just run 'Start lvm2' to activate them or boot using 'lvm' as bootoption for autostart." + fi eend 0 if checkbootparam 'lvm' ; then - einfo "Bootoption LVM found. Searching for logical volumes:" - service_wrapper lvm2 start ; eend $? + if $SYSTEMD ; then + 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 eoutdent fi @@ -1875,16 +1787,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 @@ -1897,8 +1815,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." @@ -1910,7 +1828,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 @@ -1959,9 +1877,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 $? } # }}} @@ -1970,7 +1915,6 @@ config_distri(){ if checkbootparam 'distri'; then DISTRI="$(getbootparam 'distri' 2>>$DEBUG)" if [ -r "${LIVECD_PATH}"/desktop/"$DISTRI".jpg ] ; then - [ -n "$BOOTDEBUG" ] && einfo "Debug: bootoption distri found and file ${LIVECD_PATH}/desktop/${DISTRI} present" && eend 0 # make sure the desktop.jpg file is not a symlink, so copying does not file then [ -L /usr/share/grml/desktop.jpg ] && rm /usr/share/grml/desktop.jpg cp "${LIVECD_PATH}"/desktop/"$DISTRI".jpg /usr/share/grml/desktop.jpg @@ -1979,5 +1923,43 @@ fi } # }}} +# {{{ Easteregg (for 20 years grml.org) +display_easteregg() { + einfo "You found the birthday easter egg!" ; eend 0 + + if [[ -x /bin/toilet && -x /usr/games/lolcat ]] ; then + visualize() { printf "%s\n" "$*" | toilet | /usr/games/lolcat ; } + elif [[ -x /bin/toilet ]] ; then + visualize() { printf "%s\n" "$*" | toilet ; } + else + visualize() { printf "%s\n" "$*" ; } + fi + + visualize " \o/ " + visualize "20 years" + visualize "grml.org" +} + +config_easteregg() { + checkbootparam 'noeasteregg' && return 0 + + zmodload zsh/datetime 2>/dev/null || return 0 + zmodload zsh/mathfunc 2>/dev/null || return 0 + + local birthday=1694822400 # := 2023-09-16 -> TZ=UTC date -d "2023-09-16" +%s + local one_month=$[24*30*3600] + local pi=3.14159265358979323846 + local magic=$(( one_month/(pi/2) )) # normalization factor, used to map the [birthday;birthday+-one_month] range onto [0;+-pi/2] + + if [[ $(( abs(birthday-EPOCHSECONDS) )) -le $one_month ]] ; then + if [[ $(( rand48() )) -le $(( cos((birthday-EPOCHSECONDS)/magic) )) ]] ; then + display_easteregg + fi + fi + + return 0 +} +# }}} + ## END OF FILE ################################################################# # vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=2