buildinstaller.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #!/bin/bash
  2. # This script builds the installer for *nix systems. Windows must do everything
  3. # completely differently, as usual.
  4. export PATH=/bin:/usr/bin:/sbin:/usr/sbin
  5. if [ ! -f zerotier-one ]; then
  6. echo "Could not find 'zerotier-one' binary, please build before running this script."
  7. exit 2
  8. fi
  9. machine=`uname -m`
  10. system=`uname -s`
  11. vmajor=`cat version.h | grep -F ZEROTIER_ONE_VERSION_MAJOR | cut -d ' ' -f 3`
  12. vminor=`cat version.h | grep -F ZEROTIER_ONE_VERSION_MINOR | cut -d ' ' -f 3`
  13. revision=`cat version.h | grep -F ZEROTIER_ONE_VERSION_REVISION | cut -d ' ' -f 3`
  14. if [ -z "$vmajor" -o -z "$vminor" -o -z "$revision" ]; then
  15. echo "Unable to extract version info from version.h, aborting installer build."
  16. exit 2
  17. fi
  18. rm -rf build-installer
  19. mkdir build-installer
  20. case "$system" in
  21. Linux)
  22. # Canonicalize $machine for some architectures... we use x86
  23. # and x64 for Intel stuff. ARM and others should be fine if
  24. # we ever ship officially for those.
  25. debian_arch=$machine
  26. case "$machine" in
  27. i386|i486|i586|i686)
  28. machine="x86"
  29. debian_arch="i386"
  30. ;;
  31. x86_64|amd64|x64)
  32. machine="x64"
  33. debian_arch="amd64"
  34. ;;
  35. armv6l|arm|armhf)
  36. machine="armv6l"
  37. debian_arch="armhf"
  38. ;;
  39. esac
  40. echo "Assembling Linux installer for $machine and version $vmajor.$vminor.$revision"
  41. mkdir -p 'build-installer/var/lib/zerotier-one'
  42. cp -fp 'ext/installfiles/linux/uninstall.sh' 'build-installer/var/lib/zerotier-one'
  43. cp -fp 'zerotier-one' 'build-installer/var/lib/zerotier-one'
  44. mkdir -p 'build-installer/tmp'
  45. cp -fp 'ext/installfiles/linux/init.d/zerotier-one' 'build-installer/tmp/init.d_zerotier-one'
  46. cp -fp 'ext/installfiles/linux/systemd/zerotier-one.service' 'build-installer/tmp/systemd_zerotier-one.service'
  47. targ="ZeroTierOneInstaller-linux-${machine}-${vmajor}_${vminor}_${revision}"
  48. # Use gzip in Linux since some minimal Linux systems do not have bunzip2
  49. rm -f build-installer-tmp.tar.gz
  50. cd build-installer
  51. tar -cf - * | gzip -9 >../build-installer-tmp.tar.gz
  52. cd ..
  53. rm -f $targ
  54. cat ext/installfiles/linux/install.tmpl.sh build-installer-tmp.tar.gz >$targ
  55. chmod 0755 $targ
  56. rm -f build-installer-tmp.tar.gz
  57. ls -l $targ
  58. if [ -f /usr/bin/dpkg-deb -a "$UID" -eq 0 ]; then
  59. echo
  60. echo Found dpkg-deb and you are root, trying to build Debian package.
  61. rm -rf build-installer-deb
  62. debbase="build-installer-deb/zerotier-one_${vmajor}.${vminor}.${revision}.autoupdating_$debian_arch"
  63. debfolder="${debbase}/DEBIAN"
  64. mkdir -p $debfolder
  65. cat 'ext/installfiles/linux/DEBIAN/control.in' | sed "s/__VERSION__/${vmajor}.${vminor}.${revision}.autoupdating/" | sed "s/__ARCH__/${debian_arch}/" >$debfolder/control
  66. cat $debfolder/control
  67. cp -f 'ext/installfiles/linux/DEBIAN/conffiles' "${debfolder}/conffiles"
  68. mkdir -p "${debbase}/var/lib/zerotier-one/updates.d"
  69. cp -f $targ "${debbase}/var/lib/zerotier-one/updates.d"
  70. rm -f "${debfolder}/postinst" "${debfolder}/prerm"
  71. echo '#!/bin/bash' >${debfolder}/postinst
  72. echo "/var/lib/zerotier-one/updates.d/${targ}" >>${debfolder}/postinst
  73. echo "/bin/rm -f /var/lib/zerotier-one/updates.d/*" >>${debfolder}/postinst
  74. chmod a+x ${debfolder}/postinst
  75. echo '#!/bin/bash' >${debfolder}/prerm
  76. echo 'export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin' >>${debfolder}/prerm
  77. echo 'if [ "$1" != "upgrade" ]; then' >>${debfolder}/prerm
  78. echo ' /var/lib/zerotier-one/uninstall.sh' >>${debfolder}/prerm
  79. echo 'fi' >>${debfolder}/prerm
  80. chmod a+x ${debfolder}/prerm
  81. dpkg-deb --build $debbase
  82. mv -f build-installer-deb/*.deb .
  83. rm -rf build-installer-deb
  84. fi
  85. if [ -f /usr/bin/rpmbuild ]; then
  86. echo
  87. echo Found rpmbuild, trying to build RedHat/CentOS package.
  88. rm -f /tmp/zerotier-one.spec
  89. curr_dir=`pwd`
  90. cat ext/installfiles/linux/RPM/zerotier-one.spec.in | sed "s/__VERSION__/${vmajor}.${vminor}.${revision}/g" | sed "s/__INSTALLER__/${targ}/g" >/tmp/zerotier-one.spec
  91. rpmbuild -ba /tmp/zerotier-one.spec
  92. rm -f /tmp/zerotier-one.spec
  93. fi
  94. ;;
  95. Darwin)
  96. echo "Assembling mac installer for x86/x64 (combined) version $vmajor.$vminor.$revision"
  97. mkdir -p 'build-installer/Applications'
  98. cp -a 'build-ZeroTierUI-release/ZeroTier One.app' 'build-installer/Applications'
  99. mkdir -p 'build-installer/Library/Application Support/ZeroTier/One'
  100. cp -fp 'ext/installfiles/mac/uninstall.sh' 'build-installer/Library/Application Support/ZeroTier/One'
  101. cp -fp 'ext/installfiles/mac/launch.sh' 'build-installer/Library/Application Support/ZeroTier/One'
  102. cp -fp 'zerotier-one' 'build-installer/Library/Application Support/ZeroTier/One'
  103. cp -fRp ext/bin/tap-mac/* 'build-installer/Library/Application Support/ZeroTier/One'
  104. mkdir -p 'build-installer/Library/LaunchDaemons'
  105. cp -fp 'ext/installfiles/mac/com.zerotier.one.plist' 'build-installer/Library/LaunchDaemons'
  106. targ="ZeroTierOneInstaller-mac-combined-${vmajor}_${vminor}_${revision}"
  107. rm -f build-installer-tmp.tar.bz2
  108. cd build-installer
  109. find . -type f -name .DS_Store -print0 | xargs -0 rm -f
  110. tar -cf - * | bzip2 -9 >../build-installer-tmp.tar.bz2
  111. cd ..
  112. rm -f $targ
  113. cat ext/installfiles/mac/install.tmpl.sh build-installer-tmp.tar.bz2 >$targ
  114. chmod 0755 $targ
  115. rm -f build-installer-tmp.tar.bz2
  116. ls -l $targ
  117. ;;
  118. *)
  119. echo "Unsupported platform: $system"
  120. exit 2
  121. esac
  122. rm -rf build-installer
  123. exit 0