-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
70 lines (61 loc) · 2.09 KB
/
setup.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
import sys
import os
import re
from cx_Freeze import setup, Executable
import cryptography
from cryptography.fernet import Fernet
from cpuinfo import get_cpu_info
from hashlib import sha256
import json
# generate crypto key
key = Fernet.generate_key()
# generate cpu fingerprint
def make_cpu_fingerprint():
cpuinfo = get_cpu_info()
del cpuinfo['python_version']
fingerprint = sha256(json.dumps(cpuinfo).encode('utf-8')).hexdigest()
return fingerprint
if os.getenv('LNIC_USE_FINGERPRINT'):
fprint = make_cpu_fingerprint()
if os.getenv('LNIC_USE_PASSPHRASE'):
if len(os.getenv('LNIC_USE_PASSPHRASE')) < 6:
sys.exit('Passphrase must be 6+ symbols.')
tmp_phrase = os.getenv('LNIC_USE_PASSPHRASE')
pphrase = sha256(tmp_phrase.encode('utf-8')).hexdigest()
# update entry point
newFile = ''
with open('main.py', 'r') as file:
fileContent = file.readlines()
for line in fileContent:
if 'ENC_KEY =' in line:
line = f'ENC_KEY = \'{key.decode()}\'\n'
newFile += line
if os.getenv('LNIC_USE_FINGERPRINT'):
if 'CPU_FINGER =' in line:
line = f'CPU_FINGER = \'{fprint}\'\n'
newFile += line
if os.getenv('LNIC_USE_PASSPHRASE'):
if 'PASSPHRASE =' in line:
line = f'PASSPHRASE = \'{pphrase}\'\n'
newFile += line
writeFile = open('main.py', 'w')
writeFile.write(newFile)
writeFile.close()
# Dependencies are automatically detected, but it might need fine tuning.
if sys.version_info >= (3,8):
build_exe_options = {
"packages": ["nic_api", "dns.resolver", "tld", "cryptography", "argparse", "slack_webhook", "telegram"]
}
else:
build_exe_options = {
"packages": ["nic_api", "dns.resolver", "tld", "cryptography", "argparse", "slack_webhook", "telegram"],
"build_exe": "build"
}
setup(
name = "letsencrypt-nic",
version = "1.4",
description = "letsencrypt-nic",
options = {"build_exe": build_exe_options},
executables = [Executable("auth.py"), Executable("clean.py"), Executable("main.py")]
)
print('Compile completed!')