X-Git-Url: https://git.grml.org/?p=grml-autoconfig.git;a=blobdiff_plain;f=autoconfig.functions;h=e4fe0eb0ba0782a0eab0506244d1405fd48c8bec;hp=a9aeca8f965216fc2cd1b9d093f10a5d1d43048a;hb=b9e2bd50c1b33dd544d0c0ddacc58376bdc3c0f3;hpb=557d36bf847cfdd7208cde5b577dcea8578a876c diff --git a/autoconfig.functions b/autoconfig.functions index a9aeca8..e4fe0eb 100755 --- a/autoconfig.functions +++ b/autoconfig.functions @@ -32,6 +32,16 @@ fi iszsh && setopt no_nomatch # || echo "Warning: not running under zsh!" # }}} +# {{{ Read in boot parameters +if [ -z "$CMDLINE" ]; then + # if CMDLINE was set from the outside, we're debugging. Otherwise, take + # CMDLINE from Kernel and config files + CMDLINE="$(cat /proc/cmdline)" + [ -d /cdrom/bootparams/ ] && CMDLINE="$CMDLINE $(cat /cdrom/bootparams/* | tr '\n' ' ')" + [ -d /live/image/bootparams/ ] && CMDLINE="$CMDLINE $(cat /live/image/bootparams/* | tr '\n' ' ')" +fi +# }}} + ### {{{ Utility Functions # Simple shell grep @@ -49,7 +59,7 @@ stringinstring(){ # Reread boot command line; echo last parameter's argument or return false. getbootparam(){ stringinstring " $1=" "$CMDLINE" || return 1 - result="${CMDLINE##*$1=}" + result="${CMDLINE##* $1=}" result="${result%%[ ]*}" echo "$result" return 0 @@ -97,12 +107,6 @@ mount_sys(){ } # }}} -# {{{ Read in boot parameters -[ -f /proc/version ] || mount_proc # make sure we can access /proc/cmdline when sourcing this file too -CMDLINE="$(cat /proc/cmdline)" -[ -d "${LIVECD_PATH}"/bootparams/ ] && CMDLINE="$CMDLINE $(cat ${LIVECD_PATH}/bootparams/* | tr '\n' ' ')" -# }}} - # {{{ Check if we are running from the grml-CD or HD INSTALLED="" [ -e /etc/grml_cd ] || INSTALLED="yes" @@ -362,21 +366,28 @@ config_time(){ if [ -z "$INSTALLED" ]; then # The default hardware clock timezone is stated as representing local time. UTC="--localtime" - checkbootparam utc >>$DEBUG 2>&1 && UTC="-u" - checkbootparam gmt >>$DEBUG 2>&1 && UTC="-u" + grep -q "^UTC=" /etc/default/rcS || echo "UTC=no" >> /etc/default/rcS + checkbootparam utc >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=yes|" /etc/default/rcS + checkbootparam gmt >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=yes|" /etc/default/rcS + checkbootparam localtime >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=no|" /etc/default/rcS + grep -q -i "^UTC=yes" /etc/default/rcS && UTC="-u" # hwclock uses the TZ variable KTZ="$(getbootparam tz 2>>$DEBUG)" [ -z "$KTZ" ] && [ -r /etc/timezone ] && KTZ=$(cat /etc/timezone) - [ -z "$KTZ" ] && KTZ=Europe/Vienna + if [ ! -f "/usr/share/zoneinfo/$KTZ" ] ; then + ewarn "Warning: unknown timezone $KTZ" ; eend 1 + KTZ="Europe/Vienna" + ewarn "Falling back to timezone $KTZ" ; eend 0 + fi if ! [ -r /dev/rtc ] ; then ewarn "Warning: realtime clock not available, trying to execute hwclock anyway." ; eend 0 fi - ERROR=$(TZ="$TZ" hwclock $UTC -s 2>&1 | head -1) ; RC=$? + ERROR=$(TZ="$KTZ" hwclock $UTC -s 2>&1 | head -1) ; RC=$? if [ -n "$ERROR" ] ; then eindent - ERROR=$(TZ="$TZ" hwclock $UTC -s --directisa 2>&1 | head -1) + ERROR=$(TZ="$KTZ" hwclock $UTC -s --directisa 2>&1 | head -1) if [ -n "$ERROR" ] ; then eerror "Problem running hwclock: $ERROR" ; eend 1 fi @@ -465,10 +476,21 @@ config_timezone(){ if [ -z "$INSTALLED" ]; then KTZ="$(getbootparam tz 2>>$DEBUG)" if [ -n "$KTZ" ] ; then - einfo "Setting timezone." - [ -f "/usr/share/zoneinfo/$KTZ" ] && TZ="$KTZ" - rm -f /etc/localtime - cp "/usr/share/zoneinfo/$TZ" /etc/localtime ; eend $? + if [ ! -f "/usr/share/zoneinfo/$KTZ" ] + then + ewarn "Warning: unknown timezone $KTZ"; eend 0 + else + einfo "Setting timezone." + # update debconf + area=$(echo $KTZ | cut -d '/' -f1) + zone=$(echo $KTZ | cut -d '/' -f2) + echo "tzdata tzdata/Areas select $area" | debconf-set-selections + echo "tzdata tzdata/Zones/$area select $zone" | debconf-set-selections + # update files + echo $KTZ > /etc/timezone + rm -f /etc/localtime + cp "/usr/share/zoneinfo/$KTZ" /etc/localtime ; eend $? + fi fi fi } @@ -523,8 +545,8 @@ eoutdent # skip startup of w3m {{{ config_fast(){ -if checkbootparam "fast"; then - ewarn "Bootoption fast detected. Skipping startup of w3m." +if checkbootparam "fast "; then + ewarn "Bootoption fast detected. Skipping startup of grml-quickconfig." sed -i 's#^1:.*#1:12345:respawn:/usr/bin/openvt -f -c 1 -w -- /bin/zsh#' /etc/inittab /sbin/telinit q ; eend $? fi @@ -721,13 +743,14 @@ if checkbootparam "blacklist" ; then if [ -z "$INSTALLED" ]; then einfo "Bootoption blacklist found." BLACK="$(getbootparam 'blacklist' 2>>$DEBUG)" + BLACKLIST_FILE='/etc/modprobe.d/grml.conf' if [ -n "$BLACK" ] ; then for module in $(echo ${BLACK//,/ }) ; do - einfo "Blacklisting module ${module} via /etc/modprobe.d/grml." - echo "# begin entry generated by config_blacklist of grml-autoconfig" >> /etc/modprobe.d/grml - echo "blacklist $module" >> /etc/modprobe.d/grml - echo "alias $module off" >> /etc/modprobe.d/grml - echo "# end entry generated by config_blacklist of grml-autoconfig" >> /etc/modprobe.d/grml ; eend $? + einfo "Blacklisting module ${module} via ${BLACKLIST_FILE}." + echo "# begin entry generated by config_blacklist of grml-autoconfig" >> "$BLACKLIST_FILE" + echo "blacklist $module" >> "$BLACKLIST_FILE" + echo "alias $module off" >> "$BLACKLIST_FILE" + echo "# end entry generated by config_blacklist of grml-autoconfig" >> "$BLACKLIST_FILE" ; eend $? done else eerror "No given module for blacklist found. Blacklisting will not work therefore." @@ -863,19 +886,48 @@ config_swspeak(){ # {{{ support hardware synthesizer via speakup config_hwspeak(){ - if checkbootparam hwspeak ; then + if checkbootparam speakup.synth ; then + einfo "Bootoption speakup.synth found." + eindent + + module="$(getbootparam speakup.synth 2>>$DEBUG)" + if [ -z "$module" ] ; then + eerror "Sorry, no speakup module specified for bootoption speakup.synth." + flitewrapper "Sorry, no speakup module specified for bootoption speakup.synth." + else + einfo "Trying to load $module" + modprobe "speakup_${module}" + eend $? + fi + + if [ -d /proc/speakup/ ] || grep -q speakup /proc/modules ; then + einfo "Kernel should support speakup now." ; eend 0 + flitewrapper "Kernel should support speakup now." + else + eerror "Kernel or hardware do not seem to support speakup. Skipping hwspeak." ; eend 1 + flitewrapper "Kernel or hardware do not seem to support speakup. Sorry." + fi + + eoutdent + + # hwspeak: + elif checkbootparam hwspeak ; then einfo "Bootoption hwspeak found." if [ ! -d /proc/speakup/ ] && ! grep -q speakup /proc/modules ; then - ewarn" Kernel does not support hardware speakup - trying to load kernel modules:" ; eend 0 + ewarn "Kernel does not support hardware speakup - trying to load kernel modules:" ; eend 0 eindent - for module in $(find "/lib/modules/${KERNEL}/extra/speakup/" -name \*.ko | \ - sed 's#.*speakup/##g ; s#.ko$##g' | \ - grep -ve speakup_soft -ve speakup_dummy | sort -u) ; do - einfo "Trying to load $module" - modprobe $module - eend $? - done + if ! [ -d "/lib/modules/${KERNEL}/extra/speakup/" ] ; then + eerror "Kernel does not provide speakup modules, sorry." ; eend 1 + else + for module in $(find "/lib/modules/${KERNEL}/extra/speakup/" -name \*.ko | \ + sed 's#.*speakup/##g ; s#.ko$##g' | \ + grep -ve speakup_soft -ve speakup_dummy | sort -u) ; do + einfo "Trying to load $module" + modprobe $module + eend $? + done + fi eoutdent fi @@ -1417,7 +1469,12 @@ if checkbootparam ssh ; then # finally check if we have a password we can use: if [ -n "$SSH_PASSWD" ] ; then - echo "grml:$SSH_PASSWD" | chpasswd -m + # chpasswd sucks, seriously. + if chpasswd --help 2>&1 | grep -q -- '-m,' ; then + echo "grml:$SSH_PASSWD" | chpasswd -m + else + echo "grml:$SSH_PASSWD" | chpasswd + fi fi einfo 'Starting secure shell server in background.' @@ -1534,6 +1591,8 @@ fi # checkbootparam home # }}} # {{{ Check for scripts on CD-ROM +# this is also executed when the scripts option is called. Is this a bug +# or intended? config_cdrom_scripts(){ if checkbootparam "script"; then for script in "${LIVECD_PATH}"/scripts/* ; do @@ -1804,7 +1863,9 @@ create_mnt_dirs(){ # {{{ start X window system via grml-x config_x_startup(){ -if checkbootparam startx ; then +# 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 +if checkbootparam startx && ! grep -q 'startx.*nostartx' "$CMDLINE" ; then if [ -x /usr/X11R6/bin/X ] ; then if [ -z "$INSTALLED" ] ; then WINDOWMANAGER="$(getbootparam 'startx' 2>>$DEBUG)" @@ -1839,12 +1900,12 @@ EOF fi else - eerror "We are not running from CD - startx will not work, skipping it. - Please use something like xdm, gdm or kdm for starting X on a harddisk system!" ; eend 1 + eerror "We are not running from CD - startx will not work, skipping it." + eerror " -> Please use something like xdm, gdm or kdm for starting X on a harddisk system!" ; eend 1 fi else - eerror "/usr/X11R6/bin/X is not present on this grml flavour. - Boot parameter startx does not work therefore." ; eend 1 + eerror "/usr/X11R6/bin/X is not present on this grml flavour." + eerror " -> Boot parameter startx does not work therefore." ; eend 1 fi fi } @@ -1858,104 +1919,65 @@ if checkbootparam extract ; then fi } -config_automount(){ +config_finddcsdir() { +# - If no GRMLCFG partition is found and noautoconfig is _not_ given +# on the command line, nothing is changed and the dcs files are +# searched within the .iso, $dcs-dir is set to the root directory +# within the .iso +# - If a GRMLCFG partition is found, $dcs-dir is set to the root of +# the GRMLCFG partition unless noautoconfig is set. If noautoconfig is +# set, $dcs-dir is set to the root directory within the .iso. +# - If myconfig=foo is set on the command line, $dcs-dir is set to +# foo, even if a GRMLCFG partition is present. +DCSDIR="" if checkbootparam noautoconfig || checkbootparam forensic ; then ewarn "Skipping running automount of device(s) labeled GRMLCFG as requested." ; eend 0 else - if [ -z "$INSTALLED" ] ; then - einfo "Searching for device(s) labeled with GRMLCFG. (Disable this via boot option: noautoconfig)" ; eend 0 - eindent - [ -d /mnt/grml ] || mkdir /mnt/grml - umount /mnt/grml 1>>$DEBUG 2>&1 # make sure it is not mounted -# We do need the following fix so floppy disk is available to blkid in any case :-/ - if [ -r /dev/fd0 ] ; then - einfo "Floppy device detected. Trying to access floppy disk." -# dd if=/dev/fd0 of=/dev/null bs=512 count=1 1>>$DEBUG 2>&1 - if timeout 4 dd if=/dev/fd0 of=/dev/null bs=512 count=1 1>>$DEBUG 2>&1 ; then - blkid /dev/fd0 1>>$DEBUG 2>&1 - fi - fi - DEVICE=$(blkid -t LABEL=GRMLCFG | head -1 | awk -F: '{print $1}') - [ -n "$DEVICE" ] && mount -t auto -o ro $DEVICE /mnt/grml ; RC="$?" - if [[ $RC == 0 ]]; then - einfo "Mounting device $DEVICE labeled GRMLCFG succeeded." ; eend 0 - - CONFIG='' - CONFIG="$(/bin/ls -1d /mnt/grml/[Cc][Oo][Nn][Ff][Ii][Gg].[Tt][Bb][Zz] 2>>$DEBUG)" - if [ -n "$CONFIG" ]; then - einfo "Found file ${WHITE}${CONFIG}${NORMAL} - trying to extract it." - cd / - unp $CONFIG $EXTRACTOPTIONS ; eend $? - else - ewarn "Sorry, could not find file config.tbz on device with label GRMLCFG." ; eend 1 + if [ -z "$INSTALLED" ] ; then + if checkbootparam myconfig ; then + DCSDEVICE="$(getbootparam 'myconfig' 2>>$DEBUG)" + if [ -z "$DCSDEVICE" ]; then + einfo "No device for bootoption myconfig provided." ; eend 1 + fi # [ -z "$DCSDEVICE" ] + elif checkvalue $CONFIG_MYCONFIG; then # checkbootparam myconfig + einfo "Searching for device(s) labeled with GRMLCFG. (Disable this via boot option: noautoconfig)" ; eend 0 + eindent + # We do need the following fix so floppy disk is available to blkid in any case :-/ + if [ -r /dev/fd0 ] ; then + einfo "Floppy device detected. Trying to access floppy disk." + if timeout 4 dd if=/dev/fd0 of=/dev/null bs=512 count=1 1>>$DEBUG 2>&1 ; then + blkid /dev/fd0 1>>$DEBUG 2>&1 + fi + fi + DCSDEVICE=$(blkid -t LABEL=GRMLCFG | head -1 | awk -F: '{print $1}') fi - - SCRIPT='' - SCRIPT="$(/bin/ls -1d /mnt/grml/[Gg][Rr][Mm][Ll].[Ss][Hh] 2>>$DEBUG)" - if [ -n "$SCRIPT" ]; then - einfo "Found script ${WHITE}${SCRIPT}${NORMAL} - trying to execute it." - $SCRIPT ; eend $? + if [ -n "$DCSDEVICE" ]; then + einfo "debs, config, scripts are read from $DCSDEVICE." ; eend 0 + DCSDIR="$(< /proc/mounts awk -v DCSDEV=$DCSDEVICE '{if ($1 == DCSDEV) { print $2 }}')" + if [ -n "$DCSDIR" ]; then + einfo "$DCSDEVICE already mounted on $DCSDIR"; eend 0 + else + [ -d /mnt/grml ] || mkdir /mnt/grml + umount /mnt/grml 1>>$DEBUG 2>&1 # make sure it is not mounted + mount -o ro -t auto $MOUNTDEVICE /mnt/grml ; RC="$?" + if [[ $RC == 0 ]]; then + einfo "Successfully mounted $DCSDEVICE to /mnt/grml (readonly)." ; eend 0 + eindent + fi + DCSDIR="/mnt/grml" + fi fi - grep -q '/mnt/grml' /proc/mounts && umount /mnt/grml - else - ewarn "No devices with label GRMLCFG found." ; eend 0 fi - eoutdent - fi +fi +if [ -n "$DCSDIR" ]; then + einfo "Debs, config, scripts will be read from $DCSDIR." ; eend 0 +else + einfo "Debs, config, scripts will be read from the CD image directly." ; eend 0 fi } -config_myconfig(){ - -if checkbootparam "config" ; then - CONFIG="$(getbootparam 'config' 2>>$DEBUG)" - [ -z "$CONFIG" ] && CONFIG='config.tbz' - einfo "Bootoption config found. config is set to: $CONFIG" - eindent - einfo "Trying to extract configuration file ${CONFIG}:" - cd / && unp "${LIVECD_PATH}"/config/$CONFIG $EXTRACTOPTIONS ; eend $? - eoutdent -fi - -if checkbootparam myconfig ; then - MOUNTDEVICE="$(getbootparam 'myconfig' 2>>$DEBUG)" - if [ -n "$MOUNTDEVICE" ]; then - if checkbootparam file ; then - FILENAME="$(getbootparam 'file' 2>>$DEBUG)" - [ -n "$FILENAME" ] || FILENAME='config.tbz' - fi - [ -d /mnt/grml ] || mkdir /mnt/grml - umount /mnt/grml 1>>$DEBUG 2>&1 # make sure it is not mounted - mount -o ro -t auto $MOUNTDEVICE /mnt/grml ; RC="$?" - if [[ $RC == 0 ]]; then - einfo "Successfully mounted $MOUNTDEVICE to /mnt/grml (readonly)." ; eend 0 - eindent - CONFIG='' - CONFIG="$(/bin/ls -1d /mnt/grml/[Cc][Oo][Nn][Ff][Ii][Gg].[Tt][Bb][Zz] 2>>$DEBUG)" - if [ -n "$CONFIG" ]; then - einfo "Found file ${WHITE}${CONFIG}${NORMAL} - trying to extract it." - cd / - unp $CONFIG $EXTRACTOPTIONS ; eend $? - else - ewarn "Sorry, could not find file config.tbz on device with label GRMLCFG." ; eend 1 - fi - - SCRIPT='' - SCRIPT="$(/bin/ls -1d /mnt/grml/[Gg][Rr][Mm][Ll].[Ss][Hh] 2>>$DEBUG)" - if [ -n "$SCRIPT" ]; then - einfo "Found script ${WHITE}${SCRIPT}${NORMAL} - trying to execute it." - $SCRIPT ; eend $? - fi - eoutdent - else - einfo "Could not mount $MOUNTDEVICE to /mnt/grml - sorry." ; eend 1 - fi # mount $MOUNTDEVICE - grep -q '/mnt/grml' /proc/mounts && umount /mnt/grml - else - einfo "Sorry, no device for bootoption myconfig provided. Skipping." ; eend 1 - fi # [ -n "$MOUNTDEVICE" ] -fi # checkbootparam myconfig +config_partconf() { if checkbootparam "partconf" ; then MOUNTDEVICE="$(getbootparam 'partconf' 2>>$DEBUG)" if [ -n "$MOUNTDEVICE" ]; then @@ -1983,18 +2005,61 @@ fi config_debs(){ if checkbootparam "debs" ; then DEBS="$(getbootparam 'debs' 2>>$DEBUG)" + if ! echo $DEBS | grep -q '/'; then + # backwards compatibility: if no path is given get debs from debs/ + DEBS="debs/$DEBS" + fi einfo "Tring to install debian package(s) ${DEBS}" - dpkg -i "${LIVECD_PATH}"/debs/$DEBS* ; eend $? + DEBS="$(eval echo ${DCSDIR}/$DEBS)" + dpkg -i $DEBS ; eend $? fi } config_scripts(){ if checkbootparam "scripts" ; then SCRIPTS="$(getbootparam 'scripts' 2>>$DEBUG)" - [ -z "$SCRIPTS" ] && SCRIPTS='grml.sh' - einfo "Bootparameter scripts found. Trying to execute ${SCRIPTS}:" - sh -c "${LIVECD_PATH}"/scripts/$SCRIPTS ; eend $? + if [ -z "$SCRIPTS" ]; then + SCRIPTS="$(cd ${DCSDIR}/scripts; /bin/ls -1d [Gg][Rr][Mm][Ll].[Ss][Hh] 2>>$DEBUG)" + fi + if ! echo $SCRIPTS | grep -q '/'; then + # backwards compatibility: if no path is given get scripts from scripts/ + SCRIPTS="scripts/$SCRIPTS" + fi + SCRIPTS="${DCSDIR}/$SCRIPTS" + if [ -d "$SCRIPTS" ]; then + einfo "Bootparameter scripts found. Trying to execute from directory ${SCRIPTS}:" + run-parts $SCRIPTS + else + einfo "Bootparameter scripts found. Trying to execute ${SCRIPTS}:" + sh -c $SCRIPTS + fi +fi +} + +config_config(){ +if checkbootparam config ; then + CONFIG="$(getbootparam 'config' 2>>$DEBUG)" + if [ -z "$CONFIG" ]; then + CONFIG="$(cd ${DCSDIR}; ls -1d [Cc][Oo][Nn][Ff][Ii][Gg].[Tt][Bb][Zz] 2>>$DEBUG)" + fi + if [ -n "$CONFIG" ]; then + if [ -d "${DCSDIR}/${CONFIG}" ] ; then + einfo "Taking configuration from directory ${DCSDIR}/${CONFIG}" + + cp -a ${DCSDIR}/${CONFIG}/* / + elif [ -f "${DCSDIR}/${CONFIG}" ]; then + einfo "Extracting configuration from file ${DCSDIR}/${CONFIG}" + + cd / + unp ${DCSDIR}/${CONFIG} $EXTRACTOPTIONS ; eend $? + else + ewarn "Sorry, could not find configuration file or directory ${DCSDIR}/${FILENAME}." ; eend 1 + fi + fi fi +# umount /mnt/grml if it was mounted by finddcsdir +# this doesn't really belong here +grep -q '/mnt/grml' /proc/mounts && umount /mnt/grml } # }}}