2018-08-08 06:12:38 -05:00
|
|
|
# SPDX-License-Identifier: AGPL-1.0-only
|
|
|
|
# Copyright (C) 2018 Ludvig Strigeus <info@tunsafe.com>. All Rights Reserved.
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import win32crypt
|
|
|
|
import base64
|
|
|
|
import sys
|
|
|
|
import zipfile
|
|
|
|
import re
|
2018-10-07 18:21:34 -05:00
|
|
|
import json
|
2018-08-08 06:12:38 -05:00
|
|
|
|
2018-10-07 18:21:34 -05:00
|
|
|
CONFIG = json.loads(open('../misc/config/build_py_conf.json', 'r').read())
|
|
|
|
SIGNTOOL_PASS = str(win32crypt.CryptUnprotectData(base64.b64decode(CONFIG["SIGNTOOL_ENC_PASS"]), None, None, None, 0)[1].decode('utf-16-le'))
|
2018-08-08 06:12:38 -05:00
|
|
|
|
|
|
|
def RmTree(path):
|
|
|
|
try:
|
|
|
|
print ('Deleting %s' % path)
|
|
|
|
shutil.rmtree(path)
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def Run(s):
|
|
|
|
print ('Running %s' % s)
|
|
|
|
x = os.system(s)
|
|
|
|
if x:
|
|
|
|
raise Exception('Command failed (%d) : %s' % (x, s))
|
|
|
|
|
|
|
|
def CopyFile(src, dst):
|
|
|
|
shutil.copyfile(src, dst)
|
|
|
|
|
|
|
|
def SignExe(src):
|
|
|
|
print ('Signing %s' % src)
|
2018-10-07 18:21:34 -05:00
|
|
|
cmd = r'""%s" sign /f "%s" /p %s /t http://timestamp.verisign.com/scripts/timstamp.dll "%s"' % (CONFIG["SIGNTOOL_PATH"], CONFIG["SIGNTOOL_KEY_PATH"], SIGNTOOL_PASS, src)
|
2018-08-08 06:12:38 -05:00
|
|
|
#cmd = r'""c:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x86\signtool.exe" sign %s ' % (SIGNTOOL_KEY_PATH, )
|
|
|
|
x = os.system(cmd)
|
|
|
|
if x:
|
|
|
|
raise Exception('Signing failed (%d) : %s' % (x, cmd))
|
|
|
|
|
|
|
|
def GetVersion():
|
|
|
|
for line in open(BASE + '/tunsafe_config.h', 'r'):
|
|
|
|
m = re.match('^#define TUNSAFE_VERSION_STRING "TunSafe (.*)"$', line)
|
|
|
|
if m:
|
|
|
|
return m.group(1)
|
|
|
|
raise Exception('Version not found')
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
#os.system(r'""')
|
|
|
|
|
|
|
|
command = sys.argv[1]
|
|
|
|
|
2018-10-07 18:21:34 -05:00
|
|
|
BASE = os.getcwd()
|
2018-08-08 06:12:38 -05:00
|
|
|
|
|
|
|
if command == 'build_tap':
|
2018-10-07 18:21:34 -05:00
|
|
|
Run(r'%s /V4 installer\tap\tap-windows6.nsi' % CONFIG["NSIS_PATH"])
|
2018-08-08 06:12:38 -05:00
|
|
|
SignExe(r'installer\tap\TunSafe-TAP-9.21.2.exe')
|
|
|
|
sys.exit(0)
|
|
|
|
|
2018-12-16 16:29:38 -06:00
|
|
|
if command != 'skip_build':
|
2018-10-07 18:21:34 -05:00
|
|
|
RmTree(BASE + r'\build')
|
|
|
|
Run('%s TunSafe.sln /t:Clean;Rebuild /p:Configuration=Release /m /p:Platform=x64' % CONFIG["MSBUILD_PATH"])
|
|
|
|
Run('%s TunSafe.sln /t:Clean;Rebuild /p:Configuration=Release /m /p:Platform=Win32' % CONFIG["MSBUILD_PATH"])
|
2018-08-08 06:12:38 -05:00
|
|
|
|
|
|
|
if 1:
|
2018-10-07 18:21:34 -05:00
|
|
|
try:
|
|
|
|
os.mkdir(BASE + r'\installer\x86')
|
2018-12-16 16:29:38 -06:00
|
|
|
except OSError:
|
2018-10-07 18:21:34 -05:00
|
|
|
pass
|
|
|
|
CopyFile(BASE + r'\build\Win32_Release\TunSafe.exe', BASE + r'\installer\x86\TunSafe.exe')
|
2018-10-21 09:33:37 -05:00
|
|
|
CopyFile(BASE + r'\build\Win32_Release\ts.exe', BASE + r'\installer\x86\TunSafe.com')
|
2018-08-08 06:12:38 -05:00
|
|
|
SignExe(BASE + r'\installer\x86\TunSafe.exe')
|
2018-10-21 09:33:37 -05:00
|
|
|
SignExe(BASE + r'\installer\x86\TunSafe.com')
|
2018-10-07 18:21:34 -05:00
|
|
|
|
|
|
|
try:
|
|
|
|
os.mkdir(BASE + r'\installer\x64')
|
2018-12-16 16:29:38 -06:00
|
|
|
except OSError:
|
2018-10-07 18:21:34 -05:00
|
|
|
pass
|
|
|
|
CopyFile(BASE + r'\build\x64_Release\TunSafe.exe', BASE + r'\installer\x64\TunSafe.exe')
|
2018-10-21 09:33:37 -05:00
|
|
|
CopyFile(BASE + r'\build\x64_Release\ts.exe', BASE + r'\installer\x64\TunSafe.com')
|
2018-08-08 06:12:38 -05:00
|
|
|
SignExe(BASE + r'\installer\x64\TunSafe.exe')
|
2018-10-21 09:33:37 -05:00
|
|
|
SignExe(BASE + r'\installer\x64\TunSafe.com')
|
2018-08-08 06:12:38 -05:00
|
|
|
|
|
|
|
VERSION = GetVersion()
|
|
|
|
|
2018-10-07 18:21:34 -05:00
|
|
|
Run(r'%s /V4 -DPRODUCT_VERSION=%s installer\tunsafe.nsi ' % (CONFIG["NSIS_PATH"], VERSION))
|
2018-08-08 06:12:38 -05:00
|
|
|
SignExe(BASE + r'\installer\TunSafe-%s.exe' % VERSION)
|
|
|
|
|
|
|
|
zipf = zipfile.ZipFile(BASE + '\installer\TunSafe-%s-x86.zip' % VERSION, 'w', zipfile.ZIP_DEFLATED)
|
|
|
|
zipf.write(BASE + r'\installer\x86\TunSafe.exe', 'TunSafe.exe')
|
2018-10-21 09:33:37 -05:00
|
|
|
zipf.write(BASE + r'\installer\x86\TunSafe.com', 'TunSafe.com')
|
2018-08-08 06:12:38 -05:00
|
|
|
zipf.write(BASE + r'\installer\License.txt', 'License.txt')
|
|
|
|
zipf.write(BASE + r'\installer\ChangeLog.txt', 'ChangeLog.txt')
|
|
|
|
zipf.write(BASE + r'\installer\TunSafe.conf', 'Config\\TunSafe.conf')
|
|
|
|
zipf.close()
|
|
|
|
|
|
|
|
zipf = zipfile.ZipFile(BASE + '\installer\TunSafe-%s-x64.zip' % VERSION, 'w', zipfile.ZIP_DEFLATED)
|
|
|
|
zipf.write(BASE + r'\installer\x64\TunSafe.exe', 'TunSafe.exe')
|
2018-10-21 09:33:37 -05:00
|
|
|
zipf.write(BASE + r'\installer\x64\TunSafe.com', 'TunSafe.com')
|
2018-08-08 06:12:38 -05:00
|
|
|
zipf.write(BASE + r'\installer\License.txt', 'License.txt')
|
|
|
|
zipf.write(BASE + r'\installer\ChangeLog.txt', 'ChangeLog.txt')
|
|
|
|
zipf.write(BASE + r'\installer\TunSafe.conf', 'Config\\TunSafe.conf')
|
|
|
|
zipf.close()
|