platform-upgrade 3.2 KB

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