summaryrefslogtreecommitdiff
path: root/buildinstaller.sh
blob: c2778d65394d0fd79e54a16b1b42ec5adb793328 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash

# This script builds the installer for *nix systems. Windows must do everything
# completely differently, as usual.

if [ ! -f zerotier-one ]; then
	echo "Could not find 'zerotier-one' binary, please build before running this script."
	exit 2
fi

make -j 2 file2lz4c
if [ ! -f file2lz4c ]; then
	echo "Build of file2lz4c utility failed, aborting installer build."
	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

echo "Packaging common files: zerotier-one"

rm -rf installer-build
mkdir installer-build

./file2lz4c zerotier-one zerotier_one >installer-build/zerotier_one.h

case "$system" in

	Linux)
		# 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.
		case "$machine" in
			i386|i486|i586|i686)
				machine="x86"
				;;
			x86_64|amd64|x64)
				machine="x64"
				;;
			*)
				echo "Unsupported machine type: $machine"
				exit 2
		esac

		echo "Assembling Linux installer for $machine and ZT1 version $vmajor.$vminor.$revision"

		./file2lz4c ext/installfiles/linux/uninstall.sh uninstall_sh >installer-build/uninstall_sh.h
		./file2lz4c ext/installfiles/linux/init.d/zerotier-one linux__init_d__zerotier_one >installer-build/linux__init_d__zerotier_one.h

		targ="zt1-${vmajor}_${vminor}_${revision}-linux-${machine}-install"

		if [ -e /usr/bin/clang ]; then
			clang -Os -o $targ installer.c ext/lz4/lz4.o ext/lz4/lz4hc.o
		else
			gcc -Os -o $targ installer.c ext/lz4/lz4.o ext/lz4/lz4hc.o
		fi
		strip --strip-all $targ
		ls -l $targ

		;;

	Darwin)
		echo "Assembling mac installer for x86/x64 (combined) and ZT1 version $vmajor.$vminor.$revision"

		./file2lz4c ext/installfiles/mac/uninstall.sh uninstall_sh >installer-build/uninstall_sh.h
		./file2lz4c ext/installfiles/mac/launch.sh mac__launch_sh >installer-build/mac__launch_sh.h
		./file2lz4c ext/installfiles/mac/com.zerotier.one.plist mac__com_zerotier_one_plist >installer-build/mac__com_zerotier_one_plist.h
		./file2lz4c ext/bin/tap-mac/tap.kext/Contents/Info.plist tap_mac__Info_plist >installer-build/tap_mac__Info_plist.h
		./file2lz4c ext/bin/tap-mac/tap.kext/Contents/MacOS/tap tap_mac__tap >installer-build/tap_mac__tap.h
		./file2lz4c "build-ZeroTierUI-release/ZeroTier One.app/Contents/Info.plist" mac_ui__contents_info_plist >installer-build/mac_ui__contents_info_plist.h
		./file2lz4c "build-ZeroTierUI-release/ZeroTier One.app/Contents/PkgInfo" mac_ui__contents_pkginfo >installer-build/mac_ui__contents_pkginfo.h
		./file2lz4c "build-ZeroTierUI-release/ZeroTier One.app/Contents/MacOS/ZeroTier One" mac_ui__contents_macos_zerotier_one >installer-build/mac_ui__contents_macos_zerotier_one.h
		./file2lz4c "build-ZeroTierUI-release/ZeroTier One.app/Contents/Resources/empty.lproj" mac_ui__contents_resources_empty_lproj >installer-build/mac_ui__contents_resources_empty_lproj.h
		./file2lz4c "build-ZeroTierUI-release/ZeroTier One.app/Contents/Resources/zt1icon.icns" mac_ui__contents_resources_zt1icon_icns >installer-build/mac_ui__contents_resources_zt1icon_icns.h

		targ="zt1-${vmajor}_${vminor}_${revision}-mac-combined-install"

		# Installer can be i386-only to save space, but installs combined
		# x86/x64 binaries for ZT1 itself.
		clang -Os -arch i386 -o $targ installer.c ext/lz4/lz4.o ext/lz4/lz4hc.o
		strip $targ
		ls -l $targ

		;;

	*)
		echo "Unsupported platform: $system"
		exit 2

esac

exit 0