Skip to content

Instantly share code, notes, and snippets.

@jfqd
Forked from sjorge/usbupdate
Created May 28, 2019 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfqd/44626534b43b0a7f3997d321ac61026a to your computer and use it in GitHub Desktop.
Save jfqd/44626534b43b0a7f3997d321ac61026a to your computer and use it in GitHub Desktop.
#!/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