updater.tmpl.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. export PATH=/bin:/usr/bin:/sbin:/usr/sbin
  3. shopt -s expand_aliases
  4. if [ "$UID" -ne 0 ]; then
  5. echo '*** Auto-updater must be run as root.'
  6. exit 1
  7. fi
  8. scriptPath="`dirname "$0"`/`basename "$0"`"
  9. if [ ! -s "$scriptPath" ]; then
  10. scriptPath="$0"
  11. if [ ! -s "$scriptPath" ]; then
  12. echo "*** Auto-updater cannot determine its own path; $scriptPath is not readable."
  13. exit 2
  14. fi
  15. fi
  16. endMarkerIndex=`grep -a -b -E '^################' "$scriptPath" | head -c 16 | cut -d : -f 1`
  17. if [ "$endMarkerIndex" -le 100 ]; then
  18. echo 'Internal error: unable to find end of script / start of binary data marker.'
  19. exit 2
  20. fi
  21. blobStart=`expr $endMarkerIndex + 17`
  22. if [ "$blobStart" -le "$endMarkerIndex" ]; then
  23. echo 'Internal error: unable to find end of script / start of binary data marker.'
  24. exit 2
  25. fi
  26. rm -f /tmp/ZeroTierOne-update.pkg
  27. tail -c +$blobStart "$scriptPath" >/tmp/ZeroTierOne-update.pkg
  28. chmod 0600 /tmp/ZeroTierOne-update.pkg
  29. if [ -s /tmp/ZeroTierOne-update.pkg ]; then
  30. rm -f '/Library/Application Support/ZeroTier/One/latest-update.exe' '/Library/Application Support/ZeroTier/One/latest-update.json' /tmp/ZeroTierOne-update.log
  31. installer -verbose -pkg /tmp/ZeroTierOne-update.pkg -target / >/tmp/ZeroTierOne-update.log 2>&1
  32. rm -f /tmp/ZeroTierOne-update.pkg
  33. exit 0
  34. else
  35. echo '*** Error self-unpacking update!'
  36. exit 3
  37. fi
  38. # Do not remove the last line or add a carriage return to it! The installer
  39. # looks for an unterminated line beginning with 16 #'s in itself to find
  40. # the binary blob data, which is appended after it.
  41. ################