platform-upgrade 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/bash
  2. # Select the official site or any of the mirrors by commenting out the correct line
  3. # MIRROR=https://download.joyent.com/pub/iso/
  4. MIRROR=http://smartos.nym.se/
  5. TMP=$(mktemp -d)
  6. cd "$TMP" || exit -1
  7. echo -n "Checking current boot device..."
  8. if [[ -z $1 ]] ; then
  9. USB=$(rmformat | grep Logical | awk '{print $4}' | sed 's/rdsk/dsk/;s/p0$/p1/')
  10. echo -n " detected $USB"
  11. else
  12. USB="$1"
  13. echo -n " using $USB"
  14. fi
  15. umount "$USB" 2>/dev/null
  16. mkdir usb
  17. if ! mount -F pcfs -o foldcase "$USB" "$TMP/usb" ; then
  18. echo ", mount failed"
  19. exit -1
  20. else
  21. echo -n ", mounted"
  22. fi
  23. if [[ ! -d usb/platform ]] ; then
  24. echo ", missing platform dir"
  25. exit -1
  26. else
  27. echo ", OK"
  28. fi
  29. echo -n "Downloading latest platform ($MIRROR)..."
  30. if ! curl -sk -o platform-latest.tgz "$MIRROR/platform-latest.tgz" ; then
  31. echo " failed"
  32. exit -1
  33. else
  34. echo " OK"
  35. fi
  36. echo -n "Verifying checksum..."
  37. curl -sk "$MIRROR/md5sums.txt" \
  38. | grep platform-latest.tgz \
  39. | awk '{print $1}' > expected.md5
  40. openssl md5 platform-latest.tgz | awk '{print $2}' > actual.md5
  41. if ! cmp -s actual.md5 expected.md5 ; then
  42. echo " failed"
  43. exit -1
  44. else
  45. echo " OK"
  46. fi
  47. echo -n "Extracting latest platform..."
  48. if ! gtar zxf platform-latest.tgz ; then
  49. echo " failed"
  50. exit -1
  51. else
  52. echo " OK"
  53. fi
  54. echo -n "Updating platform on boot device..."
  55. if ! rsync -a platform-20*/ usb/platform.new/ ; then
  56. echo " failed"
  57. exit -1
  58. else
  59. echo " OK"
  60. fi
  61. echo -n "Remounting boot device..."
  62. umount "$USB" 2>/dev/null
  63. if ! mount -F pcfs -o foldcase "$USB" "$TMP/usb" ; then
  64. echo " failed"
  65. exit -1
  66. else
  67. echo " OK"
  68. fi
  69. echo -n "Verifying kernel checksum on boot device..."
  70. openssl dgst -sha1 platform-20*/i86pc/kernel/amd64/unix | cut -d ' ' -f 2 > kernel.expected
  71. openssl dgst -sha1 usb/platform.new/i86pc/kernel/amd64/unix | cut -d ' ' -f 2 > kernel.actual
  72. if ! cmp -s kernel.actual kernel.expected ; then
  73. echo " failed"
  74. exit -1
  75. else
  76. echo " OK"
  77. fi
  78. echo -n "Verifying boot_archive checksum on boot device..."
  79. openssl dgst -sha1 usb/platform.new/i86pc/amd64/boot_archive | cut -d ' ' -f 2 > boot_archive.actual
  80. if ! cmp -s boot_archive.actual usb/platform.new/i86pc/amd64/boot_archive.hash ; then
  81. echo " failed"
  82. exit -1
  83. else
  84. echo " OK"
  85. fi
  86. echo -n "Activating new platform on $USB..."
  87. rm -rf usb/old
  88. mkdir usb/old
  89. if ! ( mv usb/platform usb/old && mv usb/platform.new usb/platform ) ; then
  90. echo " failed"
  91. exit -1
  92. else
  93. echo " OK"
  94. fi
  95. echo
  96. echo "Boot device upgraded. To do:"
  97. echo
  98. echo " 1) Sanity check the contents of $TMP/usb"
  99. echo " 2) umount $USB"
  100. echo " 3) reboot"