diff --git a/etc/rc.firmware b/etc/rc.firmware index a6e0082602..aff6538c72 100755 --- a/etc/rc.firmware +++ b/etc/rc.firmware @@ -9,7 +9,7 @@ #CFDEVICE=`cat /var/etc/cfdevice` -exec 3>&2 2>>/tmp/firmware_update.log +#exec 3>&2 2>>/tmp/firmware_update.log export ACTION=$1 export IMG=$2 @@ -72,10 +72,11 @@ binary_update() { #echo "${i} file does not match intended final md5." echo "${i} file does not match intended final md5." >> ${ERR_F} fi - - /bin/rm /tmp/patched/${FILE} >> ${ERR_F} - /bin/rm /tmp/patches/${i} >> ${ERR_F} - /bin/rm /tmp/patches/${i}.* >> ${ERR_F} + + chflags noschg /tmp/patched/${FILE} /tmp/patches/${i} /tmp/patches/${i}.* + /bin/rm -f /tmp/patched/${FILE} >> ${ERR_F} + /bin/rm -f /tmp/patches/${i} >> ${ERR_F} + /bin/rm -f /tmp/patches/${i}.* >> ${ERR_F} done /bin/rm -rf /tmp/patched /tmp/patches >> ${ERR_F} restore_chflags @@ -148,98 +149,95 @@ upgrade) sh /etc/rc.reboot fi ;; -pfSenseupgrade) - # wait 5 seconds before beginning - sleep 5 - - # Sanity check - bail early if there's no firmware file! - if [ ! -r $IMG ]; then - echo "2nd parameter has not been passed or file does not exist. Exiting." | logger -p daemon.info -i -t Upgrade - exit - fi - - backup_chflags - remove_chflags - - #exec /dev/console 2>/dev/console - - echo "Firmware upgrade in progress..." | logger -p daemon.info -i -t Upgrade - - # backup config - /bin/mkdir -p /tmp/configbak - cp -p /conf/* /tmp/configbak 2>/dev/null - # mount /cf - /etc/rc.conf_mount_rw - /sbin/mount -w -o noatime /cf 2>/dev/null - /sbin/mount -w -o noatime / 2>/dev/null - - # tar explode image onto hd - echo "Installing $IMG." | logger -p daemon.info -i -t Upgrade - cd / && /usr/bin/tar xzUPf $IMG | logger -p daemon.info -i -t Upgrade - /usr/bin/find / -name CVS -exec rm -fr {} \; - echo "Image installed $IMG." | logger -p daemon.info -i -t Upgrade - - # process custom image if its passed - if [ $# -eq 3 ]; then - if [ -f $CUSTOMIMG ]; then - echo "Custom image $CUSTOMIMG found." | logger -p daemon.info -i -t Upgrade - echo "Custom image ($CUSTOMIMG) found." - PWD_DIR=`pwd` - cd / && /usr/bin/tar xzPUf $CUSTOMIMG | logger -p daemon.info -i -t Upgrade - cd $PWD_DIR - echo "Custom image $CUSTOMIMG installed." | logger -p daemon.info -i -t Upgrade + pfSenseupgrade) + # wait 5 seconds before beginning + sleep 5 + # Sanity check - bail early if there's no firmware file! + if [ ! -r $IMG ]; then + echo "2nd parameter has not been passed or file does not exist. Exiting." | logger -p daemon.info -i -t Upgrade + exit + fi + backup_chflags + remove_chflags + echo "Firmware upgrade in progress..." | logger -p daemon.info -i -t Upgrade + # backup config + /bin/mkdir -p /tmp/configbak + cp -p /conf/* /tmp/configbak 2>/dev/null + # mount /cf + /etc/rc.conf_mount_rw + /sbin/mount -w -o noatime /cf 2>/dev/null + /sbin/mount -w -o noatime / 2>/dev/null + echo "Extracting $IMG." | logger -p daemon.info -i -t Upgrade + gzip -d $IMG + NEWIMG="`echo $IMG | sed 's/.tgz/.tar/'`" + echo "Installing $NEWIMG." | logger -p daemon.info -i -t Upgrade + for i in `/usr/bin/tar tvzf $NEWIMG`; + do + FILE=`basename ${i}` + echo "Working on ${FILE} - /${i}" + echo "Working on ${FILE} - /${i}" | logger -p daemon.info -i -t Upgrade + (cd /tmp && /usr/bin/tar xf ${NEWIMG} ${i}) + echo "Installing /${i}" + echo "Installing /${i}" | logger -p daemon.info -i -t Upgrade + /usr/bin/install -S "/tmp/${i}" "/${i}" + chflags noschg "/tmp/${i}" + /bin/rm -f "/tmp/${i}" + done + /usr/bin/find / -name CVS -exec rm -fr {} \; + echo "Image installed $IMG." | logger -p daemon.info -i -t Upgrade + # process custom image if its passed + if [ $# -eq 3 ]; then + if [ -f $CUSTOMIMG ]; then + echo "Custom image $CUSTOMIMG found." | logger -p daemon.info -i -t Upgrade + echo "Custom image ($CUSTOMIMG) found." + PWD_DIR=`pwd` + cd / && /usr/bin/tar xzPUf $CUSTOMIMG | logger -p daemon.info -i -t Upgrade + cd $PWD_DIR + echo "Custom image $CUSTOMIMG installed." | logger -p daemon.info -i -t Upgrade + fi fi - fi - - # restore config - cp -p /tmp/configbak/* /conf 2>/dev/null - - # restore /etc symlinks - rm /etc/hosts - ln -s /var/etc/hosts /etc/hosts - - restore_chflags - - # Remove upgrade file - rm -f $IMG - - rm -f /var/run/firmware.lock - - /bin/sync - sleep 5 - - # remount /cf ro - rm -rf /etc/rc.conf - rm -rf /etc/motd - find / -name CVS -type d -exec rm {} \; - rm -rf /usr/savecore/* - /etc/rc.conf_mount_ro - /sbin/umount -f /cf 2>/dev/null - /sbin/mount -r /cf 2>/dev/null - /sbin/umount -f / 2>/dev/null - /sbin/mount -r / 2>/dev/null - if [ -e /etc/init_bootloader.sh ]; then - sh /etc/init_bootloader.sh - fi - /bin/sync - echo "Done." | logger -p daemon.info -i -t Upgrade - - # If /tmp/post_upgrade_command exists after update - # then execute the command. - if [ -f /tmp/post_upgrade_command ]; then - sh /tmp/post_upgrade_command - fi - - # If the archive has unpacked a file called - # /tmp/no_upgrade_reboot_required then do - # not reboot after upgrade. - if [ -f /tmp/no_upgrade_reboot_required ]; then - rm /tmp/no_upgrade_reboot_required - else - rm -f /var/run/config.lock - sh /etc/rc.reboot - fi - ;; + # restore config + cp -p /tmp/configbak/* /conf 2>/dev/null + # restore /etc symlinks + rm /etc/hosts + ln -s /var/etc/hosts /etc/hosts + restore_chflags + rm -f /var/run/firmware.lock + # Remove upgrade file + rm -f $IMG + /bin/sync + sleep 5 + # remount /cf ro + rm -rf /etc/rc.conf + rm -rf /etc/motd + find / -name CVS -type d -exec rm {} \; + rm -rf /usr/savecore/* + /etc/rc.conf_mount_ro + /sbin/umount -f /cf 2>/dev/null + /sbin/mount -r /cf 2>/dev/null + /sbin/umount -f / 2>/dev/null + /sbin/mount -r / 2>/dev/null + if [ -e /etc/init_bootloader.sh ]; then + sh /etc/init_bootloader.sh + fi + rm $NEWIMG + /bin/sync + echo "Done." | logger -p daemon.info -i -t Upgrade + # If /tmp/post_upgrade_command exists after update + # then execute the command. + if [ -f /tmp/post_upgrade_command ]; then + sh /tmp/post_upgrade_command + fi + # If the archive has unpacked a file called + # /tmp/no_upgrade_reboot_required then do + # not reboot after upgrade. + if [ -f /tmp/no_upgrade_reboot_required ]; then + rm /tmp/no_upgrade_reboot_required + else + rm -f /var/run/config.lock + sh /etc/rc.reboot + fi + ;; delta_update) backup_chflags remove_chflags