install.tmpl.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. export PATH=/bin:/usr/bin:/sbin:/usr/sbin
  3. shopt -s expand_aliases
  4. dryRun=0
  5. echo "*** ZeroTier One install/update ***"
  6. if [ "$UID" -ne 0 ]; then
  7. echo "Not running as root so doing dry run (no modifications to system)..."
  8. dryRun=1
  9. fi
  10. if [ $dryRun -gt 0 ]; then
  11. alias ln="echo '>> dry run: ln'"
  12. alias rm="echo '>> dry run: rm'"
  13. alias mv="echo '>> dry run: mv'"
  14. alias chown="echo '>> dry run: chown'"
  15. alias chgrp="echo '>> dry run: chgrp'"
  16. alias chkconfig="echo '>> dry run: chkconfig'"
  17. alias zerotier-cli="echo '>> dry run: zerotier-cli'"
  18. alias service="echo '>> dry run: service'"
  19. fi
  20. scriptPath="`dirname "$0"`/`basename "$0"`"
  21. if [ ! -r "$scriptPath" ]; then
  22. scriptPath="$0"
  23. if [ ! -r "$scriptPath" ]; then
  24. echo "Installer cannot determine its own path; $scriptPath is not readable."
  25. exit 2
  26. fi
  27. fi
  28. endMarkerIndex=`grep -a -b -E '^################' "$scriptPath" | head -c 16 | cut -d : -f 1`
  29. if [ "$endMarkerIndex" -le 100 ]; then
  30. echo 'Internal error: unable to find end of script / start of binary data marker.'
  31. exit 2
  32. fi
  33. blobStart=`expr $endMarkerIndex + 17`
  34. if [ "$blobStart" -le "$endMarkerIndex" ]; then
  35. echo 'Internal error: unable to find end of script / start of binary data marker.'
  36. exit 2
  37. fi
  38. echo 'Extracting files...'
  39. if [ $dryRun -gt 0 ]; then
  40. echo ">> dry run: tail -c +$blobStart \"$scriptPath\" | gunzip -c | tar -xvop -C / -f -"
  41. else
  42. tail -c +$blobStart "$scriptPath" | gunzip -c | tar -xvop -C / -f -
  43. fi
  44. if [ $dryRun -eq 0 -a ! -d "/var/lib/zerotier-one" ]; then
  45. echo 'Archive extraction failed, cannot find zerotier-one binary in "/var/lib/zerotier-one".'
  46. exit 2
  47. fi
  48. echo 'Installing zerotier-cli command line utility...'
  49. rm -f /usr/bin/zerotier-cli
  50. ln -sf /var/lib/zerotier-one/zerotier-one /usr/bin/zerotier-cli
  51. echo 'Installing and (re-)starting zerotier-one daemon...'
  52. chkconfig zerotier-one on
  53. service zerotier-one restart
  54. sleep 1
  55. zerotier-cli info
  56. exit 0
  57. # Do not remove the last line or add a carriage return to it! The installer
  58. # looks for an unterminated line beginning with 16 #'s in itself to find
  59. # the binary blob data, which is appended after it.
  60. ################