##################################################################### #!/bin/ksh # #ifdef __USAGE #%C [-i] # #Examples: #In sysinit: #%C #When Changing USB devices: #%C -i # #NOTE: #Run with "-i" option when changing USB storage devices #endif # # Copyright (c) ABB Inc. 2006 ##################################################################### #set -v while getopts i opt $* do case $opt in i) input="Y" ;; esac done # #=================================================== # Create /usr/tmp dir if it doesn't exist # if [ -d /usr/tmp ] then echo "" else mkdir /usr/tmp fi # #=================================================== # Warn about the consequences if test "$input" then echo "-------------------------> WARNING <--------------------------------" echo "Remounting USB devices may disrupt data archiving, backup or retrieval" echo "currently being performed on the mounted devices." echo "Proceed with caution." echo "" tmp="" while [ -z "$tmp" ]; do echo "Remount anyway [Y/N]:" read tmp if [ -n "$tmp" ]; then if [ "$tmp" = "Y" ]; then restart="Y" elif [ "$tmp" = "y" ]; then restart="Y" elif [ "$tmp" = "N" ]; then exit 0 elif [ "$tmp" = "n" ]; then exit 0 else tmp="" fi fi done fi #=================================================== # List existing USB FAT file system tgt=$(/bin/ls /dos/ 2>/dev/null) if test "$tgt" then echo "----------------------------------------------------------------------" echo "Checking FAT file system:" echo "" /bin/slay -fQ Dosfsys 2>/dev/null /bin/df -h /dos/* 2>/dev/null echo "" echo "Unmounting FAT file system..." while test "$tgt" do todo=`echo "$tgt" |awk '{print $1}'` echo "/dos/$todo" /bin/umount /dos/$todo if [ $? -ne 0 ] then echo "Please remove the source of the umount command failure!" echo "You may () stop the script and run it again after the failure condition is corrected." sleep 5 fi tgt=$(/bin/ls /dos/ 2>/dev/null) done fi sleep 2 # #=================================================== # List existing CDs /bin/prefix -D /cd 2>/dev/null tgt=$(/bin/ls / |grep cd 2>/dev/null) if test "$tgt" then echo "Checking mounted CDs:" while test "$tgt" do todo=`echo "$tgt" |awk '{print $1}'` echo "/$todo" /bin/umount /$todo if [ $? -ne 0 ] then echo "Please remove the source of the umount command failure!" echo "You may () stop the script and run it again after the failure condition is corrected." sleep 5 fi tgt=$(/bin/ls / | grep cd 2>/dev/null) done fi sleep 2 # # #=================================================== tgt=$(/bin/ls /dev/USB* 2>/dev/null) if test "$tgt" then echo "Unmounting USB (umass) devices:" /bin/find /dev/USB* -print -exec /bin/umount {}\; 2>/dev/null sleep 5 echo "Removing USB (umass) devices:" /bin/find /dev/USB* -print -exec /bin/rm -f {}\; 2>/dev/null fi # #=================================================== tgt=$(/bin/ls /usr/tmp/USBfd.out 2>/dev/null) if test "$tgt" then # echo "Unmounting USB (umass) floppy devices:" while read tgt do echo "$tgt" /bin/umount "$tgt" if [ $? -ne 0 ] then echo "Please remove the source of the umount command failure!" echo "You may () stop the script and run it again after the failure condition is corrected." sleep 5 fi sleep 5 /bin/rm -f "$tgt" chktgt=$(/bin/ls $tgt 2>/dev/null) if test "$chktgt" then echo "ERROR: Removing $tgt failed. Please re-run this command. Exiting..." exit fi done/dev/null) if test "$running" then echo "ERROR: Unmounting /dev/USB* failed. Please trubleshoot then re-run this command..." sleep 3 exit fi # #=================================================== #Stop any USB FAT processes so we can start ok # echo "Slaying CD fsys..." /bin/slay -fQ Iso9660fsys 2>/dev/null echo "Slaying FAT fsys..." /bin/slay -fQ Fatfsys 2>/dev/null sleep 3 # # #=================================================== #If master Fsys is running, slay it... # running=$(/bin/sin | /bin/grep Fsys.umass) if test "$running" then echo "Slaying Fsys.umass..." /bin/slay -fQ Fsys.umass 2>/dev/null sleep 5 fi # #=================================================== #Give some time for USB device replacement # if test "$input" then echo "----------------------------------------------------------------------" echo "Please remove/insert USB device(s) and hit ENTER key..." read tgt fi # #=================================================== #If master I/O USB driver is not running, run it... running=$(/bin/sin | /bin/grep io-usb) if test -z "$running" then echo "Starting io-usb..." nohup /bin/io-usb & sleep 5 fi # #=================================================== #Check if a USB device exists else leave # # tgt=$(/bin/ls /dev/us* 2>/dev/null) if test -z "$tgt" then echo "No USB device present. Exiting..." echo "Starting CD fsys..." /bin/Iso9660fsys echo "Starting FAT fsys..." /bin/Fatfsys sleep 5 /bin/prefix -A /cd=/cd0 exit fi present=$(/bin/usb | /bin/grep Device) if test -z "$present" then echo "No USB device present. Exiting..." echo "Starting CD fsys..." nohup /bin/Iso9660fsys echo "Starting FAT fsys..." nohup /bin/Fatfsys sleep 5 /bin/prefix -A /cd=/cd0 exit fi # #=================================================== # Start Fsys.umass # running=$(/bin/sin | /bin/grep Fsys.umass) if test -z "$running" then echo "Starting Fsys.umass..." /bin/ls -c1 /dev/fd* |/bin/sort >/usr/tmp/fd1.out nohup /bin/Fsys.umass fsys -NFsys.umass -n Direct-Access=USBhd -n Sequential-Access=USBtp -n WORM=USBwo -n CD-ROM=USBcd -n Optical=USBmo sleep 10 /bin/ls -c1 /dev/fd* |/bin/sort >/usr/tmp/fd2.out /bin/diff -n /usr/tmp/fd1.out /usr/tmp/fd2.out |grep "/dev/fd" >/usr/tmp/USBfd.out fi # #=================================================== # Mount partitions # tgt=$(/bin/ls /dev/USB* 2>/dev/null) if test "$tgt" then echo "Mounting USB (umass) partitions:" /bin/find /dev/USB* ! -name "USBcd*" -print -exec /bin/mount -p {}\; fi # #=================================================== echo "Starting CD fsys..." /bin/Iso9660fsys echo "Starting FAT fsys..." /bin/Fatfsys sleep 5 /bin/prefix -A /cd=/cd0 # #=================================================== tgt=$(/bin/ls -c1 /dos/ 2>/dev/null) if test "$tgt" then echo "Mounted the following FAT storage:" /bin/df -h /dos/* 2>/dev/null fi # #=================================================== if test "$input" then echo "" echo "----------------------------------------------------------------------" echo "Please hit ENTER key to exit..." read tgt fi