Browse Source

Installer build script for *nix systems.

Adam Ierymenko 11 years ago
parent
commit
34302edcc5
6 changed files with 138 additions and 45 deletions
  1. 1 0
      .gitignore
  2. 1 1
      Makefile.linux
  3. 70 0
      buildinstaller.sh
  4. 61 39
      installer.cpp
  5. 2 2
      main.cpp
  6. 3 3
      node/Updater.cpp

+ 1 - 0
.gitignore

@@ -29,3 +29,4 @@ mac-tap/tuntap/tap.kext
 *.obj
 *.obj
 *.tlog
 *.tlog
 /installer-build
 /installer-build
+/zt1-*-install

+ 1 - 1
Makefile.linux

@@ -43,7 +43,7 @@ file2lz4c: ext/lz4/lz4hc.o FORCE
 	$(CXX) $(CXXFLAGS) -o file2lz4c file2lz4c.cpp node/Utils.cpp node/Salsa20.cpp ext/lz4/lz4hc.o
 	$(CXX) $(CXXFLAGS) -o file2lz4c file2lz4c.cpp node/Utils.cpp node/Salsa20.cpp ext/lz4/lz4hc.o
 
 
 clean:
 clean:
-	rm -f $(OBJS) file2lz4c zerotier-*
+	rm -f $(OBJS) file2lz4c zerotier-* zt1-*-install
 	rm -rf installer-build
 	rm -rf installer-build
 
 
 FORCE:
 FORCE:

+ 70 - 0
buildinstaller.sh

@@ -0,0 +1,70 @@
+#!/bin/bash
+
+make -j 4 one file2lz4c
+
+if [ ! -f file2lz4c ]; then
+	echo "Build of file2lz4c utility failed, aborting installer build."
+	exit 2
+fi
+
+if [ ! -f zerotier-one ]; then
+	echo "Build of zerotier-one 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)
+		case "$machine" in
+			i386|i486|i586|i686)
+				machine="x86"
+				;;
+			x86_64|amd64|x64)
+				machine="x64"
+				;;
+			*)
+				echo "Unknonwn machine type: $machine"
+				exit 2
+		esac
+		echo "Assembling Linux installer for $machine and ZT1 version $vmajor.$vminor.$revision"
+
+		./file2lz4c installer/linux/uninstall.sh uninstall_sh >installer-build/uninstall_sh.h
+		./file2lz4c installer/linux/init.d/zerotier-one linux__init_d__zerotier_one >installer-build/linux__init_d__zerotier_one.h
+
+		ls -l installer-build
+
+		g++ -Os -o "zt1-${vmajor}_${vminor}_${revision}-linux-${machine}-install" installer.cpp ext/lz4/lz4.o ext/lz4/lz4hc.o
+
+		;;
+
+	Darwin)
+		echo "Assembling OSX installer for x86/x64 (combined) and ZT1 version $vmajor.$vminor.$revision"
+
+		;;
+
+	*)
+		echo "Unsupported platform: $system"
+		exit 2
+
+esac
+
+exit 0

+ 61 - 39
installer.cpp

@@ -25,6 +25,11 @@
  * LLC. Start here: http://www.zerotier.com/
  * LLC. Start here: http://www.zerotier.com/
  */
  */
 
 
+/*
+ * This can be run to install ZT1 for the first time or to update it. It
+ * carries all payloads internally as LZ4 compressed blobs.
+ */
+
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
@@ -35,7 +40,6 @@
 #include "version.h"
 #include "version.h"
 
 
 #ifdef __WINDOWS__
 #ifdef __WINDOWS__
-#include <WinSock2.h>
 #include <Windows.h>
 #include <Windows.h>
 #include <tchar.h>
 #include <tchar.h>
 #include <wchar.h>
 #include <wchar.h>
@@ -50,40 +54,40 @@
 #include "ext/lz4/lz4.h"
 #include "ext/lz4/lz4.h"
 #include "ext/lz4/lz4hc.h"
 #include "ext/lz4/lz4hc.h"
 
 
-// Include generated binaries -------------------------------------------------
+// Include Lz4 comrpessed blobs -----------------------------------------------
 
 
 // zerotier-one binary (or zerotier-one.exe for Windows)
 // zerotier-one binary (or zerotier-one.exe for Windows)
