platform-upgrade 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. TMP=$(mktemp -d)
  3. cd $TMP || exit -1
  4. echo -n "Checking current boot device..."
  5. if [ "x$1" == "x" ] ; then
  6. USB=$(rmformat | grep Logical | awk '{print $4}' | sed 's/rdsk/dsk/;s/p0$/p1/')
  7. echo -n " detected $USB"
  8. else
  9. USB=$1
  10. echo -n " using $USB"
  11. fi
  12. umount $USB 2>/dev/null
  13. mkdir usb
  14. if ( ! mount -F pcfs -o foldcase $USB $TMP/usb ) ; then
  15. echo ", mount failed"
  16. exit -1
  17. else
  18. echo -n ", mounted"
  19. fi
  20. if [ ! -d usb/platform ] ; then
  21. echo ", missing platform dir"
  22. exit -1
  23. else
  24. echo ", OK"
  25. fi
  26. echo -n "Downloading latest platform..."
  27. if ( ! curl -sk -o platform-latest.tgz https://download.joyent.com/pub/iso/platform-latest.tgz ) ; then
  28. echo " failed"
  29. exit -1
  30. else
  31. echo " OK"
  32. fi
  33. echo -n "Verifying checksum..."
  34. curl -sk https://download.joyent.com/pub/iso/md5sums.txt \
  35. | grep platform-latest.tgz \
  36. | awk '{print $1}' > expected.md5
  37. openssl md5 platform-latest.tgz | awk '{print $2}' > actual.md5
  38. if ( ! cmp -s actual.md5 expected.md5 ) ; then
  39. echo " failed"
  40. exit -1
  41. else
  42. echo " OK"
  43. fi
  44. echo -n "Extracting platform..."
  45. if ( ! gtar zxf platform-latest.tgz ) ; then
  46. echo " failed"
  47. exit -1
  48. else
  49. echo " OK"
  50. fi
  51. echo -n "Updating platform on boot device..."
  52. if ( ! rsync -a platform-20*/ usb/platform.new/ ) ; then
  53. echo " failed"
  54. exit -1
  55. else
  56. echo " OK"
  57. fi
  58. echo -n "Activating new platform on boot device..."
  59. rm -rf usb/platform.old
  60. if ( ! ( mv usb/platform usb/platform.old && mv usb/platform.new usb/platform ) ) ; then
  61. echo " failed"
  62. echo " *** Your boot device might now be in an inconsistent state ***"
  63. exit -1
  64. else
  65. echo " OK"
  66. fi
  67. echo
  68. echo "Boot device upgraded. To do:"
  69. echo
  70. echo " 1) Sanity check the contents of $TMP/usb"
  71. echo " 2) umount $USB"
  72. echo " 3) reboot"