##!/bin/sh # ------------------------------------------------------------------------- # Amador's Script: netflash Created: 07/08/10 # # !!!!!! GENERATED BY mkscript: 15:50 07/08/10 !!!!!! # # Copyright (C) Amador Business Computers, Inc. 1998 - 2010 # All Rights Reserved. # Licensed Material-Property of Amador Business Computers, Inc. # # <@(#) Amador Script: netflash 2010.07.08> # # Amador's Shell Script: Updates Thin Client OS over a network # ------------------------------------------------------------------------ # NOTES SECTION # 07/08/10 - Jim Selover Created this script. # 02/15/11 - JRS Modified script to find the root disk, rather than assume sda. # 01/28/14 - JRS Updated script to work with ABCThin 4.x.x images. # 02/13/14 - JRS Added xorg.conf files to device backup file. # FUNCTION SECTION netflash_help () { echo $echo_e "\nUsage: $progname [-p parameter] [-h|-?|-help]" echo $echo_e " -p pararmeter demo of how command line processing works" echo $echo_e " -h -? -help Display this message" echo exit 1 } # MAIN SCRIPT [ "$abc_env" ] || . /usr/opt/am/bin/abc_env progname=`basename $0` # Command line Arg processing area. until [ $# -lt 1 ] do arg="X$1" echo $arg | grep "^X-" > /dev/null 2>&1 if [ $? -eq 0 ]; then arg=`echo $arg | cut -d"-" -f2` else break fi [ "$arg" = "h" -o "$arg" = "?" -o "$arg" = "help" ] && netflash_help if [ "$arg" = "s" ]; then server="$2" shift # an extra shift to move to next arg. fi if [ "$arg" = "i" ]; then image="$2" shift # an extra shift to move to next arg. fi shift done if [ -s /tmp/netflash.info ]; then . /tmp/netflash.info else if [ "$server" = "" ]; then echo $echo_e "Enter hostname or IP address of NFS server: \c" read server fi if [ "$image" = "" ]; then echo $echo_e "Enter filename for Thin Client Image: \c" read image fi fi echo "$image" | grep "abcthin-[5,6,7,8]" > /dev/null if [ $? -eq 0 ]; then dmidecode 2> /dev/null | grep "64-bit capable" > /dev/null if [ $? -ne 0 ]; then echo $echo_e "ERROR: This device does appear to be 64-bit capable!" echo $echo_e " abcthin-5+ is 64 bit only. exiting..." exit 1 fi fi echo "$image" | grep "abcthin-[5,6,7,8].*uefi" > /dev/null if [ $? -eq 0 ]; then echo $echo_e "\nThe image $image is for UEFI, 64 bit, systems only!" echo $echo_e "Answer 'y' to confirm the target system supports UEFI 64-bit. (n): \c" read ans [ "$ans" = "Y" -o "$ans" = "y" ] || exit 1 echo $echo_e "\nNOTE: UEFI Boot will need to be turned on in the BIOS" echo $echo_e " after the network flash is complete.\n" fi echo $echo_e "Looking for Thin Client image:\c" mount | grep " /tmp/mnt " > /dev/null 2>&1 [ $? -eq 0 ] && umount /tmp/mnt || mkdir /tmp/mnt 2> /dev/null mount $server:/usr1/ABCThinclient /tmp/mnt if [ $? -ne 0 ]; then echo $echo_e "\nERROR: Cannot mount $server:/usr1/ABCThinclient!" exit 1 fi ls /tmp/mnt/$image > /dev/null 2>&1 if [ $? -ne 0 ]; then echo $echo_e "\nERROR: Cannot find $server:/usr1/ABCThinclient/$image!" exit 1 fi echo " Found." echo $echo_e "Ready to update the thin client. DO NOT interrupt the update!" #echo $echo_e "After the flash is complete, the unit must be disconnected" #echo $echo_e "from power, then booted." echo $echo_e "\nEnter to continue, CTRL-C to cancel...\c" read ans cd / echo $echo_e "Saving current Network and Connection info to `hostname`.tgz..." tar -czf /tmp/mnt/`hostname`.tgz etc/sysconfig/network* home/ulocal/.ICAClient home/ulocal/.config/tsclient/connections home/ulocal/.nx/config etc/X11/xorg.conf* am_def/def_racnum 2> /dev/null # Shutdown X-Windows echo $echo_e "\nStopping X-Windows..." init 3 sleep 4 # Shutdown as many services as possible. echo $echo_e "\nStopping non-essential services..." service gpm stop > /dev/null 2>&1 service ntpd stop > /dev/null 2>&1 service xinetd stop > /dev/null 2>&1 service avahi-daemon stop > /dev/null 2>&1 service messagebus stop > /dev/null 2>&1 service crond stop > /dev/null 2>&1 service exim stop > /dev/null 2>&1 service haldaemon stop > /dev/null 2>&1 service rpcidmapd stop > /dev/null 2>&1 service rpcbind stop > /dev/null 2>&1 service nfslock stop > /dev/null 2>&1 service acpid stop > /dev/null 2>&1 service sshd stop > /dev/null 2>&1 service portreserve stop > /dev/null 2>&1 service postfix stop > /dev/null 2>&1 service rsyslog stop > /dev/null 2>&1 killall gnome-keyring-daemon > /dev/null 2>&1 killall udevd > /dev/null 2>&1 killall dhclient > /dev/null 2>&1 killall pulseaudio > /dev/null 2>&1 initctl stop tty1 > /dev/null 2>&1 initctl stop tty2 > /dev/null 2>&1 initctl stop tty3 > /dev/null 2>&1 initctl stop tty4 > /dev/null 2>&1 initctl stop tty5 > /dev/null 2>&1 initctl stop tty6 > /dev/null 2>&1 initctl stop tty TTY=/dev/tty1 > /dev/null 2>&1 initctl stop tty TTY=/dev/tty2 > /dev/null 2>&1 initctl stop tty TTY=/dev/tty3 > /dev/null 2>&1 initctl stop tty TTY=/dev/tty4 > /dev/null 2>&1 initctl stop tty TTY=/dev/tty5 > /dev/null 2>&1 initctl stop tty TTY=/dev/tty6 > /dev/null 2>&1 swapoff -a > /dev/null 2>&1 rmmod i915 video drm_kms_helper drm i2c_algo_bit i2c_core > /dev/null 2>&1 umount /dsk2 > /dev/null 2>&1 # Make a temp '/' filesystem with just enough to reboot the client after # the flash is done. cd /tmp mkdir lib mkdir proc mkdir dev mkdir sys mkdir bin mkdir sbin cp /lib/ld-linux.so.2 lib for name in `echo /sbin/reboot /bin/bash /bin/dd /bin/gzip /bin/sync /bin/sleep`; do for library in `ldd $name 2> /dev/null | grep -v "not a" \ | cut -d" " -f3`; do libdir=`dirname $library` libdir=`basename $libdir` [ -f /tmp/lib/$library ] && continue cp $library /tmp/lib done cp $name /tmp/$name 2> /dev/null done rootdisk=`mount 2> /dev/null | grep " on / " | cut -d' ' -f1` major=`ls -l $rootdisk | tr -s ' ' | cut -d' ' -f5 | cut -d',' -f1` rootdisk=`basename $rootdisk` mknod dev/$rootdisk b $major 0 sleep 4 # Just a little time for the last of ulocal pids to die. mount -o remount,ro / > /dev/null 2>&1 echo $echo_e "\n\n\n\n\n This device is being updated!" > /dev/tty1 echo $echo_e "\n DO NOT Power off unless instructed to do so!\c" > /dev/tty1 echo $echo_e "\nRe-flashing the internal drive. This may take up to 30 minutes." echo $echo_e "The thin client will reboot when done. Please wait...\c" echo '#!/bin/bash' > .flash echo "export PATH=/bin:/sbin" >> .flash echo "$image" | grep "\.gz$" > /dev/null if [ $? -eq 0 ]; then echo "gzip -c -d mnt/$image | dd of=/dev/$rootdisk bs=1k" >> .flash else echo "dd if=mnt/$image of=/dev/$rootdisk bs=1k" >> .flash fi sync echo "/bin/sync" >> .flash echo "/bin/sleep 10" >> .flash echo "/sbin/reboot -f" >> .flash chmod 755 .flash chroot /tmp /bin/bash ./.flash