|
@@ -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;
|
|
}
|
|
}
|