2013-11-08 16:42:11 +00:00
#!/bin/bash
2013-11-13 14:07:59 +00:00
# This script builds the installer for *nix systems. Windows must do everything
# completely differently, as usual.
2013-11-08 16:42:11 +00:00
2014-01-04 00:53:00 +00:00
export PATH = /bin:/usr/bin:/sbin:/usr/sbin
2013-11-13 14:07:59 +00:00
if [ ! -f zerotier-one ] ; then
echo "Could not find 'zerotier-one' binary, please build before running this script."
2013-11-08 16:42:11 +00:00
exit 2
fi
machine = ` uname -m`
system = ` uname -s`
vmajor = ` cat version.h | grep -F ZEROTIER_ONE_VERSION_MAJOR | cut -d ' ' -f 3`
vminor = ` cat version.h | grep -F ZEROTIER_ONE_VERSION_MINOR | cut -d ' ' -f 3`
revision = ` cat version.h | grep -F ZEROTIER_ONE_VERSION_REVISION | cut -d ' ' -f 3`
if [ -z " $vmajor " -o -z " $vminor " -o -z " $revision " ] ; then
echo "Unable to extract version info from version.h, aborting installer build."
exit 2
fi
2014-01-04 00:53:00 +00:00
rm -rf build-installer
mkdir build-installer
2013-11-08 16:42:11 +00:00
case " $system " in
Linux)
2013-11-13 14:07:59 +00:00
# Canonicalize $machine for some architectures... we use x86
# and x64 for Intel stuff. ARM and others should be fine if
# we ever ship officially for those.
2014-12-03 21:40:33 +00:00
debian_arch = $machine
2013-11-08 16:42:11 +00:00
case " $machine " in
i386| i486| i586| i686)
machine = "x86"
2014-12-03 21:40:33 +00:00
debian_arch = "i386"
2013-11-08 16:42:11 +00:00
; ;
x86_64| amd64| x64)
machine = "x64"
2014-12-03 21:40:33 +00:00
debian_arch = "amd64"
2013-11-08 16:42:11 +00:00
; ;
2014-12-04 22:38:49 +00:00
armv6l| arm| armhf)
machine = "armv6l"
debian_arch = "armhf"
; ;
2013-11-08 16:42:11 +00:00
esac
2013-11-13 14:07:59 +00:00
2014-01-04 00:53:00 +00:00
echo " Assembling Linux installer for $machine and version $vmajor . $vminor . $revision "
2013-11-08 16:42:11 +00:00
2015-06-11 15:56:54 +00:00
mkdir -p 'build-installer/var/lib/zerotier-one/ui'
2014-01-04 00:53:00 +00:00
cp -fp 'ext/installfiles/linux/uninstall.sh' 'build-installer/var/lib/zerotier-one'
cp -fp 'zerotier-one' 'build-installer/var/lib/zerotier-one'
2015-06-11 15:56:54 +00:00
for f in ui/*.html ui/*.js ui/*.css ui/*.jsx ; do
cp -fp " $f " 'build-installer/var/lib/zerotier-one/ui'
done
2014-02-14 23:18:59 +00:00
mkdir -p 'build-installer/tmp'
cp -fp 'ext/installfiles/linux/init.d/zerotier-one' 'build-installer/tmp/init.d_zerotier-one'
cp -fp 'ext/installfiles/linux/systemd/zerotier-one.service' 'build-installer/tmp/systemd_zerotier-one.service'
2013-12-13 21:49:46 +00:00
2014-01-04 00:53:00 +00:00
targ = " ZeroTierOneInstaller-linux- ${ machine } - ${ vmajor } _ ${ vminor } _ ${ revision } "
2014-01-06 18:11:32 +00:00
# Use gzip in Linux since some minimal Linux systems do not have bunzip2
2014-01-04 00:53:00 +00:00
rm -f build-installer-tmp.tar.gz
cd build-installer
tar -cf - * | gzip -9 >../build-installer-tmp.tar.gz
cd ..
rm -f $targ
cat ext/installfiles/linux/install.tmpl.sh build-installer-tmp.tar.gz >$targ
2014-01-04 00:53:55 +00:00
chmod 0755 $targ
2014-01-04 00:53:00 +00:00
rm -f build-installer-tmp.tar.gz
2014-01-06 18:11:32 +00:00
ls -l $targ
2013-11-08 22:37:47 +00:00
2014-12-03 21:40:33 +00:00
if [ -f /usr/bin/dpkg-deb -a " $UID " -eq 0 ] ; then
echo
echo Found dpkg-deb and you are root, trying to build Debian package.
2014-12-03 22:09:17 +00:00
2014-12-03 21:40:33 +00:00
rm -rf build-installer-deb
2014-12-03 22:09:17 +00:00
2015-06-03 00:14:18 +00:00
debbase = " build-installer-deb/zerotier-one_ ${ vmajor } . ${ vminor } . ${ revision } _ $debian_arch "
2014-12-03 21:40:33 +00:00
debfolder = " ${ debbase } /DEBIAN "
mkdir -p $debfolder
2014-12-03 22:09:17 +00:00
2015-06-03 00:14:18 +00:00
cat 'ext/installfiles/linux/DEBIAN/control.in' | sed " s/__VERSION__/ ${ vmajor } . ${ vminor } . ${ revision } / " | sed " s/__ARCH__/ ${ debian_arch } / " >$debfolder /control
2014-12-03 22:09:17 +00:00
cat $debfolder /control
2014-12-03 21:40:33 +00:00
cp -f 'ext/installfiles/linux/DEBIAN/conffiles' " ${ debfolder } /conffiles "
2014-12-03 22:09:17 +00:00
mkdir -p " ${ debbase } /var/lib/zerotier-one/updates.d "
cp -f $targ " ${ debbase } /var/lib/zerotier-one/updates.d "
rm -f " ${ debfolder } /postinst " " ${ debfolder } /prerm "
echo '#!/bin/bash' >${ debfolder } /postinst
echo " /var/lib/zerotier-one/updates.d/ ${ targ } " >>${ debfolder } /postinst
echo "/bin/rm -f /var/lib/zerotier-one/updates.d/*" >>${ debfolder } /postinst
chmod a+x ${ debfolder } /postinst
echo '#!/bin/bash' >${ debfolder } /prerm
2014-12-04 21:28:03 +00:00
echo 'export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin' >>${ debfolder } /prerm
echo 'if [ "$1" != "upgrade" ]; then' >>${ debfolder } /prerm
echo ' /var/lib/zerotier-one/uninstall.sh' >>${ debfolder } /prerm
echo 'fi' >>${ debfolder } /prerm
2014-12-03 22:09:17 +00:00
chmod a+x ${ debfolder } /prerm
2014-12-03 21:40:33 +00:00
dpkg-deb --build $debbase
2014-12-03 22:09:17 +00:00
2014-12-03 21:40:33 +00:00
mv -f build-installer-deb/*.deb .
rm -rf build-installer-deb
fi
2014-12-05 01:12:59 +00:00
if [ -f /usr/bin/rpmbuild ] ; then
echo
echo Found rpmbuild, trying to build RedHat/CentOS package.
rm -f /tmp/zerotier-one.spec
curr_dir = ` pwd `
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
rpmbuild -ba /tmp/zerotier-one.spec
rm -f /tmp/zerotier-one.spec
fi
2013-11-08 16:42:11 +00:00
; ;
*)
echo " Unsupported platform: $system "
exit 2
esac
2014-12-03 21:40:33 +00:00
rm -rf build-installer
2013-11-08 16:42:11 +00:00
exit 0