-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-client
executable file
·60 lines (46 loc) · 1.92 KB
/
install-client
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
#!/usr/bin/env python3
import argparse
import os
print("\n### Installing VPN Client")
exec_path = "/usr/bin/start-vpn-client.sh"
servicefile_path = "/lib/systemd/system/vpnclient.service"
servicefile = """[Unit]
Description=Softether client
After=docker.service
[Service]
Type=oneshot
ExecStart={path}
[Install]
WantedBy=multi-user.target""".format(path=exec_path)
client_startcmd = "docker run -d --name=vpncli --privileged --net=host -e VPN_SERVER={server_ip} -e VPN_PORT={port} -e ACCOUNT_USER={user} -e ACCOUNT_PASS={pass} mitsutaka/softether-vpnclient"
def write_file(content, path):
print("\n### Writing file at " + path + " with:\n" + content)
exec_file = open(path, "w")
exec_file.write(content)
exec_file.close()
def main():
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--server_ip", help="VPN Server IP Address", required=True)
parser.add_argument("--port", help="VPN Server port", default=4434)
parser.add_argument("--user", help="Username used to authenticate", default="soft")
parser.add_argument("--pass", help="Password to use to authenticate", default="ether")
parser.add_argument("--client_ip", help="What IP address to assign to this client after connecting", required=True)
args = parser.parse_args()
write_file(
"#!/bin/bash\n" +
"docker stop vpncli || true\n" +
"docker rm vpncli || true\n" +
client_startcmd.format(**vars(args)) +
"\n" +
"sleep 5\n" +
"ifconfig vpn_default " + args.client_ip,
exec_path)
os.system("chmod 777 " + exec_path)
write_file(servicefile, servicefile_path)
os.system("systemctl daemon-reload")
os.system("systemctl enable docker")
os.system("systemctl start docker")
os.system("systemctl enable vpnclient.service")
os.system("systemctl start vpnclient.service")
if __name__ == "__main__":
main()