From: Heiko Z. <smi...@us...> - 2004-05-22 22:29:41
|
Update of /cvsroot/devil-linux/build/scripts/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21907/scripts/scripts Modified Files: save-config Log Message: Adds deterministic save location, fixes issues with ISO/config on same device (Tim Tait) Index: save-config =================================================================== RCS file: /cvsroot/devil-linux/build/scripts/scripts/save-config,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- save-config 27 Apr 2004 13:39:35 -0000 1.28 +++ save-config 22 May 2004 22:29:33 -0000 1.29 @@ -13,46 +13,117 @@ source /etc/init.d/functions QUIET="" +DL_CONFIG_SOURCE="" +DL_CONFIG_FILE="etc.tar.bz2" -if [ "$1" = "-q" ]; then - QUIET="yes" +CONFIG_MOUNT=/var/adm/mount +mkdir -p $CONFIG_MOUNT || exit 1 + +if [ -f "/shm/DL_CONFIG_SOURCE" ]; then + DL_CONFIG_SOURCE=`cat /shm/DL_CONFIG_SOURCE 2> /dev/null` fi -# generate the device list we need to search for the configuration information -PARTITIONS_IDE=`find /dev/ide/ -name "part*" 2> /dev/null` -PARTITIONS_SCSI=`find /dev/scsi/ -name "part*" 2> /dev/null` -FLOPPIES=`find /dev/floppy/ -name "?" 2> /dev/null` -CONFIG_SRC_LIST="$PARTITIONS_SCSI $PARTITIONS_IDE $FLOPPIES" +if [ -f "/shm/DL_CONFIG_FILE" ]; then + DL_CONFIG_FILE=`cat /shm/DL_CONFIG_FILE 2> /dev/null` +fi -CONFIG_MOUNT=/var/adm/mount -DL_CONFIG_SOURCE="" +while [ ! -z "$1" ]; do + case "$1" in + "-h" ) + echo "save-config [-hqs] [-d DEVICE] [-f FILE]" + echo " Saves the Devil-Linux configuration (/etc and /root trees) to a bzip2 compressed tar file." + echo " By default, the file loaded during boot will updated." + echo; + echo " -d <devicename> Device to use for configuration file." + echo " -f <filename> Name of configuration file (default is \"etc.tar.bz2\")." + echo " -h This help text" + echo " -q Quiet operation, no status ouput." + echo " -s Force search of all devices for configuration file." + echo; + exit 0 + ;; -mkdir -p $CONFIG_MOUNT || exit 1 + "-q" ) QUIET="yes" + ;; -$GREEN -echo -e "searching for configuration media" -$NORMAL + "-d" ) + shift + if [ -z "$1" ]; then + echo "Error - Device name missing" + exit 1 + else + DL_CONFIG_SOURCE=$1 + fi + ;; -until [ -e $CONFIG_MOUNT/etc.tar.bz2 ] ; -do + "-s" ) + DL_CONFIG_SOURCE="" + ;; + + "-f" ) + shift + if [ -z "$1" ]; then + echo "Error - File name missing" + exit 1 + else + DL_CONFIG_FILE=$1 + fi + ;; + + * ) + echo "Unknown option: $1" + exit 1 + ;; + esac + shift +done + +if [ -n $DL_CONFIG_SOURCE ]; then + if [ -b $DL_CONFIG_SOURCE ]; then + if [ -z "$QUIET" ]; then + $GREEN + echo -e "Found configuration file location used by boot: $DL_CONFIG_SOURCE" + $NORMAL + fi + else + $FAILURE + echo "Configuration file device specified \"$DL_CONFIG_SOURCE\" no longer exists!" + echo "Run save-config again with \"-s\" switch to search for other locations." + $NORMAL + exit 0 + fi +else + + # generate the device list we need to search for the configuration information + PARTITIONS_IDE=`find /dev/ide/ -name "part*" 2> /dev/null` + PARTITIONS_SCSI=`find /dev/scsi/ -name "part*" 2> /dev/null` + FLOPPIES=`find /dev/floppy/ -name "?" 2> /dev/null` + CONFIG_SRC_LIST="$PARTITIONS_SCSI $PARTITIONS_IDE $FLOPPIES" + + $GREEN + echo -e "searching for configuration media" + $NORMAL + + until [ -e "$CONFIG_MOUNT/$DL_CONFIG_FILE" ] ; + do for CFG_SRC in $CONFIG_SRC_LIST do echo -e "Checking $CFG_SRC" - if mount -n -t auto $CFG_SRC $CONFIG_MOUNT >/dev/null 2>&1 ; then + if mount -n -o ro,noatime -t auto $CFG_SRC $CONFIG_MOUNT >/dev/null 2>&1 ; then - if [ -e $CONFIG_MOUNT/etc.tar.bz2 ] ; then + if [ -e "$CONFIG_MOUNT/$DL_CONFIG_FILE" ] ; then + umount $CONFIG_MOUNT $SUCCESS echo -e "Found configuration on $CFG_SRC" $NORMAL - DL_CONFIG_SOURCE=$CFG_SRC if [ -z "$QUIET" ]; then echo -n "Do you want to use this device?" if ask_yes_no ; then + DL_CONFIG_SOURCE=$CFG_SRC continue 2 - else - umount $CONFIG_MOUNT fi else + DL_CONFIG_SOURCE=$CFG_SRC continue 2 fi else @@ -61,10 +132,8 @@ $SUCCESS echo -e "\n*** Found empty media $CFG_SRC . ***\n" $NORMAL - echo -n "Should I copy default configuration to it?" + echo -n "Do you want to save your configuration to this device?" if ask_yes_no ; then - mount -t auto $CFG_SRC $CONFIG_MOUNT >/dev/null 2>&1 - cp -i /config/etc.tar.bz2 $CONFIG_MOUNT/ DL_CONFIG_SOURCE=$CFG_SRC continue 2 fi @@ -77,22 +146,34 @@ $NORMAL read ANS echo -done - -umount $CONFIG_MOUNT &> /dev/null + + done +fi $WARNING echo "using device $DL_CONFIG_SOURCE" $NORMAL -until [ -e $CONFIG_MOUNT/etc.tar.bz2 ] ; do - if mount $DL_CONFIG_SOURCE $CONFIG_MOUNT 2>&1 >/dev/null ; then - if [ -e $CONFIG_MOUNT/etc.tar.bz2 ] ; then - continue +until [ -e $CONFIG_MOUNT/$DL_CONFIG_FILE ] ; do +# if mount $DL_CONFIG_SOURCE $CONFIG_MOUNT 2>&1 >/dev/null ; then + if mount -o ro,noatime $DL_CONFIG_SOURCE $CONFIG_MOUNT ; then + if [ -e $CONFIG_MOUNT/$DL_CONFIG_FILE ] ; then + $YELLOW + echo "Updating file on device..." + $NORMAL + break else - umount $CONFIG_MOUNT + # why should we require it exist? If the user + # wants it elsewhere let them say so. + # maybe the wanted to make a copy of a tesy config + # on a new diskette? + $YELLOW + echo "Creating new file on device..." + $NORMAL + break fi fi + umount $CONFIG_MOUNT &> /dev/null beep;beep; $FAILURE echo "Please insert Configuration Media in $DL_CONFIG_SOURCE" @@ -100,11 +181,11 @@ sleep 2 done -if [ -z "$QUIET" ]; then +if [ -z "$QUIET" -a -e $CONFIG_MOUNT/$DL_CONFIG_FILE ] ; then $SUCCESS echo "listing difference" $NORMAL - ( cd / ; tar -djf $CONFIG_MOUNT/etc.tar.bz2 etc ) + ( cd / ; tar -djf $CONFIG_MOUNT/$DL_CONFIG_FILE etc ) umount $CONFIG_MOUNT @@ -116,15 +197,18 @@ fi fi +# This umount seems completely un-needed? Is this to give the user a chance to switch media? umount $CONFIG_MOUNT &> /dev/null -mount -t auto $DL_CONFIG_SOURCE $CONFIG_MOUNT +# mount RO at first to avoid mount error if config is on same device as ISO +mount -o ro,noatime -t auto $DL_CONFIG_SOURCE $CONFIG_MOUNT +mount -o remount,rw,noatime $CONFIG_MOUNT $SUCCESS echo "Saving current configuration" $NORMAL -tar -C /shm -cjf $CONFIG_MOUNT/etc.tar.bz2 \ +tar -C /shm -cjf $CONFIG_MOUNT/$DL_CONFIG_FILE \ --exclude=*~ \ --exclude=mtab \ --exclude=*.2.old \ @@ -143,15 +227,18 @@ if [ $error -eq 141 ]; then echo "media protected, configuration not saved" else - chmod 0600 $CONFIG_MOUNT/etc.tar.bz2 + chmod 0600 $CONFIG_MOUNT/$DL_CONFIG_FILE $SUCCESS echo "Configuration saved" $NORMAL # run user specfic script after successful save # useful for backing up the config elsewhere - [ -x /root/bin/post-save-config ] && /root/bin/post-save-config + # Pass device and file name just saved + [ -x /root/bin/post-save-config ] && /root/bin/post-save-config $DL_CONFIG_SOURCE $CONFIG_MOUNT $DL_CONFIG_FILE fi -umount $CONFIG_MOUNT sync;sync;sync +# This kludge is in case configuration device is also location of bootcd.iso. Restore back to RO mode +mount -o remount,ro,noatime $CONFIG_MOUNT +umount $CONFIG_MOUNT |