Jakob Borg 13 năm trước cách đây
commit
ae70ab27c3
2 tập tin đã thay đổi với 144 bổ sung0 xóa
  1. 61 0
      README.md
  2. 83 0
      platform-upgrade

+ 61 - 0
README.md

@@ -0,0 +1,61 @@
+smartos-platform-upgrade
+========================
+
+A script to simplify upgrades of USB booted SmartOS installations.
+
+Installation
+------------
+
+Drop the script in `/opt/local/bin` on the GZ.
+
+Usage
+-----
+
+Run the script. It'll find the USB stick, download the latest platform from
+Joyent, do the upgrade and report its status. The download and update platform
+stages will probably take a few minutes each.
+
+```
+[root@00-25-90-7d-03-8b ~]# platform-upgrade
+Checking current boot device... detected /dev/dsk/c0t0d0p1, mounted, OK
+Downloading latest platform... OK
+Verifying checksum... OK
+Extracting platform... OK
+Updating platform on boot device... OK
+Activating new platform on boot device... OK
+
+Boot device upgraded. To do:
+
+ 1) Sanity check the contents of /tmp/tmp.KCaawL/usb
+ 2) umount /dev/dsk/c0t0d0p1
+ 3) reboot
+[root@00-25-90-7d-03-8b ~]# 
+```
+
+Once the upgrade is done, verify that the contents of the USB stick looks sane,
+unmount it and reboot to the new platform.
+
+```
+[root@00-25-90-7d-03-8b ~]# ls -l /tmp/tmp.KCaawL/usb
+total 24
+drwxrwxrwx   1 root     root        4096 Jan  3  2011 boot
+drwxrwxrwx   1 root     root        4096 Dec 28 16:03 platform
+drwxrwxrwx   1 root     root        4096 Dec 28 15:24 platform.old
+[root@00-25-90-7d-03-8b ~]# ls -l /tmp/tmp.KCaawL/usb/platform
+total 9
+drwxrwxrwx   1 root     root        4096 Dec 28 16:03 i86pc
+-rwxrwxrwx   1 root     root          17 Dec 28 02:40 root.password
+[root@00-25-90-7d-03-8b ~]# umount /dev/dsk/c0t0d0p1
+[root@00-25-90-7d-03-8b ~]# reboot
+```
+
+By default, the first removable device found is assumed to be the boot USB
+stick. If this is not the case, the correct device name can be given on the
+command line:
+
+```
+[root@00-25-90-38-94-04 ~]# platform-upgrade /dev/dsk/c1t0d0p1
+Checking current boot device... using /dev/dsk/c1t0d0p1, mounted, OK
+Downloading latest platform...
+```
+

+ 83 - 0
platform-upgrade

@@ -0,0 +1,83 @@
+#!/bin/bash
+       
+TMP=$(mktemp -d)
+cd $TMP || exit -1
+
+echo -n "Checking current boot device..."
+if [ "x$1" == "x" ] ; then
+        USB=$(rmformat | grep Logical | awk '{print $4}' | sed 's/rdsk/dsk/;s/p0$/p1/')
+        echo -n " detected $USB"
+else   
+        USB=$1
+        echo -n " using $USB"
+fi     
+
+umount $USB 2>/dev/null
+mkdir usb
+if ( ! mount -F pcfs -o foldcase $USB $TMP/usb ) ; then
+        echo ", mount failed"
+	exit -1
+else
+	echo -n ", mounted"
+fi
+
+if [ ! -d usb/platform ] ; then
+        echo ", missing platform dir"
+        exit -1
+else
+	echo ", OK"
+fi     
+       
+echo -n "Downloading latest platform..."
+if ( !  curl -sk -o platform-latest.tgz https://download.joyent.com/pub/iso/platform-latest.tgz ) ; then
+        echo " failed"
+        exit -1
+else
+	echo " OK"
+fi
+       
+echo -n "Verifying checksum..."
+curl -sk https://download.joyent.com/pub/iso/md5sums.txt \
+	| grep platform-latest.tgz \
+	| awk '{print $1}' > expected.md5
+openssl md5 platform-latest.tgz | awk '{print $2}' > actual.md5
+if ( ! cmp -s actual.md5 expected.md5 ) ; then
+        echo " failed"
+        exit -1
+else
+	echo " OK"
+fi
+
+echo -n "Extracting platform..."
+if ( ! gtar zxf platform-latest.tgz ) ; then
+        echo " failed"
+        exit -1
+else
+	echo " OK"
+fi
+
+echo -n "Updating platform on boot device..."
+if ( ! rsync -a platform-20*/ usb/platform.new/ ) ; then
+        echo " failed"
+        exit -1
+else
+	echo " OK"
+fi
+
+echo -n "Activating new platform on boot device..."
+rm -rf usb/platform.old
+if ( ! ( mv usb/platform usb/platform.old && mv usb/platform.new usb/platform ) ) ; then
+	echo " failed"
+	echo " *** Your boot device might now be in an inconsistent state ***"
+	exit -1
+else
+	echo " OK"
+fi
+
+echo
+echo "Boot device upgraded. To do:"
+echo
+echo " 1) Sanity check the contents of $TMP/usb"
+echo " 2) umount $USB"
+echo " 3) reboot"
+