platform-upgrade 3.1 KB

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