/
main.py
executable file
·314 lines (233 loc) · 12.5 KB
/
main.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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/usr/bin/python3
"""
Copyright [2020-2021] [M.Amin Azimi .K (amzy-0)]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
__authors__ = ['M.Amin Azimi .K(amzy-0)',
'https://github.com/amzy-0/pck3r/graphs/contributors']
from os import system as syscall
from os import chdir
from sys import argv
from libs import stuff
from libs import dotnet
argc = len(argv)
def error_sys():
stuff.sysERR('''
Please try:
$ pck3r sys <update/upgrade/updgr(update and upgrade)>''')
while True:
# check network connection, if internet not avalable BREAK the operation
if (syscall('ping -c1 4.2.2.4 > /dev/null 2>&1')) != 0:
if argc == 2 and argv[1] == 'help':
pass
else:
stuff.sysERR('Network is unreachable')
break
# if user just type $ pck3r
if argc <= 1:
stuff.sysERR('After "pck3r" is empty!\nPlease try:\n$ pck3r help')
else:
# if argument 1 equal to "clear"
# clear terminal
# do :
if argv[1] == 'clear' and argc == 2:
syscall('clear')
stuff.sysOk(' This is funny clear command :D')
# pck3r updator
elif argv[1] == 'update' and argc == 2:
if (syscall('ls /opt/pck3r > /dev/null 2<&1'))==0:
chdir('/opt/pck3r')
syscall('sudo -p "[sudo]🔑 : " git pull ; sudo git restore .; ./installer.py')
else:
stuff.sysERR('You can not update pck3r with the "root" permission')
# if argument 1 equal to "help"
# like -> $ pck3r help
# do :
elif argv[1] == 'help' and argc == 2:
from libs import help
# if argument 1 equal to "install"
# and argument 2 is not empty
# do :
elif argv[1] == 'install' and argc >= 2:
# if after install is empty
if argv[1]== 'install' and argc <= 2:
stuff.sysERR('After "install" is empty !')
elif argv[2] == 'flstudio' and argc == 3:
from libs import flstudio
# if argument 2 is nodejs
elif argv[2]=='nodejs' and argc==3:
if (syscall(
'''echo %s ;
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -p "[sudo]🔑 : " -E bash -; sudo -p "[sudo]🔑 : " apt install -y nodejs
sudo -p "[sudo]🔑 : " apt update && echo %s;
echo %s;
sudo -p "[sudo]🔑 : " apt install yarnpkg -y'''
% (stuff.YEL, stuff.CYN, stuff.MAG)))==0:
stuff.sysOk()
syscall('echo %s"Nodejs LTS Version :" ; node --version %s'
%(stuff.GRN, stuff.NRM))
syscall('echo "Npm Version :" %s; npm --version %s'
%(stuff.GRN, stuff.NRM))
# Exception
else:
stuff.sysERR('please retry...\n$ pck3r install nodejs')
elif argv[2] == 'dotnet' and argc==3:
dotnet.install_dotnet()
elif argv[2] == 'ohmyzsh' and argc==3:
syscall('sudo -p "[sudo]🔑 : " apt install zsh curl')
if (syscall('curl --version')) == 0 :
syscall('sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"')
else:
syscall('echo "curl" is required for using "ohMyZsh" ; sudo -p "[sudo]🔑 : " apt install curl')
syscall('sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"')
# argument 2 is not empty
elif argv[2:] != [] and argc >= 2:
stuff.sysOk('Command is valid : "$ pck3r install"\nLoading package lists...')
packages = argv[2:]
packages = list(packages)
for package in packages:
if syscall(('sudo -p "[sudo]🔑 : " apt install -f && sudo -p "[sudo]🔑 : " dpkg --configure -a ; sudo -p "[sudo]🔑 : " apt install %s 2> /dev/null '
% package))==0:
if package[0] == '-':
continue
failed = list()
failed.append(package)
syscall("echo %s; %s --version" % (stuff.GRN, package))
stuff.sysOk('Package(s) or Command(s) : %s | Status : found ! ...'
% ' '.join(failed))
elif syscall(('sudo -p "[sudo]🔑 : " apt install %s > /dev/null 2>&1' % package))==25600:
failed = list()
failed.append(package)
stuff.sysERR('Package(s) or Command(s) : %s | Status : Not found ! ...'
% ' '.join(failed))
syscall('sleep 1')
elif (syscall('sudo -p "[sudo]🔑 : " apt install %s 2> /dev/null '
% ' '.join(argv[2:]))) != 0 :
# all the packages after "sudo apt install" assigned to the : packages variable
for package in packages: #validation
if (syscall('sudo -p "[sudo]🔑 : " apt install %s 2> /dev/null' % package))==25600:
failed = list()
failed.append(package)
stuff.sysERR('Package(s) or Command(s) : "%s" | Status : Not found ! ...'
% ' '.join(failed))
syscall('sleep 1')
break
print(stuff.NRM)
break
# if argument 1 equal to "uninstall"
elif argv[1] == 'uninstall' and argc >= 2:
# if after "uninstall" is empty
if argv[1] == 'uninstall' and argc <= 2:
stuff.sysERR('After "uninstall" is empty !')
# if user want uninstall dotnet
# do :
elif argv[2]=='dotnet' and argc==3:
dotnet.uninstall_dotnet()
# argument 2 is not empty
# do :
elif argv[2:] != [] and argc >= 2:
stuff.sysOk('Command is valid!')
syscall('sudo -p "[sudo]🔑 : " apt purge %s' % ' '.join(argv[2:]))
# if argument 1 equal to "rm" (sudo apt remove)
elif argv[1] == 'rm' and argc >= 2:
# if after install is empty
if argv[1]== 'rm' and argc<=2:
stuff.sysERR('After "rm" is empty !')
# argument 2 is not empty
# do :
if argv[2:] != [] and argc>=2:
stuff.sysOk('Command is valid!')
syscall('sudo -p "[sudo]🔑 : " apt remove %s' % ' '.join(argv[2:]))
# Exception
else:
stuff.sysOk('Command or package(s) not found : %s' % ' '.join(argv[2:]))
# Too many arguments error for $ pck3r term
# Only use :
# $ pck3r tilix <somthing> <somthing> <somthing> <somthing>, ...
elif argv[1] =='tilix' and argc==2:
ans = input('install and run "tilix" terminal (y/n) ? ')
if (ans == 'y'):
syscall('sudo -p "[sudo]🔑 : " apt install tilix > /dev/null 2>&1 ; tilix& > /dev/null 2>&1; clear')
else:
break
# Too many arguments error for $ pck3r tilix
# Only use :
# $ pck3r tilix <somthing> <somthing> <somthing> <somthing>, ...
elif argv[1] =='tilix' and argc>2:
stuff.sysOk('Too many arguments !\nOnly use :\n$ pck3r term')
# if after "sys" command is empty
elif argv[1] == 'sys' and argc == 2:
error_sys()
# if after pck3r equal to "sys"
elif argv[1] == 'sys' and argc > 2:
if argv[2]=='update' and argc==3:
if (syscall('sudo -p "[sudo]🔑 : " apt update')) == 0:
stuff.sysOk('All package(s) status : UPDATED')
else:
stuff.sysERR()
# if user command, equal to $ pck3r sys upgrade
#do :
elif argv[2] == 'upgrade' and argc==3:
if (syscall('sudo -p "[sudo]🔑 : " apt full-upgrade')) != 0:
stuff.sysERR()
else:
# print with green logo
stuff.sysOk('All package(s) status : UPGRADED')
# echo green color and
# and say:
syscall('echo %s' % stuff.GRN)
# All information about OS
syscall('echo your OS information :')
syscall('uname -a ')
# the machine architecture
syscall('echo your machine architecture : ')
syscall('uname -p')
# end of the all information and
#back to the true color of this terminal
syscall('echo %s' % stuff.NRM)
# if user command, equal to $ pck3r sys updgr
#do :
elif argv[2] == 'updgr' and argc==3:
if (syscall('sudo -p "[sudo]🔑 : " apt update && sudo -p "[sudo]🔑 : " apt full-upgrade')) != 0:
stuff.sysERR()
else:
stuff.sysOk('All package(s) status : UPDATED and UPGRADED')
syscall('echo %s' % stuff.GRN)
syscall('echo your OS information :')
syscall('uname -a ')
syscall('echo your machine architecture : ')
syscall('uname -p')
syscall('echo %s' % stuff.NRM)
# if command is not a valid one !
# will send an error to the user.
# do :
else:
error_sys()
# if after "pkg" is empty
elif argv[1]== 'pkg' and argc <= 2:
stuff.sysERR('After "pkg" is empty !')
# if after "pkg" is not empty
elif argv[1] == 'pkg' and argc >= 2:
# if after "pkg" isn't empty
if argv[2:] != [] and argc >= 2:
syscall('apt search %s' % ' '.join(argv[2:]))
# if user want to see the pck3r version
elif argv[1] == 'version' and argc ==2:
chdir('/opt/pck3r')
syscall(f'echo {stuff.CYN}version is : `git describe --tags --abbrev=0` {stuff.YEL}{stuff.NRM}')
print(f'{stuff.NRM}{stuff.CYN}{", ".join(__authors__[:2])}, ...{stuff.NRM}')
# if command not valid
# print :
# and breaking any operation
else:
stuff.sysERR('Command not found !\nPlease try:\n$ pck3r help')
# end of (for) loop
break