platform-upgrade 3.4 KB

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