mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-21 05:53:09 +00:00
Installer build script for *nix systems.
This commit is contained in:
parent
c93de67d79
commit
34302edcc5
1
.gitignore
vendored
1
.gitignore
vendored
@ -29,3 +29,4 @@ mac-tap/tuntap/tap.kext
|
||||
*.obj
|
||||
*.tlog
|
||||
/installer-build
|
||||
/zt1-*-install
|
||||
|
@ -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
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) file2lz4c zerotier-*
|
||||
rm -f $(OBJS) file2lz4c zerotier-* zt1-*-install
|
||||
rm -rf installer-build
|
||||
|
||||
FORCE:
|
||||
|
70
buildinstaller.sh
Executable file
70
buildinstaller.sh
Executable file
@ -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
|
100
installer.cpp
100
installer.cpp
@ -25,6 +25,11 @@
|
||||
* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -35,7 +40,6 @@
|
||||
#include "version.h"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
#include <tchar.h>
|
||||
#include <wchar.h>
|
||||
@ -50,40 +54,40 @@
|
||||
#include "ext/lz4/lz4.h"
|
||||
#include "ext/lz4/lz4hc.h"
|
||||
|
||||
// Include generated binaries -------------------------------------------------
|
||||
// Include Lz4 comrpessed blobs -----------------------------------------------
|
||||
|
||||
// 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
|
||||
#ifdef __UNIX_LIKE__
|
||||
#include "installer-build/uninstall_sh.c"
|
||||
#include "installer-build/uninstall_sh.h"
|
||||
#endif
|
||||
|
||||
// Linux init.d script
|
||||
#ifdef __LINUX__
|
||||
#include "installer-build/init_d__zerotier_one.c"
|
||||
#include "installer-build/linux__init_d__zerotier_one.h"
|
||||
#endif
|
||||
|
||||
// Apple Tap device driver
|
||||
#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
|
||||
|
||||
// Windows Tap device drivers
|
||||
// Windows Tap device drivers for x86 and x64 (installer will be x86)
|
||||
#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
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
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];
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
return false;
|
||||
#ifdef __WINDOWS__
|
||||
@ -122,7 +126,10 @@ static bool _instFile(const void *lz4,int decompressedLen,const char *path)
|
||||
delete [] data;
|
||||
return true;
|
||||
}
|
||||
#define instFile(name,path) _instFile(name,name##_UNCOMPRESSED_LEN,path)
|
||||
|
||||
#define putBlob(name,path) _putBlob(name,name##_UNCOMPRESSED_LEN,path)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
int _tmain(int argc, _TCHAR* argv[])
|
||||
@ -130,99 +137,114 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
int main(int argc,char **argv)
|
||||
#endif
|
||||
{
|
||||
#ifdef __UNIX_LIKE__ // -------------------------------------------------------
|
||||
|
||||
char buf[4096];
|
||||
|
||||
#ifdef __UNIX_LIKE__
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
printf("# ZeroTier One installer/updater starting...\n");
|
||||
|
||||
const char *zthome;
|
||||
#ifdef __APPLE__
|
||||
mkdir("/Library/Application Support/ZeroTier",0755);
|
||||
chmod("/Library/Application Support/ZeroTier",0755);
|
||||
chown("/Library/Application Support/ZeroTier",0,0);
|
||||
printf("mkdir /Library/Application Support/ZeroTier\n");
|
||||
mkdir(zthome = "/Library/Application Support/ZeroTier/One",0755);
|
||||
#else
|
||||
mkdir("/var/lib",0755);
|
||||
printf("mkdir /var/lib\n");
|
||||
mkdir(zthome = "/var/lib/zerotier-one",0755);
|
||||
#endif
|
||||
chmod(zthome,0755);
|
||||
chown(zthome,0,0);
|
||||
printf("mkdir %s\n",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;
|
||||
}
|
||||
chmod(buf,0755);
|
||||
chown(buf,0,0);
|
||||
fprintf(stdout,"%s\n",buf);
|
||||
printf("write %s\n",buf);
|
||||
|
||||
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;
|
||||
}
|
||||
chmod(buf,0755);
|
||||
chown(buf,0,0);
|
||||
fprintf(stdout,"%s\n",buf);
|
||||
printf("write %s\n",buf);
|
||||
|
||||
#ifdef __APPLE__
|
||||
sprintf(buf,"%s/tap.kext");
|
||||
mkdir(buf,0755);
|
||||
chmod(buf,0755);
|
||||
chown(buf,0,0);
|
||||
printf("mkdir %s\n",buf);
|
||||
sprintf(buf,"%s/tap.kext/Contents");
|
||||
mkdir(buf,0755);
|
||||
chmod(buf,0755);
|
||||
chown(buf,0,0);
|
||||
printf("mkdir %s\n",buf);
|
||||
sprintf(buf,"%s/tap.kext/Contents/MacOS");
|
||||
mkdir(buf,0755);
|
||||
chmod(buf,0755);
|
||||
chown(buf,0,0);
|
||||
printf("mkdir %s\n",buf);
|
||||
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;
|
||||
}
|
||||
chmod(buf,0644);
|
||||
chown(buf,0,0);
|
||||
fprintf(stdout,"%s\n",buf);
|
||||
printf("write %s\n",buf);
|
||||
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;
|
||||
}
|
||||
chmod(buf,0755);
|
||||
chown(buf,0,0);
|
||||
fprintf(stdout,"%s\n",buf);
|
||||
printf("write %s\n",buf);
|
||||
#endif
|
||||
|
||||
#ifdef __LINUX__
|
||||
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;
|
||||
}
|
||||
chown(buf,0,0);
|
||||
chmod(buf,0755);
|
||||
fprintf(stdout,"%s\n",buf);
|
||||
printf("write %s\n",buf);
|
||||
|
||||
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");
|
||||
printf("link /etc/init.d/zerotier-one /etc/rc2.d/S11zerotier-one\n");
|
||||
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");
|
||||
printf("link /etc/init.d/zerotier-one /etc/rc4.d/S11zerotier-one\n");
|
||||
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 // __UNIX_LIKE__
|
||||
printf("# Done!\n");
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#endif // __UNIX_LIKE__ -------------------------------------------------------
|
||||
|
||||
#endif // __WINDOWS__
|
||||
#ifdef __WINDOWS__ // ---------------------------------------------------------
|
||||
|
||||
#endif // __WINDOWS__ ---------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
4
main.cpp
4
main.cpp
@ -162,7 +162,7 @@ int main(int argc,char **argv)
|
||||
mkdir(homeDir,0755); // will fail if it already exists
|
||||
{
|
||||
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");
|
||||
if (pf) {
|
||||
fprintf(pf,"%ld",(long)getpid());
|
||||
@ -192,7 +192,7 @@ int main(int argc,char **argv)
|
||||
#ifdef __UNIX_LIKE__
|
||||
{
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
|
@ -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)
|
||||
#define _updSupported 1
|
||||
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);
|
||||
#endif
|
||||
/*
|
||||
#if defined(__arm__) || defined(__arm) || defined(__aarch64__)
|
||||
#define _updSupported 1
|
||||
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);
|
||||
#endif
|
||||
*/
|
||||
@ -380,7 +380,7 @@ std::string Updater::generateUpdateFilename(unsigned int vMajor,unsigned int vMi
|
||||
return std::string();
|
||||
#endif
|
||||
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);
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user