|
From: Heiko Z. <smi...@us...> - 2004-04-09 01:01:19
|
Update of /cvsroot/devil-linux/build/config/etc/initrd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22540/config/etc/initrd Modified Files: linuxrc Log Message: - don't wait for usb-storage driver if no devices are present (Roland Pabel) - added boot parameter 'config=<device>:<filename>' which is given priority in search for configuration archive (Roland Pabel) Index: linuxrc =================================================================== RCS file: /cvsroot/devil-linux/build/config/etc/initrd/linuxrc,v retrieving revision 1.66 retrieving revision 1.67 diff -u -d -r1.66 -r1.67 --- linuxrc 27 Mar 2004 00:12:54 -0000 1.66 +++ linuxrc 9 Apr 2004 00:47:35 -0000 1.67 @@ -35,6 +35,34 @@ export PATH=$PATH:/sbin:/usr/sbin +scan_device_for_config() { + # $1 = device + # $2 = filename + SRC=$1 + FILE=$2 + echo -n "Checking for \"$FILE\" on \"$SRC\" ... " + if mount -n -t auto $SRC /floppy >/dev/null 2>&1 ; then + if [ -e /floppy/$FILE ] ; then + $GREEN + echo "success!" + $NORMAL + DL_CONFIG_SOURCE=$SRC + DL_CONFIG_FILE=$FILE + return 0 + else + $YELLOW + echo "file not found." + $NORMAL + umount /floppy # in case user swaps floppy when we are accepting input + fi + else + $RED + echo "mount failed." + $NORMAL + fi + return 1 +} + mod_config() { [ ! -e /etc/sysconfig/config.org ] && cp /etc/sysconfig/config /etc/sysconfig/config.org rm -f /etc/sysconfig/config.tmp @@ -70,8 +98,75 @@ # get rid of modprobe warnings mkdir -p /shm/etc -echo "waiting until usb-storage driver has initialized all devices ..." -sleep 15 +if [ `lsmod | grep -c "^usb-storage.*(unused)$"` != 0 ]; then + echo "waiting until usb-storage driver has initialized all devices ..." + sleep 15 +fi + +echo -e "Loading loop-AES module"; +modprobe loop 2> /dev/null + +# save loaded config +DL_CONFIG_SOURCE="" +DL_CONFIG_FILE="" + +$GREEN +echo "Searching for configuration media" +$NORMAL + +# parse user config +CONFIG_USER=`awk -v RS=' ' -v FS='=' '/^config=/ { print $2 }' /proc/cmdline` +CONFIG_USER_SRC="" +CONFIG_USER_FILE="" +if [ "$CONFIG_USER" != "" ]; then + CONFIG_USER_ERROR=0 + case `echo $CONFIG_USER | awk -v FS=: '{ print NF-1 }'` in + 0 ) + CONFIG_USER_SRC=`echo $CONFIG_USER | grep "/dev/"` + CONFIG_USER_FILE=`echo $CONFIG_USER | grep -v "/dev/"` + ;; + 1 ) + CONFIG_USER_SRC=`echo ${CONFIG_USER%:*}"` + CONFIG_USER_FILE=`echo ${CONFIG_USER#*:}"` + ;; + * ) + CONFIG_USER_ERROR=1 + ;; + esac + # sanity checks + [ "$CONFIG_USER_SRC" != "" ] && CONFIG_USER_ERROR=`echo $CONFIG_USER_SRC | grep -c -v "^/dev/"` + [ "$CONFIG_USER_FILE" != "" ] && CONFIG_USER_ERROR=`echo $CONFIG_USER_FILE | grep -c "/dev/"` + [ "$CONFIG_USER" = ":" ] && CONFIG_USER_ERROR=1 # just in case... + case $CONFIG_USER_ERROR in + 0 ) + $BLUE + echo -n "Trying to load configuration " + if [ "$CONFIG_USER_FILE" != "" ]; then + $GREEN + echo -n "\"$CONFIG_USER_FILE\" " + $NORMAL + fi + if [ "$CONFIG_USER_SRC" != "" ]; then + $BLUE + echo -n "from device " + $GREEN + echo -n "\"$CONFIG_USER_SRC\" " + $NORMAL + fi + $BLUE + echo "first." + $NORMAL + ;; + * ) + $RED + echo -n "Improper config parameter : \"$CONFIG_USER\". Ignored." + beep; sleep 1; echo -n "."; sleep 1; beep; echo "." + $NORMAL + CONFIG_USER_SRC="" + CONFIG_USER_FILE="" + ;; + esac +fi # generate the device list we need to search for the configuration information CDROM_IDE=`find /dev/ide/ -name "cd*" 2> /dev/null` @@ -81,34 +176,32 @@ DISCS_SCSI=`find /dev/scsi/ -name "disc" 2> /dev/null` FLOPPIES=`find /dev/floppy/ -name "?" 2> /dev/null` CONFIG_SRC_LIST="$PARTITIONS_SCSI $PARTITIONS_IDE $DISCS_SCSI $CDROM_IDE $CDROM_SCSI $FLOPPIES" -DL_CONFIG_SOURCE="" - -echo -e "Loading loop-AES module"; -modprobe loop 2> /dev/null +CONFIG_FILE_LIST="etc.tar.bz2" -$GREEN -echo -e "searching for configuration media" -$NORMAL +if [ "$CONFIG_USER_SRC" != "" ] && [ "$CONFIG_USER_FILE" != "" ]; then + # search for most specific config first + scan_device_for_config $CONFIG_USER_SRC $CONFIG_USER_FILE + if [ $? = 1 ]; then + $YELLOW + echo "Sorry, could not load your configuration. Continuing searching..." + $NORMAL + fi +else + # if no specific config is given, prepend to lists + CONFIG_SRC_LIST="$CONFIG_USER_SRC $CONFIG_SRC_LIST" + CONFIG_FILE_LIST="$CONFIG_USER_FILE $CONFIG_FILE_LIST" +fi -until [ -e /floppy/etc.tar.bz2 ] ; do - for CFG_SRC in $CONFIG_SRC_LIST +# if no configuration has been found yet, create one +until [ "$DL_CONFIG_SOURCE" != "" ] ; do + for CFG_FILE in $CONFIG_FILE_LIST do - echo -e "Checking for configuration on $CFG_SRC" - if mount -n -t auto $CFG_SRC /floppy >/dev/null 2>&1 ; then - - if [ -e /floppy/etc.tar.bz2 ] ; then - $YELLOW - echo -e "Found configuration on $CFG_SRC" - $NORMAL - DL_CONFIG_SOURCE=$CFG_SRC - continue 2 - else - umount /floppy # in case user swaps floppy when we are accepting input - fi - fi + for CFG_SRC in $CONFIG_SRC_LIST + do + scan_device_for_config $CFG_SRC $CFG_FILE && continue 3 + done done - # first pass looks for existing configuration, 2nd pass will create if none found for CFG_SRC in $CONFIG_SRC_LIST do echo -e "Looking for empty configuation media on $CFG_SRC" @@ -137,6 +230,7 @@ umount /cdrom sync DL_CONFIG_SOURCE=$CFG_SRC + DL_CONFIG_FILE="etc.tar.bz2" continue 2 fi fi @@ -153,11 +247,12 @@ unset ANS RET export DL_CONFIG_SOURCE +export DL_CONFIG_FILE mkdir -p /shm/root echo "loading configuration" -tar -C /shm -xjf /floppy/etc.tar.bz2 +tar -C /shm -xjf /floppy/$DL_CONFIG_FILE # create mtab for mount cat /proc/mounts > /etc/mtab @@ -178,7 +273,7 @@ $YELLOW echo "checking PGP signature of configuration" $NORMAL - if ! /bin/gpgv --homedir /cdrom/config --keyring /cdrom/config/pubring.gpg --ignore-time-conflict -q /floppy/etc.tar.bz2.sig ;then + if ! /bin/gpgv --homedir /cdrom/config --keyring /cdrom/config/pubring.gpg --ignore-time-conflict -q /floppy/$DL_CONFIG_FILE.sig ;then $RED echo echo "********************************************************************************" @@ -235,7 +330,7 @@ #change to new root and start up the real system pivot_root . initrd -exec /bin/chroot . /sbin/pre_init $DL_CONFIG_SOURCE $@ <dev/console >dev/console 2>&1 +exec /bin/chroot . /sbin/pre_init $DL_CONFIG_SOURCE $DL_CONFIG_FILE $@ <dev/console >dev/console 2>&1 # something went wrong echo |