buildinstaller.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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|arm7l|armv7l)
  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/ui'
  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. for f in ui/*.html ui/*.js ui/*.css ui/*.jsx ; do
  45. cp -fp "$f" 'build-installer/var/lib/zerotier-one/ui'
  46. done
  47. mkdir -p 'build-installer/tmp'
  48. cp -fp 'ext/installfiles/linux/init.d/zerotier-one' 'build-installer/tmp/init.d_zerotier-one'
  49. cp -fp 'ext/installfiles/linux/systemd/zerotier-one.service' 'build-installer/tmp/systemd_zerotier-one.service'
  50. targ="ZeroTierOneInstaller-linux-${machine}-${vmajor}_${vminor}_${revision}"
  51. # Use gzip in Linux since some minimal Linux systems do not have bunzip2
  52. rm -f build-installer-tmp.tar.gz
  53. cd build-installer
  54. tar -cf - * | gzip -9 >../build-installer-tmp.tar.gz
  55. cd ..
  56. rm -f $targ
  57. cat ext/installfiles/linux/install.tmpl.sh build-installer-tmp.tar.gz >$targ
  58. chmod 0755 $targ
  59. rm -f build-installer-tmp.tar.gz
  60. ls -l $targ
  61. if [ -f /usr/bin/dpkg-deb -a "$UID" -eq 0 ]; then
  62. echo
  63. echo Found dpkg-deb and you are root, trying to build Debian package.
  64. rm -rf build-installer-deb
  65. debbase="build-installer-deb/zerotier-one_${vmajor}.${vminor}.${revision}_$debian_arch"
  66. debfolder="${debbase}/DEBIAN"
  67. mkdir -p $debfolder
  68. cat 'ext/installfiles/linux/DEBIAN/control.in' | sed "s/__VERSION__/${vmajor}.${vminor}.${revision}/" | sed "s/__ARCH__/${debian_arch}/" >$debfolder/control
  69. cat $debfolder/control
  70. cp -f 'ext/installfiles/linux/DEBIAN/conffiles' "${debfolder}/conffiles"
  71. mkdir -p "${debbase}/var/lib/zerotier-one/updates.d"
  72. cp -f $targ "${debbase}/var/lib/zerotier-one/updates.d"
  73. rm -f "${debfolder}/postinst" "${debfolder}/prerm"
  74. echo '#!/bin/bash' >${debfolder}/postinst
  75. echo "/var/lib/zerotier-one/updates.d/${targ} >>/dev/null 2>&1" >>${debfolder}/postinst
  76. echo "/bin/rm -f /var/lib/zerotier-one/updates.d/*" >>${debfolder}/postinst
  77. chmod a+x ${debfolder}/postinst
  78. echo '#!/bin/bash' >${debfolder}/prerm
  79. echo 'export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin' >>${debfolder}/prerm
  80. echo 'if [ "$1" != "upgrade" ]; then' >>${debfolder}/prerm
  81. echo ' /var/lib/zerotier-one/uninstall.sh >>/dev/null 2>&1' >>${debfolder}/prerm
  82. echo 'fi' >>${debfolder}/prerm
  83. chmod a+x ${debfolder}/prerm
  84. dpkg-deb --build $debbase
  85. mv -f build-installer-deb/*.deb .
  86. rm -rf build-installer-deb
  87. fi
  88. if [ -f /usr/bin/rpmbuild ]; then
  89. echo
  90. echo Found rpmbuild, trying to build RedHat/CentOS package.
  91. rm -f /tmp/zerotier-one.spec
  92. curr_dir=`pwd`
  93. 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
  94. rpmbuild -ba /tmp/zerotier-one.spec
  95. rm -f /tmp/zerotier-one.spec
  96. fi
  97. ;;
  98. *)
  99. echo "Unsupported platform: $system"
  100. exit 2
  101. esac
  102. rm -rf build-installer
  103. exit 0