forked from TunSafe/TunSafe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
102 lines (84 loc) · 3.56 KB
/
build.py
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
102
# SPDX-License-Identifier: AGPL-1.0-only
# Copyright (C) 2018 Ludvig Strigeus <[email protected]>. All Rights Reserved.
import os
import shutil
import win32crypt
import base64
import sys
import zipfile
import re
import json
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'))
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)
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)
#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]
BASE = os.getcwd()
if command == 'build_tap':
Run(r'%s /V4 installer\tap\tap-windows6.nsi' % CONFIG["NSIS_PATH"])
SignExe(r'installer\tap\TunSafe-TAP-9.21.2.exe')
sys.exit(0)
if command != 'skip_build':
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"])
if 1:
try:
os.mkdir(BASE + r'\installer\x86')
except OSError:
pass
CopyFile(BASE + r'\build\Win32_Release\TunSafe.exe', BASE + r'\installer\x86\TunSafe.exe')
CopyFile(BASE + r'\build\Win32_Release\ts.exe', BASE + r'\installer\x86\TunSafe.com')
SignExe(BASE + r'\installer\x86\TunSafe.exe')
SignExe(BASE + r'\installer\x86\TunSafe.com')
try:
os.mkdir(BASE + r'\installer\x64')
except OSError:
pass
CopyFile(BASE + r'\build\x64_Release\TunSafe.exe', BASE + r'\installer\x64\TunSafe.exe')
CopyFile(BASE + r'\build\x64_Release\ts.exe', BASE + r'\installer\x64\TunSafe.com')
SignExe(BASE + r'\installer\x64\TunSafe.exe')
SignExe(BASE + r'\installer\x64\TunSafe.com')
VERSION = GetVersion()
Run(r'%s /V4 -DPRODUCT_VERSION=%s installer\tunsafe.nsi ' % (CONFIG["NSIS_PATH"], VERSION))
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')
zipf.write(BASE + r'\installer\x86\TunSafe.com', 'TunSafe.com')
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')
zipf.write(BASE + r'\installer\x64\TunSafe.com', 'TunSafe.com')
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()