-#include "installer-build/zerotier_one.c"
+#include "installer-build/zerotier_one.h"
 
 
 // Unix uninstall script, installed in home for user to remove
 // Unix uninstall script, installed in home for user to remove
 #ifdef __UNIX_LIKE__
 #ifdef __UNIX_LIKE__
-#include "installer-build/uninstall_sh.c"
+#include "installer-build/uninstall_sh.h"
 #endif
 #endif
 
 
 // Linux init.d script
 // Linux init.d script
 #ifdef __LINUX__
 #ifdef __LINUX__
-#include "installer-build/init_d__zerotier_one.c"
+#include "installer-build/linux__init_d__zerotier_one.h"
 #endif
 #endif
 
 
 // Apple Tap device driver
 // Apple Tap device driver
 #ifdef __APPLE__
 #ifdef __APPLE__
-#include "installer-build/tap_mac__Info_plist.c"
-#include "installer-build/tap_mac__tap.c"
+#include "installer-build/tap_mac__Info_plist.h"
+#include "installer-build/tap_mac__tap.h"
 #endif
 #endif
 
 
-// Windows Tap device drivers
+// Windows Tap device drivers for x86 and x64 (installer will be x86)
 #ifdef __WINDOWS__
 #ifdef __WINDOWS__
-#include "installer-build/tap_windows__x64__ztTap100_sys.c"
-#include "installer-build/tap_windows__x64__ztTap100_inf.c"
-#include "installer-build/tap_windows__x86__ztTap100_sys.c"
-#include "installer-build/tap_windows__x86__ztTap100_inf.c"
-#include "installer-build/tap_windows__devcon32_exe.c"
-#include "installer-build/tap_windows__devcon64_exe.c"
+#include "installer-build/tap_windows__x64__ztTap100_sys.h"
+#include "installer-build/tap_windows__x64__ztTap100_inf.h"
+#include "installer-build/tap_windows__x86__ztTap100_sys.h"
+#include "installer-build/tap_windows__x86__ztTap100_inf.h"
+#include "installer-build/tap_windows__devcon32_exe.h"
+#include "installer-build/tap_windows__devcon64_exe.h"
 #endif
 #endif
 
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 
 
