BASH   55

flget

Guest on 24th November 2022 03:21:05 PM

  1. #!/bin/sh
  2.  
  3. if [ -r /etc/flashsite ]; then
  4.   . /etc/flashsite
  5. else
  6.   echo $0: cannot read /etc/flashsite
  7.   exit 1
  8. fi
  9.  
  10. set `sed -En -e '/^#/d' -e 's,^(/dev/[ad][ad].)s([12])a.*$,\1 \2,p' /etc/fstab` >/dev/null
  11.  
  12. if [ "$2" = 1 ]; then
  13.   new=2
  14. elif [ "$2" = 2 ]; then
  15.   new=1
  16. else
  17.   echo $0: cannot parse root partition name in /etc/fstab
  18.   exit 1
  19. fi
  20.  
  21. drive=$1
  22. newpart=$1s$new
  23. export FTP_USER FTP_PASSWORD HTTP_AUTH
  24.  
  25. echo Downloading image to $newpart...
  26. rm -f /tmp/.updated
  27. #sysctl kern.geom.debugflags=16
  28. if ( fetch -v -o - $url && touch /tmp/.updated ) | bunzip2 2>/dev/null | \
  29.   dd obs=64k of=$newpart
  30. then
  31.   [ -e /tmp/.updated ] || exit 1
  32.  
  33.   echo Correcting fstab...
  34.   mount ${newpart}a /mnt || exit 1
  35.   sed -i.bak s,$1s$2,$newpart, /mnt/etc/fstab /mnt/conf/base/etc/fstab
  36.  
  37.   echo Correcting loader.conf...
  38. #  sed -E -i.bak s/\(vfs.root.mountfrom=\"ufs:\).*/\\1${newpart#/dev/}a\"/ /mnt/boot/loader.conf
  39.   mount -u -o rw /
  40.   sed -E -i.bak s/\(vfs.root.mountfrom=\"ufs:\).*/\\1${newpart#/dev/}a\"/ /mnt/boot/loader.conf /boot/loader.conf
  41.   umount /mnt
  42.   mount -u -o ro /
  43.  
  44.   echo Correcting boot0...
  45. #  boot0cfg -s $new $1
  46. #  sysctl kern.geom.debugflags=0
  47.   gpart set -a active -i $new $drive
  48. fi
  49. echo Finished

Raw Paste


Login or Register to edit or fork this paste. It's free.