-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.py
More file actions
executable file
·83 lines (72 loc) · 3.4 KB
/
Copy pathinstaller.py
File metadata and controls
executable file
·83 lines (72 loc) · 3.4 KB
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
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# compile on linux with `sudo wine pyinstaller --onefile installer.py`
# cant run properly in wine!!
import os
import sys
from sys import exit
# Config values
HOST = "https://github.com/keukeiland/keuknet-client/releases/latest/download/"
DOWNLOAD_ARGS = "--no-progress-meter --fail -L"
OTHER_DESKTOP_FILES_DIR = "/usr/share/applications"
OTHER_BINARIES_DIR = "/usr/bin"
OTHER_DEPENDENCIES = {
'wg-quick': "WireGuard-tools",
'xdg-mime': "XDG",
'curl': "cURL",
'chmod': "chmod"
}
# Constants
WINDOWS = os.name == 'nt'
OTHER = not WINDOWS
# Initialization
if WINDOWS:
import ctypes
# Privileges
if not ctypes.windll.shell32.IsUserAnAdmin() == 1:
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
exit(1)
# Confirmation
os.system("mshta \"javascript:alert('Before continuing please save all open files.');close()\"")
if OTHER:
# Privileges
if not os.geteuid() == 0:
print("Not running as root, cancelling install...")
exit(1)
# Confirmation
input(f"This script will install:\n'keuknet.desktop' to '{OTHER_DESKTOP_FILES_DIR}'\n'keuknet.py' to '{OTHER_BINARIES_DIR}'\nPress 'CTRL+C' to cancel or 'Enter/Return' to continue.")
# Preparation
if WINDOWS:
os.system("mkdir \"%TEMP%\\keuknetinstaller\"")
os.system(f"curl -o \"%TEMP%\\keuknetinstaller\\wireguard.exe\" https://download.wireguard.com/windows-client/wireguard-installer.exe {DOWNLOAD_ARGS}")
os.system(f"curl -o \"%TEMP%\\keuknetinstaller\\keuknet.exe\" {HOST}keuknet.exe {DOWNLOAD_ARGS}")
os.system("mkdir \"%PROGRAMFILES%\\KeukNet\"")
if OTHER:
if not os.path.isdir(OTHER_DESKTOP_FILES_DIR) or not os.path.isdir(OTHER_BINARIES_DIR):
print("Unusual file-system lay-out detected. Is your OS UNIX-compliant?\nIf not please edit this script to use the correct paths.")
exit(1)
for cmd, name in OTHER_DEPENDENCIES.items():
if os.system(f"man {cmd} >/dev/null") != 0:
print(f"{name} not available at '{cmd}'. Please install a package that provides {cmd}.")
exit(1)
# Installation
if WINDOWS:
os.system("%TEMP%\\keuknetinstaller\\wireguard.exe && taskkill /IM wireguard.exe /F")
os.system("move \"%TEMP%\\keuknetinstaller\\keuknet.exe\" \"%PROGRAMFILES%\\KeukNet\\keuknet.exe\"")
os.system("reg add HKCR\\keuknet /ve /d \"URL:KeukNet\" /f")
os.system("reg add HKCR\\keuknet /v \"URL Protocol\" /d "" /f")
os.system("reg add HKCR\\keuknet\\shell /f")
os.system("reg add HKCR\\keuknet\\shell\\open /f")
os.system("reg add HKCR\\keuknet\\shell\\open\\command /d \"\\\"C:\\Program Files\\KeukNet\\keuknet.exe\\\" \"%1\"\" /f")
if OTHER:
os.system(f"curl -o \"{OTHER_DESKTOP_FILES_DIR}/keuknet.desktop\" {HOST}keuknet.desktop {DOWNLOAD_ARGS}")
os.system(f"curl -o \"{OTHER_BINARIES_DIR}/keuknet.py\" {HOST}keuknet.py {DOWNLOAD_ARGS}")
os.system(f"chmod +x \"{OTHER_BINARIES_DIR}/keuknet.py\"")
os.system("xdg-mime default keuknet.desktop x-scheme-handler/keuknet")
# Finalization
if WINDOWS:
os.system("shutdown /g /f /t 3 /d p:4:2 /c \"Rebooting in 3 sec to finish KeukNet installation\"")
if OTHER:
print("Successfully installed the KeukNet client.")