-static unsigned char *unlz4(const void *lz4,int decompressedLen)
+static unsigned char *_unlz4(const void *lz4,int decompressedLen)
 {
 {
 	unsigned char *buf = new unsigned char[decompressedLen];
 	unsigned char *buf = new unsigned char[decompressedLen];
 	if (LZ4_decompress_fast((const char *)lz4,(char *)buf,decompressedLen) != decompressedLen) {
 	if (LZ4_decompress_fast((const char *)lz4,(char *)buf,decompressedLen) != decompressedLen) {
@@ -93,9 +97,9 @@ static unsigned char *unlz4(const void *lz4,int decompressedLen)
 	return buf;
 	return buf;
 }
 }
 
 
-static bool _instFile(const void *lz4,int decompressedLen,const char *path)
+static bool _putBlob(const void *lz4,int decompressedLen,const char *path)
 {
 {
-	unsigned char *data = unlzr(lz4,decompressedLen);
+	unsigned char *data = _unlz4(lz4,decompressedLen);
 	if (!data)
 	if (!data)
 		return false;
 		return false;
 #ifdef __WINDOWS__
 #ifdef __WINDOWS__
@@ -122,7 +126,10 @@ static bool _instFile(const void *lz4,int decompressedLen,const char *path)
 	delete [] data;
 	delete [] data;
 	return true;
 	return true;
 }
 }
-#define instFile(name,path) _instFile(name,name##_UNCOMPRESSED_LEN,path)
+
+#define putBlob(name,path) _putBlob(name,name##_UNCOMPRESSED_LEN,path)
+
+// ----------------------------------------------------------------------------
 
 
 #ifdef __WINDOWS__
 #ifdef __WINDOWS__
 int _tmain(int argc, _TCHAR* argv[])
 int _tmain(int argc, _TCHAR* argv[])
@@ -130,99 +137,114 @@ int _tmain(int argc, _TCHAR* argv[])
 int main(int argc,char **argv)
 int main(int argc,char **argv)
 #endif
 #endif
 {
 {
-	char buf[4096];
+#ifdef __UNIX_LIKE__ // -------------------------------------------------------
 
 
-#ifdef __UNIX_LIKE__
+	char buf[4096];
 
 
 	if (getuid() != 0) {
 	if (getuid() != 0) {
-		fprintf(stderr,"ZeroTier One installer must be run as root.\n");
+		printf("! ZeroTier One installer must be run as root.\n");
 		return 2;
 		return 2;
 	}
 	}
 
 
+	printf("# ZeroTier One installer/updater starting...\n");
+
 	const char *zthome;
 	const char *zthome;
 #ifdef __APPLE__
 #ifdef __APPLE__
 	mkdir("/Library/Application Support/ZeroTier",0755);
 	mkdir("/Library/Application Support/ZeroTier",0755);
 	chmod("/Library/Application Support/ZeroTier",0755);
 	chmod("/Library/Application Support/ZeroTier",0755);
 	chown("/Library/Application Support/ZeroTier",0,0);
 	chown("/Library/Application Support/ZeroTier",0,0);
+	printf("mkdir /Library/Application Support/ZeroTier\n");
 	mkdir(zthome = "/Library/Application Support/ZeroTier/One",0755);
 	mkdir(zthome = "/Library/Application Support/ZeroTier/One",0755);
 #else
 #else
 	mkdir("/var/lib",0755);
 	mkdir("/var/lib",0755);
+	printf("mkdir /var/lib\n");
 	mkdir(zthome = "/var/lib/zerotier-one",0755);
 	mkdir(zthome = "/var/lib/zerotier-one",0755);
 #endif
 #endif
 	chmod(zthome,0755);
 	chmod(zthome,0755);
 	chown(zthome,0,0);
 	chown(zthome,0,0);
+	printf("mkdir %s\n",zthome);
 
 
 	sprintf(buf,"%s/zerotier-one",zthome);
 	sprintf(buf,"%s/zerotier-one",zthome);
-	if (!instFile(zerotier_one,buf)) {
-		fprintf(stderr,"Unable to write %s\n",buf);
+	if (!putBlob(zerotier_one,buf)) {
+		printf("! unable to write %s\n",buf);
 		return 1;
 		return 1;
 	}
 	}
 	chmod(buf,0755);
 	chmod(buf,0755);
 	chown(buf,0,0);
 	chown(buf,0,0);
-	fprintf(stdout,"%s\n",buf);
+	printf("write %s\n",buf);
 
 
 	sprintf(buf,"%s/uninstall.sh",zthome);
 	sprintf(buf,"%s/uninstall.sh",zthome);
-	if (!instFile(uninstall_sh,buf)) {
-		fprintf(stderr,"Unable to write %s\n",buf);
+	if (!putBlob(uninstall_sh,buf)) {
+		printf("! unable to write %s\n",buf);
 		return 1;
 		return 1;
 	}
 	}
 	chmod(buf,0755);
 	chmod(buf,0755);
 	chown(buf,0,0);
 	chown(buf,0,0);
-	fprintf(stdout,"%s\n",buf);
+	printf("write %s\n",buf);
 
 
 #ifdef __APPLE__
 #ifdef __APPLE__
 	sprintf(buf,"%s/tap.kext");
 	sprintf(buf,"%s/tap.kext");
 	mkdir(buf,0755);
 	mkdir(buf,0755);
 	chmod(buf,0755);
 	chmod(buf,0755);
 	chown(buf,0,0);
 	chown(buf,0,0);
+	printf("mkdir %s\n",buf);
 	sprintf(buf,"%s/tap.kext/Contents");
 	sprintf(buf,"%s/tap.kext/Contents");
 	mkdir(buf,0755);
 	mkdir(buf,0755);
 	chmod(buf,0755);
 	chmod(buf,0755);
 	chown(buf,0,0);
 	chown(buf,0,0);
+	printf("mkdir %s\n",buf);
 	sprintf(buf,"%s/tap.kext/Contents/MacOS");
 	sprintf(buf,"%s/tap.kext/Contents/MacOS");
 	mkdir(buf,0755);
 	mkdir(buf,0755);
 	chmod(buf,0755);
 	chmod(buf,0755);
 	chown(buf,0,0);
 	chown(buf,0,0);
+	printf("mkdir %s\n",buf);
 	sprintf(buf,"%s/tap.kext/Contents/Info.plist",zthome);
 	sprintf(buf,"%s/tap.kext/Contents/Info.plist",zthome);
-	if (!instFile(tap_mac__Info_plist,buf)) {
-		fprintf(stderr,"Unable to write %s\n",buf);
+	if (!putBlob(tap_mac__Info_plist,buf)) {
+		printf("! unable to write %s\n",buf);
 		return 1;
 		return 1;
 	}
 	}
 	chmod(buf,0644);
 	chmod(buf,0644);
 	chown(buf,0,0);
 	chown(buf,0,0);
-	fprintf(stdout,"%s\n",buf);
+	printf("write %s\n",buf);
 	sprintf(buf,"%s/tap.kext/Contents/MacOS/tap",zthome);
 	sprintf(buf,"%s/tap.kext/Contents/MacOS/tap",zthome);
-	if (!instFile(tap_mac__tap,buf)) {
-		fprintf(stderr,"Unable to write %s\n",buf);
+	if (!putBlob(tap_mac__tap,buf)) {
+		printf("! unable to write %s\n",buf);
 		return 1;
 		return 1;
 	}
 	}
 	chmod(buf,0755);
 	chmod(buf,0755);
 	chown(buf,0,0);
 	chown(buf,0,0);
-	fprintf(stdout,"%s\n",buf);
+	printf("write %s\n",buf);
 #endif
 #endif
 
 
 #ifdef __LINUX__
 #ifdef __LINUX__
 	sprintf(buf,"/etc/init.d/zerotier-one");
 	sprintf(buf,"/etc/init.d/zerotier-one");
-	if (!instFile(init_d__zerotier_one,buf)) {
-		fprintf(stderr,"Unable to write %s\n",buf);
+	if (!putBlob(linux__init_d__zerotier_one,buf)) {
+		printf("! unable to write %s\n",buf);
 		return 1;
 		return 1;
 	}
 	}
 	chown(buf,0,0);
 	chown(buf,0,0);
 	chmod(buf,0755);
 	chmod(buf,0755);
-	fprintf(stdout,"%s\n",buf);
+	printf("write %s\n",buf);
 
 
 	symlink("/etc/init.d/zerotier-one","/etc/rc0.d/K89zerotier-one");
 	symlink("/etc/init.d/zerotier-one","/etc/rc0.d/K89zerotier-one");
+	printf("link /etc/init.d/zerotier-one /etc/rc0.d/K89zerotier-one\n");
 	symlink("/etc/init.d/zerotier-one","/etc/rc2.d/S11zerotier-one");
 	symlink("/etc/init.d/zerotier-one","/etc/rc2.d/S11zerotier-one");
+	printf("link /etc/init.d/zerotier-one /etc/rc2.d/S11zerotier-one\n");
 	symlink("/etc/init.d/zerotier-one","/etc/rc3.d/S11zerotier-one");
 	symlink("/etc/init.d/zerotier-one","/etc/rc3.d/S11zerotier-one");
+	printf("link /etc/init.d/zerotier-one /etc/rc3.d/S11zerotier-one\n");
 	symlink("/etc/init.d/zerotier-one","/etc/rc4.d/S11zerotier-one");
 	symlink("/etc/init.d/zerotier-one","/etc/rc4.d/S11zerotier-one");
+	printf("link /etc/init.d/zerotier-one /etc/rc4.d/S11zerotier-one\n");
 	symlink("/etc/init.d/zerotier-one","/etc/rc5.d/S11zerotier-one");
 	symlink("/etc/init.d/zerotier-one","/etc/rc5.d/S11zerotier-one");
+	printf("link /etc/init.d/zerotier-one /etc/rc5.d/S11zerotier-one\n");
 #endif
 #endif
 
 
-#endif // __UNIX_LIKE__
+	printf("# Done!\n");
 
 
-#ifdef __WINDOWS__
+#endif // __UNIX_LIKE__ -------------------------------------------------------
+
+#ifdef __WINDOWS__ // ---------------------------------------------------------
 
 
-#endif // __WINDOWS__
+#endif // __WINDOWS__ ---------------------------------------------------------
 
 
 	return 0;
 	return 0;
 }
 }

+ 2 - 2
main.cpp

@@ -162,7 +162,7 @@ int main(int argc,char **argv)
 	mkdir(homeDir,0755); // will fail if it already exists
 	mkdir(homeDir,0755); // will fail if it already exists
 	{
 	{
 		char pidpath[4096];
 		char pidpath[4096];
-		Utils::snrpintf(pidpath,sizeof(pidpath),"%s/zerotier-one.pid",homeDir);
+		Utils::snprintf(pidpath,sizeof(pidpath),"%s/zerotier-one.pid",homeDir);
 		FILE *pf = fopen(pidpath,"w");
 		FILE *pf = fopen(pidpath,"w");
 		if (pf) {
 		if (pf) {
 			fprintf(pf,"%ld",(long)getpid());
 			fprintf(pf,"%ld",(long)getpid());
@@ -192,7 +192,7 @@ int main(int argc,char **argv)
 #ifdef __UNIX_LIKE__
 #ifdef __UNIX_LIKE__
 	{
 	{
 		char pidpath[4096];
 		char pidpath[4096];
-		Utils::snrpintf(pidpath,sizeof(pidpath),"%s/zerotier-one.pid",homeDir);
+		Utils::snprintf(pidpath,sizeof(pidpath),"%s/zerotier-one.pid",homeDir);
 		Utils::rm(pidpath);
 		Utils::rm(pidpath);
 	}
 	}
 #endif
 #endif

+ 3 - 3
node/Updater.cpp

@@ -357,14 +357,14 @@ std::string Updater::generateUpdateFilename(unsigned int vMajor,unsigned int vMi
 #if defined(__i386) || defined(__i486) || defined(__i586) || defined(__i686) || defined(__amd64) || defined(__x86_64) || defined(i386)
 #if defined(__i386) || defined(__i486) || defined(__i586) || defined(__i686) || defined(__amd64) || defined(__x86_64) || defined(i386)
 #define _updSupported 1
 #define _updSupported 1
 	char buf[128];
 	char buf[128];
-	Utils::snprintf(buf,sizeof(buf),"zt1-%u_%u_%u-linux-%s-update",vMajor,vMinor,revision,(sizeof(void *) == 8) ? "x64" : "x86");
+	Utils::snprintf(buf,sizeof(buf),"zt1-%u_%u_%u-linux-%s-install",vMajor,vMinor,revision,(sizeof(void *) == 8) ? "x64" : "x86");
 	return std::string(buf);
 	return std::string(buf);
 #endif
 #endif
 /*
 /*
 #if defined(__arm__) || defined(__arm) || defined(__aarch64__)
 #if defined(__arm__) || defined(__arm) || defined(__aarch64__)
 #define _updSupported 1
 #define _updSupported 1
 	char buf[128];
 	char buf[128];
-	Utils::snprintf(buf,sizeof(buf),"zt1-%u_%u_%u-linux-%s-update",vMajor,vMinor,revision,(sizeof(void *) == 8) ? "arm64" : "arm32");
+	Utils::snprintf(buf,sizeof(buf),"zt1-%u_%u_%u-linux-%s-install",vMajor,vMinor,revision,(sizeof(void *) == 8) ? "arm64" : "arm32");
 	return std::string(buf);
 	return std::string(buf);
 #endif
 #endif
 */
 */
@@ -380,7 +380,7 @@ std::string Updater::generateUpdateFilename(unsigned int vMajor,unsigned int vMi
 	return std::string();
 	return std::string();
 #endif
 #endif
 	char buf[128];
 	char buf[128];
-	Utils::snprintf(buf,sizeof(buf),"zt1-%u_%u_%u-mac-x86combined-update",vMajor,vMinor,revision);
+	Utils::snprintf(buf,sizeof(buf),"zt1-%u_%u_%u-mac-x86combined-install",vMajor,vMinor,revision);
 	return std::string(buf);
 	return std::string(buf);
 #endif
 #endif