platform-upgrade 2.9 KB

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