From 73ba2ea4706132edb816e3c1b15f5b83ffeee38d Mon Sep 17 00:00:00 2001 From: Marc Haber Date: Thu, 30 Jul 2009 13:42:37 +0200 Subject: [PATCH] re-work of debs, config, scripts handling, according to issue #715 - debs, config and scripts are always searched and read from the same place ($dcs-dir). Which place this is varies, depending on GRMLCFG, noautoconfig and myconfig. - debs are searched in $dcs-dir/debs. If debs=foo is given, foo is taken as a shell wildcard for the debs being installed, paths are allowed and relative to $dcs-dir. - config archives (config.tbz) are searched directly in $dcs-dir. If config=foo is given and foo is a file, that file is unpacked and its content taken as configuration archive. If config=foo is given and foo is a directory, the contents of the directory tree is copied over the live CD configuration. paths are allowed and relative to $dcs-dir - scripts are searched in $dcs-dir/scripts. If scripts=foo is given and foo is a file, that file is executed. If scripts=foo is given and foo is a directory, all files inside that directory are executed. Paths are allowed and relative to $dcs-dir. - 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. --- autoconfig | 6 +- autoconfig.functions | 195 ++++++++++++++++++++++++++++----------------------- grml-autoconfig | 14 ++-- 3 files changed, 116 insertions(+), 99 deletions(-) diff --git a/autoconfig b/autoconfig index 2721a5e..36fcfae 100644 --- a/autoconfig +++ b/autoconfig @@ -55,7 +55,8 @@ CONFIG_BLANKING='yes' # check for bootoption noblank to disable console CONFIG_BLINDSOUND='yes' # play 'beep' and play welcome message CONFIG_BLIND='yes' # check for blind option or brltty CONFIG_CDROM_PERM='yes' # for burning on IDE-CD-Roms, k3b (and others) check for special permissions -CONFIG_CDROM_SCRIPTS='yes' # run scripts from /cdrom/scripts +CONFIG_CDROM_SCRIPTS='no' # run scripts from /cdrom/scripts +CONFIG_CONFIG='yes' # do we want config unpacking to work? CONFIG_CONSOLE='yes' # activate mgetty when using console=... as bootparam CONFIG_CREATE_MNT_DIRS='no' # create /mnt-directories CONFIG_DEBOOTSTRAP='yes' # support automatic installation of Debian via grml-deboostrap @@ -68,6 +69,7 @@ CONFIG_DISTRI='yes' # support some customization via bootoption distri CONFIG_DMA='yes' # Enable DMA for all IDE drives CONFIG_EXTRACT='yes' # specify which (only in combination with bootparam myconfig/netconfig useful) CONFIG_FAST='yes' # skip startup of w3m on tty1 +CONFIG_FINDDCSDIR='yes' # search for a debs, config, scripts directory CONFIG_FIREWIRE_DEV='no' # bugfix for kernel >=2.6.11 - create some firewire-devices CONFIG_FIX_PASSWD='yes' # fix unionfs-problem with passwd CONFIG_FIX_UNIONFS='yes' # fix/workaround for unionfs @@ -95,9 +97,11 @@ CONFIG_MYCONFIG='yes' # check if we want the config floppy CONFIG_MYPATH='yes' # provide setting additional paths via bootoption mypath CONFIG_NETCONFIG='yes' # download configuration archive provided by bootoption netconfig=... CONFIG_NETIPV6='yes' # check for bootparam ipv6 +CONFIG_PARTCONF='yes' # do we want partconf to work? CONFIG_PASSWD='yes' # set password via bootparam passwd CONFIG_PCMCIA='no' # check for pcmcia and start cardmgr CONFIG_QEMU='yes' # qemu specific stuff +CONFIG_SCRIPTS='yes' # execute scripts from the scripts option CONFIG_SERVICES='yes' # check for services to run, provided via bootparam CONFIG_SETKEYCODES='yes' # run setkeycodes when bootoption setkeycodes found CONFIG_SMALL='yes' # use a less "bloat" /etc/inittab for small computer with less RAM diff --git a/autoconfig.functions b/autoconfig.functions index dcb76da..19fdbf6 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 @@ -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" @@ -1587,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 @@ -1913,97 +1919,65 @@ if checkbootparam extract ; then fi } -config_unpack(){ -MOUNTDEVICE="$1" -MESSAGE="$2" - -if [ ! -b "$MOUNTDEVICE" ] ; then - return; -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 $MESSAGE 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 checkbootparam config ; then - FILENAME="$(getbootparam 'config' 2>>$DEBUG)" - if [ -e /mnt/grml/"${FILENAME}" ] ; then - einfo "Using /mnt/grml/$FILENAME instead of config.tbz" - CONFIG="/mnt/grml/${FILENAME}" - fi - else - [ -n "$CONFIG" ] && FILENAME="$(basename $CONFIG)" || FILENAME="config.tbz" - fi - - 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 ${FILENAME} on device ${MOUNTDEVICE} ${MESSAGE}." ; 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 - -} - -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 - # We do need the following fix so floppy disk is available to blkid in any case :-/ - if [ -r /dev/fd0 ] ; then + 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 - DEVICE=$(blkid -t LABEL=GRMLCFG | head -1 | awk -F: '{print $1}') - config_unpack "$DEVICE" "labeled GRMCFG" + fi + DCSDEVICE=$(blkid -t LABEL=GRMLCFG | head -1 | awk -F: '{print $1}') + fi + 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 fi 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 +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 +} -if checkbootparam myconfig ; then - MOUNTDEVICE="$(getbootparam 'myconfig' 2>>$DEBUG)" - if [ -n "$MOUNTDEVICE" ]; then - config_unpack "$MOUNTDEVICE" - 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 @@ -2031,19 +2005,62 @@ 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 +} # }}} # {{{ mypath diff --git a/grml-autoconfig b/grml-autoconfig index 2c97dbc..7e46b47 100755 --- a/grml-autoconfig +++ b/grml-autoconfig @@ -53,12 +53,6 @@ mount_pts mount_sys # }}} -# {{{ Read in boot parameters -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' ' ')" -# }}} - # {{{ main grml-autoconfig checkvalue $CONFIG_DEBUG && config_debug @@ -206,12 +200,16 @@ checkvalue $CONFIG_EXTRACT && config_extract checkvalue $CONFIG_HOMEDIR && config_homedir -checkvalue $CONFIG_MYCONFIG && config_myconfig +checkvalue $CONFIG_FINDDCSDIR && config_finddcsdir checkvalue $CONFIG_DEBS && config_debs checkvalue $CONFIG_SCRIPTS && config_scripts +checkvalue $CONFIG_CONFIG && config_config + +checkvalue $CONFIG_PARTCONF && config_partconf + [ -n "$SPLASH" ] && /usr/bin/grml-bootsplash "||||||||">/dev/tty14 checkvalue $CONFIG_CDROM_SCRIPTS && config_cdrom_scripts @@ -258,8 +256,6 @@ checkvalue $CONFIG_915RESOLUTION && config_915resolution checkvalue $CONFIG_IPW3945 && config_ipw3945 -checkvalue $CONFIG_AUTOMOUNT && config_automount - checkvalue $CONFIG_MYPATH && config_mypath checkvalue $CONFIG_DISTCC && config_distcc -- 2.1.4