-
Notifications
You must be signed in to change notification settings - Fork 6
/
installer
executable file
·195 lines (158 loc) · 5.59 KB
/
installer
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#! /usr/bin/env python3
# coding: utf-8
"""
This fast installer is destined to the developpers who want to create
their own quick installer, with 'geninstaller'.
Just read the comments and complete the informations asked below,
the magic will do the rest.
IMPORTANT:
Geninstaller only installs applications in the user's space, it does not
access to the system files. Therefore, each installation is relative
to one user of the computer. It is possible to install the application
on multiple sessions, but each application installed will remain totally
independent.
"""
# =========== THERE WE GO ===================================
# PLACE THIS FILE IN THE ROOT DIRECTORY OF YOUR PROJECT
# =====================================================================
# ======= Complete this informations ==================================
# choose a good name, do NOT use underscores here
NAME = "Nord Manager"
# short description (optionnal), a few words would be fine
DESCRIPTION = "Unofficial NordVPN manager in the system tray"
# The main executable file of the application
# The path is relative to this directory (BASE_DIR defined below)
EXECUTABLE = "app/nordmanager.py"
# The icon that your system will use (optionnal, but so much better)
# The path is relative to this directory (BASE_DIR defined below)
ICON = "app/icon_nordvpn.png"
# Does your application needs to appear within a terminal ?
# (usually, a graphical application doesn't need a terminal)
TERMINAL = False
# uncomment the categories in which you want your app to appear in (optionnal).
# if needed, read this:
# freedesktop.org doc for categories
# https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry
# additionnal categories
# https://specifications.freedesktop.org/menu-spec/latest/apas02.html
CATEGORIES = [
# "AudioVideo",
# "Audio",
# "Video",
# "Development",
# "Education",
# "Game",
# "Graphics",
"Network",
# "Office",
# "Science",
# "Settings",
# "System",
"Utility",
]
# ADDITIONAL OPTIONS
exec_options = "" # if the exec needs additional options
# if more parameters are needed in the .desktop file, fill this list
# with the lines you want. e.g: ["foo=bar", "truc=machin"]
options = [
"Keywords=geninstaller;",
]
# you can add your own PyPI dependencies here if you want:
dependencies = [
'geninstaller>=1.1.2', # do not remove this line.
]
# you're done ! :)
# = do not touch what is following unless you know what you're doing ==
# =====================================================================
import os
import sys
import pkg_resources
# dependencies check
version = sys.version_info # user's python version
this_file = os.path.basename(__file__)
def check_pip(test=False):
"""Checks if pip is installed, if it is not,
closes the program with a message"""
res = os.popen(f"python{version[0]}.{version[1]} -m pip -V").read().strip()
OK = False
if res.startswith('pip'):
OK = True
if not OK or test:
this_file = os.path.basename(__file__)
message = (
"pip is not installed for your main version of python3.\n"
"Please install pip first (see below)"
", and then, restart your session "
f"before executing './{this_file}' again.\n\n"
" INSTALLING pip:\n"
"- DEBIAN (Ubuntu, Linux Mint, etc...):\n"
"$ sudo apt install python3-pip\n"
"- Fedora, CentOS/RHEL 7+:\n"
"$ sudo yum install python3-pip\n"
"- ARCH LINUX, Manjaro:\n"
"$ sudo pacman -S python-pip\n"
"- OPENSUSE:\n"
"$ sudo zypper install python3-pip\n"
"\n"
"Or, for any distribution:\n"
"$ wget https://bootstrap.pypa.io/get-pip.py\n"
"$ chmod +x get-pip.py\n"
"$ sudo python3 get-pip.py\n"
)
print("\x1b[0;30;33m" + "ABORTED !\n" + "\x1b[0m")
print(message)
to_send = f"\"Installation Aborted !!\" \"{message}\""
os.system(f"notify-send {to_send}")
exit()
check_pip()
def pip_install_dependencies():
for dependency in dependencies:
dependency = dependency.replace(">", "=").split('=')[0]
os.system(
f"python{version[0]}.{version[1]} "
f"-m pip install --upgrade {dependency}")
print(
"\x1b[0;30;32m" # text is green
"Dependencies successfully installed."
"\x1b[0m"
)
try:
pkg_resources.require(dependencies)
except pkg_resources.VersionConflict: # python3.7/3.8
pip_install_dependencies()
except pkg_resources.DistributionNotFound: # python3.6/3.9
pip_install_dependencies()
from flamewok.cli import cli
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
datas = {
"name": NAME,
"exec": EXECUTABLE,
"comment": DESCRIPTION,
"terminal": TERMINAL,
"icon": ICON,
"categories": CATEGORIES,
"base_dir": BASE_DIR,
"exec_options": exec_options,
"options": options,
}
def install():
"""installs geninstaller's database on the system,
if not already installed. Absolutely required !"""
from geninstaller.helpers import autoinstall
from geninstaller import core
autoinstall()
# and then, installs your application
core.install(datas)
def main():
routes = [
f"installer program for: {NAME}",
"INSTALLATION",
("", install, (
f"Install '{NAME}' by simply executing '$ ./{this_file}'"
)),
"HELP",
(["-h", "--help"], cli.help, "display this help"),
]
cli.route(*routes)
if __name__ == "__main__":
main()