summaryrefslogtreecommitdiff
path: root/branding/scripts/init
blob: ba9ce5231e342d2ae20cdb02e00d77ee8f833519 (plain)
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
103
104
105
106
107
108
#!/usr/bin/env python3
# (c) LEAP Encryption Access Project 2020
# License: GPL

import subprocess
import sys
import os

VENDOR_PATH = None
SCRIPT_NAME = sys.argv[0]
CA_README = "config/CERT.Readme"
ASSETS_README = "assets/FILES.Readme"

def initVendor():
    global VENDOR_PATH
    if not VENDOR_PATH:
        bail("ERROR: Please set VENDOR_PATH environment variable.")
    VENDOR_PATH = os.path.abspath(VENDOR_PATH)
    if os.path.isdir(VENDOR_PATH):
        bail("ERROR: VENDOR_PATH folder already exists")

    for d in ["config", "assets", "pkg"]:
        os.makedirs(os.path.join(VENDOR_PATH, d))

    initVendorConfig()
    initGitRepo() 
    displayRepoInfo()

def displayRepoInfo():
    print("[+] Initialized repo in", VENDOR_PATH)
    print(f"[ ] - Add the assets in the assets/ folder, see {ASSETS_README}.")
    print(f"[ ] - Add the CA certificate in the config/ folder, see {CA_README}.")
    print("[ ] - Remember to commit your changes.")
    print()
    print("[+] After doing that, you can run 'make vendor_check' to validate the configuration for your provider.")

def bail(msg=None):
    if not msg:
        print("ERROR: no arguments supported!")
        print('Usage: {scriptname}'.format(
            scriptname=SCRIPT_NAME))
    else:
        print(msg)
    sys.exit(1)

def getVendorPath():
    return os.environ.get('VENDOR_PATH')

def initVendorConfig():

    with open(os.path.join(VENDOR_PATH, "config", "vendor.conf"), "w") as f:
        f.write(CONF_TEMPLATE)

    with open(os.path.join(VENDOR_PATH, CA_README), "w") as f:
        f.write(CA_INFO)

    with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "ASSETS_LIST")) as f:
        allAssets = f.read()

    with open(os.path.join(VENDOR_PATH, ASSETS_README), "w") as f:
        f.write(ASSETS_INFO)
        f.write(allAssets)

def initGitRepo():
    out = subprocess.run(['git', 'init'], cwd=VENDOR_PATH)
    if out.returncode != 0:
        print(f'ERROR: cannot initialize git repo in {VENDOR_PATH}')


CONF_TEMPLATE = """[default]

provider = myprovider

[myprovider]

name                = MyProvider
applicationName     = MyProviderVPN
binaryName          = myprovider-vpn

providerURL         = example.org
auth                = anon
apiURL              = https://api.myprovider.net/
caURL               = https://myprovider.net/ca.crt

infoURL             = https://myprovider.net/vpn
tosURL              = https://myprovider.net/tos
helpURL             = https://myprovider.net/support

geolocationAPI      = https://myprovider.net:9001/json

askForDonations     = true
donateURL           = https://myprovider.net/vpn/donate
"""

CA_INFO = """Place in this folder your provider's CA certificate, with the name:

    <providerName>-ca.crt
"""

ASSETS_INFO = """This is the list of assets that you MUST place in this folder for your provider:

"""

if __name__ == "__main__":
    if len(sys.argv) != 1:
        bail()
    VENDOR_PATH = getVendorPath()
    initVendor()