platform-upgrade 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. usb_count=(${usb})
  16. if [ ${#usb_count[@]} -gt 1 ]; then
  17. echo " Warning: more than one removable device detected."
  18. exit -1
  19. fi
  20. else
  21. usb="$1"
  22. echo -n " using $usb"
  23. fi
  24. umount "$usb" 2>/dev/null
  25. mkdir usb
  26. if ! mount -F pcfs -o foldcase "$usb" "$tmp/usb" ; then
  27. echo ", mount failed"
  28. exit -1
  29. else
  30. echo -n ", mounted"
  31. fi
  32. if [[ ! -d usb/platform ]] ; then
  33. echo ", missing platform dir"
  34. exit -1
  35. else
  36. echo ", OK"
  37. fi
  38. echo -n "Downloading latest platform ($platform_file)..."
  39. if ! curl -sk -o "$platform_file" "$platform_url" ; then
  40. echo " failed"
  41. exit -1
  42. else
  43. echo " OK"
  44. fi
  45. echo -n "Verifying checksum..."
  46. curl -sk "$md5sums_url" \
  47. | grep "$platform_file" \
  48. | awk '{print $1}' > expected.md5
  49. openssl md5 "$platform_file" | awk '{print $2}' > actual.md5
  50. if ! cmp -s actual.md5 expected.md5 ; then
  51. echo " failed"
  52. exit -1
  53. else
  54. echo " OK"
  55. fi
  56. echo -n "Extracting latest platform..."
  57. if ! gtar zxf "$platform_file" ; then
  58. echo " failed"
  59. exit -1
  60. else
  61. echo " OK"
  62. fi
  63. echo -n "Updating platform on boot device..."
  64. if ! rsync -a "$platform_dir/" usb/platform.new/ ; then
  65. echo " failed"
  66. exit -1
  67. else
  68. echo " OK"
  69. fi
  70. echo -n "Remounting boot device..."
  71. umount "$usb" 2>/dev/null
  72. if ! mount -F pcfs -o foldcase "$usb" "$tmp/usb" ; then
  73. echo " failed"
  74. exit -1
  75. else
  76. echo " OK"
  77. fi
  78. echo -n "Verifying kernel checksum on boot device..."
  79. openssl dgst -sha1 "$platform_dir"/i86pc/kernel/amd64/unix | cut -d ' ' -f 2 > kernel.expected
  80. openssl dgst -sha1 usb/platform.new/i86pc/kernel/amd64/unix | cut -d ' ' -f 2 > kernel.actual
  81. if ! cmp -s kernel.actual kernel.expected ; then
  82. echo " failed"
  83. exit -1
  84. else
  85. echo " OK"
  86. fi
  87. echo -n "Verifying boot_archive checksum on boot device..."
  88. openssl dgst -sha1 usb/platform.new/i86pc/amd64/boot_archive | cut -d ' ' -f 2 > boot_archive.actual
  89. if ! cmp -s boot_archive.actual usb/platform.new/i86pc/amd64/boot_archive.hash ; then
  90. echo " failed"
  91. exit -1
  92. else
  93. echo " OK"
  94. fi
  95. echo -n "Activating new platform on $usb..."
  96. rm -rf usb/old
  97. mkdir usb/old
  98. if ! ( mv usb/platform usb/old && mv usb/platform.new usb/platform ) ; then
  99. echo " failed"
  100. exit -1
  101. else
  102. echo " OK"
  103. fi
  104. echo
  105. echo "Boot device upgraded. To do:"
  106. echo
  107. echo " 1) Sanity check the contents of $tmp/usb"
  108. echo " 2) umount $usb"
  109. echo " 3) reboot"