platform-upgrade 3.0 KB

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