FreeNAS Code
This project has moved to github - see https://github.com/freenas
Brought to you by:
cochard,
mattolander
#!/bin/sh #set -x # /etc/rc.firmware # part of FreeNAS (http://www.freenas.org) # Copyright (C) 2005-2007 Olivier Cochard-Labbe <olivier@freenas.org>. # All rights reserved. # # Based on m0n0wall (http://m0n0.ch/wall) # Copyright (C) 2003-2007 Manuel Kasper <mk@neon1.net>. # All rights reserved. # Script usage: # rc.firmware <args> [<file>] # Where <args> can take the following values: # - enable: Create a 30MB ram drive in /ftmp # - disable: Erase ram drive # - upgrade <file> : Do an embedded release (IMG file) upgrade using the file <file> # - fullupgrade <file> : Do a full release (TGZ file) upgrade using the file <file> SIZE="30M" CFDEVICE=`cat /var/etc/cfdevice` case $1 in enable) # Redirect I/O to console. exec </dev/console >/dev/console 2>/dev/console # Use auto-unit feature to automatically select an unused device. /sbin/mdmfs -s $SIZE -b 8192 -f 1024 md /ftmp > /dev/null 2>&1 if [ 0 != $? ]; then # successful? echo echo "Upgrade Error: Failed to create in-memory file system." /usr/bin/logger "Upgrade Error: Failed to create in-memory file system." exit 1 fi ;; disable) # Redirect I/O to console. exec </dev/console >/dev/console 2>/dev/console # Get the md device. MDID=`/sbin/mount -p | /usr/bin/grep /ftmp | /usr/bin/awk '{print $1}'` # Umount in-memory file system. /sbin/umount -f /ftmp > /dev/null 2>&1 if [ 0 != $? ]; then # successful? echo echo "Upgrade Error: Failed to umount in-memory file system." /usr/bin/logger "Upgrade Error: Failed to umount in-memory file system." exit 1 fi # Detach md device. /sbin/mdconfig -d -u $MDID ;; upgrade) # Wait 5 seconds before beginning sleep 5 # Redirect I/O to console. exec </dev/console >/dev/console 2>/dev/console echo echo "Firmware upgrade in progress. Please wait..." # Check if firmware file exists if [ ! -r $2 ]; then echo "Error: Firmware file does not exist." /usr/bin/logger "upgrade: ERROR: Firmware file does not exist." exit 1 fi # Backup config mkdir /tmp/configbak cp -p /conf/* /tmp/configbak # Unmount /cf /sbin/umount -f /cf # dd image onto card result=1 if [ -r $2 ]; then /usr/bin/gzip -cd -S "" $2 | /bin/dd of=/dev/${CFDEVICE} bs=16k > /dev/null 2>&1 result=$? if [ 0 != ${result} ]; then # successful? echo "Error: Failed to dd firmware image on '/dev/${CFDEVICE}'!" /usr/bin/logger "upgrade: ERROR: Failed to dd firmware image on '/dev/${CFDEVICE}'!" else echo "Firmware installed successful." /usr/bin/logger "upgrade: Firmware installed successful." fi fi # Mount /cf read-write /sbin/mount -w -o noatime /cf # Restore config cp -p /tmp/configbak/* /conf rm -r /tmp/configbak # Remount /cf read-only /sbin/umount -f /cf /sbin/mount -r /cf # Reboot system if upgrade was successful. if [ 0 -eq ${result} ]; then echo "Rebooting system..." /sbin/shutdown -r now > /dev/null 2>&1 else exit 1 fi ;; fullupgrade) # Wait 5 seconds before beginning. sleep 5 # Redirect I/O to console. exec </dev/console >/dev/console 2>/dev/console echo echo "Firmware upgrade in progress. Please wait..." # Check if firmware file exists. if [ ! -r $2 ]; then echo "Error: Firmware file does not exist." /usr/bin/logger "upgrade: ERROR: Firmware file does not exist." exit 1 fi #DO NOT OVERRIDE LIBRARY IN USE: lib/libc.so.6 #WARNING: The library files name are related to the FreeNAS release to be upgraded #Must add a switch (case) here depending of the version number being upgraded ? #MUST CLOSE ALL SERVICES before ??? #(FreeBSD seems to crash if replacing a library in use) #ls /var/run/*.pid #cat #kill -9 pidnumber # #Warning: tar uses usr/lib/libarchive.so.2 and lib/libz.so.3 tar zxvf $2 --exclude usr/lib/libarchive.so.2 --exclude lib/libz.so.3 --exclude lib/libc.so.6 -C / #Extract libarchive.so.2 and libz.so.3 to the /ftmp directory and copy them (cp doesn't use these libraries) tar zxvf $2 --include usr/lib/libarchive.so.2 --include lib/libz.so.3 -C /ftmp cp -p /ftmp/usr/lib/libarchive.so.2 /usr/lib/libarchive.so.2 cp -p /ftmp/lib/libz.so.3 /lib/libz.so.32 #How to override lib/libc.so.6 ? And, does this file need to be overridden ? #Need to be added: List of old files to be deleted (is necessary?) echo "Firmware installed successful." echo "Rebooting system..." /sbin/shutdown -r now > /dev/null 2>&1 ;; esac exit 0