Created
May 28, 2019 11:42
-
-
Save sjorge/5f83ceecda845c92ac09b5c041cfe7d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
## CONFIG | |
# Lookup USBKEY: disklist -r | |
AUTO_REBOOT=1 | |
MIRROR=us-east.manta.joyent.com | |
USBKEY=c1t0d0 | |
## INIT | |
CURRENT_REFERENCE=$(curl -s -k https://${MIRROR}/Joyent_Dev/public/builds/smartos/ | grep release | tail -n 1 | json name) | |
CURRENT_REFERENCE=$(curl -s -k https://${MIRROR}/Joyent_Dev/public/builds/smartos/${CURRENT_REFERENCE}/) | |
CURRENT_PLATFORM=$(curl -s -k https://${MIRROR}/${CURRENT_REFERENCE}/smartos/ | grep platform- | json name) | |
ACTIVE_TIMESTAMP=$(uname -a | awk '{ print $4 }' | cut -d"_" -f2) | |
CURRENT_TIMESTAMP=$(echo ${CURRENT_PLATFORM} | cut -d"-" -f2 | cut -d"." -f1) | |
ACTIVE_DATE=$(echo ${ACTIVE_TIMESTAMP} | cut -d'T' -f1) | |
CURRENT_DATE=$(echo ${CURRENT_TIMESTAMP} | cut -d'T' -f1) | |
if [ $CURRENT_DATE -gt $ACTIVE_DATE ]; then | |
cd /tmp | |
curl -O -s -k https://${MIRROR}/${CURRENT_REFERENCE}/smartos/${CURRENT_PLATFORM} | |
curl -O -s -k https://${MIRROR}/${CURRENT_REFERENCE}/smartos/md5sums.txt | |
PLATFORM_HASH=$(digest -a md5 $CURRENT_PLATFORM) | |
VERIFY_HASH=$(grep platform md5sums.txt | awk '{ print $1 }') | |
if [ "$PLATFORM_HASH" == "$VERIFY_HASH" ]; then | |
mount -F pcfs /dev/dsk/${USBKEY}s2 /mnt | |
tar xf /tmp/${CURRENT_PLATFORM} -C /mnt/ 2> /dev/null > /dev/null | |
[ -d /mnt/backup ] && rm -rf /mnt/backup | |
mv /mnt/platform /mnt/backup | |
mv /mnt/platform-* /mnt/platform | |
umount /mnt | |
fi | |
rm platform-* | |
rm md5sums.txt | |
if [ $AUTO_REBOOT -gt 0 ]; then | |
shutdown -i6 -g0 -y | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment