|
From: Serge L. <sma...@us...> - 2009-01-29 02:57:05
|
Update of /cvsroot/devil-linux/build/config/etc/initrd In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv30935 Modified Files: linuxrc mount_cdrom Log Message: - updater now supports squashfs images and the both bootloaders (syslinux and grub) Index: linuxrc =================================================================== RCS file: /cvsroot/devil-linux/build/config/etc/initrd/linuxrc,v retrieving revision 1.103 retrieving revision 1.104 diff -u -d -r1.103 -r1.104 --- linuxrc 7 Jan 2009 06:37:14 -0000 1.103 +++ linuxrc 29 Jan 2009 02:56:54 -0000 1.104 @@ -182,6 +182,24 @@ return 1 } +reboot_if_updated() { +# check if the DL ISO got upgraded +# should be invoked after each mount_cdrom execution. + if [ -e /shm/dl_iso_replaced ]; then + sync + umount /cd || mount -o remount,ro /cd + umount /floppy || mount -o remount,ro /floppy + umount /cdrom || mount -o remount,ro /cdrom + $RED + echo "Rebooting..." + sleep 3 + reboot + echo "Oops... something goes wrong..." + $NORMAL + /bin/sh + fi +} + # make sure all kernel warnings get lost (seriously!) klogd -c 1 @@ -297,6 +315,7 @@ $NORMAL continue fi + reboot_if_updated mount -n -t auto $CFG_SRC /floppy >/dev/null 2>&1 || continue cp -i /cdrom/config/etc-mods.tar.bz2 /floppy/ || continue umount /cdrom @@ -338,16 +357,6 @@ mkdir -p /shm/root fi -# check if the DL ISO got upgraded -if [ -e /shm/dl_iso_replaced ]; then - cd /cdrom - #change to new root - pivot_root . initrd - $RED - echo "Rebooting..." - $NORMAL - exec /usr/sbin/chroot . /sbin/reboot -f -fi $GREEN echo "loading configuration" @@ -357,6 +366,7 @@ if [ ! -e /cdrom/DEVIL-LINUX ] ; then # find the CDROM /mount_cdrom /cdrom + reboot_if_updated fi tar -C /shm -xjf /cdrom/config/etc-mods.tar.bz2 # @@ -389,6 +399,7 @@ if [ ! -e /cdrom/DEVIL-LINUX ] ; then # find the CDROM /mount_cdrom /cdrom + reboot_if_updated fi DL_DEVICE=$(cat /shm/DL_DEVICE) Index: mount_cdrom =================================================================== RCS file: /cvsroot/devil-linux/build/config/etc/initrd/mount_cdrom,v retrieving revision 1.48 retrieving revision 1.49 diff -u -d -r1.48 -r1.49 --- mount_cdrom 26 Jan 2009 23:55:34 -0000 1.48 +++ mount_cdrom 29 Jan 2009 02:56:54 -0000 1.49 @@ -77,6 +77,22 @@ kill $busypid >/dev/null 2>&1; usleep ${DELAY} } +beep () { + # $1 = optional, number of times to beep (default=1) + # $2 = optional, sleep that many seconds between beeps (default=1) + # $3 = optional, print this with 'echo -n' after each sleep + local count=${1:-1} + local waitcnt=${2:-1} + local string=$3 + + while [ $count -gt 0 ]; do + echo -en "\007" + [ -n "$string" ] && echo -en "$string" + let count-- + [ $count -gt 0 ] && sleep $waitcnt + done +} + run_from_ram () { # # usage: run_from_ram [--cdrom|--file] @@ -235,6 +251,46 @@ return 0 } +manual_recovery () { + $RED + beep 5 + echo " Critical error!" + echo "Most probably the system will not boot up after reset!" + echo "You can try to recover the system manually or reinstall it!" + $NORMAL + echo "The system partition is mounted to ${FILEMOUNT}" + echo "Exit from shell will cause reboot." + /sbin/sh + sync + exit 1 +} + +copy_bootfiles () { + + # we don't know where kernel and initrd are + # they maybe either in / (syslinux) or in /boot (grub) + if [ -e ${FILEMOUNT}/boot/vmlinuz ]; then + PREFIX="boot" + fi + + # We are copying the following files only: + # System.map, initrd.gz, vmlinuz, memtest + # because we shouldn't overwrite neither boot loader + # config files nor the bootloader itself. + # make sure we set the file permission secure + for i in System.map initrd.gz vmlinuz memtest + do + cp -fp ${mountpoint}/boot/$i ${FILEMOUNT}/${PREFIX}/ || + ( echo "Error during copying \"${mountpoint}/boot/$i\" to \"${FILEMOUNT}/${PREFIX}/\""; return 1 ) + chown -R 0.0 ${FILEMOUNT}/${PREFIX}/$i + chmod -R u+rw,g-rwx,o-rwx ${FILEMOUNT}/${PREFIX}/$i + done + + cp -fp ${mountpoint}/DEVIL-LINUX ${FILEMOUNT}/ + + sync +} + if [ ! $silent ]; then $GREEN echo "Searching for Devil-Linux CD-ROM" @@ -313,7 +369,8 @@ $GREEN echo "media found" $NORMAL - if [ -e /cd/bootcd.iso.new ] ; then + + if [[ "$(ls ${FILEMOUNT}/bootcd.*.new 2>/dev/null)" != "" ]]; then $BLUE echo "****************************" echo "* Found Devil-Linux update *" @@ -321,37 +378,69 @@ echo echo "Backing up old version" $RED - rm -f /cd/bootcd.iso.old &> /dev/null - mv /cd/bootcd.iso /cd/bootcd.iso.old || echo "Backup failed" + rm -f ${FILEMOUNT}/bootcd.*.old &> /dev/null + for i in $( ls ${FILEMOUNT}/bootcd.* | grep -v ".new" ) + do + mv $i $i.old || echo "Backup failed" + done $BLUE echo "Activating new version" - $RED - rm -f /cd/bootcd.iso &> /dev/null - if mv /cd/bootcd.iso.new /cd/bootcd.iso ; then + + if [ -e ${FILEMOUNT}/bootcd.squash.new ] ; then + IMAGE="bootcd.squash" + IMAGEFS="squashfs" + elif [ -e ${FILEMOUNT}/bootcd.iso.new ] ; then + IMAGE="bootcd.iso" + IMAGEFS="iso9660" + fi + + if mv -f ${FILEMOUNT}/${IMAGE}.new ${FILEMOUNT}/${IMAGE} ; then # create flag file, so the other scripts know about it touch /shm/dl_iso_replaced $BLUE echo "Upgrading System Boot Files" $NORMAL - /sbin/mount -o loop -t iso9660 /cd/bootcd.iso /cdrom + /sbin/mount -o loop -t ${IMAGEFS} ${FILEMOUNT}/${IMAGE} ${mountpoint} - cp -fp /cdrom/boot/* /cd/boot/ 2> /dev/null - cp -fp /cdrom/DEVIL-LINUX /cd/ - # make sure we set the file permission secure - chown -R 0.0 /cd/* - chmod -R u+rw,g-rwx,o-rwx /cd/* + if ! copy_bootfiles ; then - sync - /sbin/umount /cdrom &> /dev/null - - $GREEN - echo "Mounting old version" - $NORMAL - /sbin/mount -o loop -t iso9660 /cd/bootcd.iso.old ${mountpoint} || return 1 - echo $disk > /shm/DL_DEVICE - dl_version=`cat /cd/DEVIL-LINUX 2> /dev/null` - exit 0 + /sbin/umount ${mountpoint} &> /dev/null + + $RED + echo "Errors during System Boot Files upgrading." + echo "Recovering the previous system..." + + $GREEN + echo "Mounting old version" + $NORMAL + + if [ -e ${FILEMOUNT}/bootcd.squash.old ] ; then + IMAGE="bootcd.squash" + IMAGEFS="squashfs" + elif [ -e ${FILEMOUNT}/bootcd.iso.old ] ; then + IMAGE="bootcd.iso" + IMAGEFS="iso9660" + else + echo "No backup was found!" + manual_recovery + fi + + /sbin/mount -o loop -t ${IMAGEFS} ${FILEMOUNT}/${IMAGE}.old ${mountpoint} + + copy_bootfiles || ( manual_recovery ) + + /sbin/umount ${mountpoint} + + mv -f ${FILEMOUNT}/${IMAGE}.old ${FILEMOUNT}/${IMAGE} || + ( echo "Error during renaming \"${IMAGE}.old\" to \"${IMAGE}\""; manual_recovery ) + echo "The image and system boot files have been recovered..." + else + echo "System has been updated." + sync + fi + # Update is complete + exit 0 else echo "Activation failed" fi @@ -360,6 +449,7 @@ $NORMAL fi + if [[ "$(ls ${FILEMOUNT}/bootcd.* | grep -v '.old' 2>/dev/null)" != "" ]]; then echo $disk > /shm/DL_DEVICE |