-
Notifications
You must be signed in to change notification settings - Fork 0
/
Updater.py
114 lines (97 loc) · 3.51 KB
/
Updater.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
#If you are using this on a Rasperry Pi OS based system, run the command sudo pip install popen. Install pip if required with command sudo install pip.
#Updater Simple Linux-only update script
#Copyright (C) 2021 CJO Automated
#Full copyright info at: https://github.com/ReviloWillson/Updater/blob/main/LICENSE
import os, sys
USER = os.environ.get('SUDO_USER')
if USER == None:
print('You must use sudo.')
quit()
if sys.platform != 'linux':
print('This only works on Linux. You are running on:', sys.platform)
quit()
def errors(self):
return self._errors
def colored(text, color):
color = color.lower()
colors = {
"grey": "\033[1;30m%s\033[0m",
"red": "\033[1;31m%s\033[0m",
"green": "\033[1;32m%s\033[0m",
"yellow": "\033[1;33m%s\033[0m",
"blue": "\033[1;34m%s\033[0m",
"purple": "\033[1;35m%s\033[0m",
"cyan": "\033[1;36m%s\033[0m",
"white": "\033[1;37m%s\033[0m",
}
return colors[color] % text
def run_command(cmd=""):
import subprocess
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = p.stdout.read().decode('utf-8')
status = p.poll()
return status, result
def do(msg="", cmd=""):
print("[ ] %s..." % (msg), end='', flush=True)
status, result = eval(cmd)
if status == 0 or status == None or result == "":
print('\r[ %s ]' % colored("OK", "green"))
return True
else:
print('\r[%s]' % colored("Fail", "red"))
errors.append("%s error:\n Status:%s\n Error:%s" %
(msg, status, result))
return False
print('Updater \nCopyright (C) 2021 CJO Automated')
#Allow yourself DevAccess by adding: or USER == '<usertolist>': on the end of the line below.
if USER == 'revilo' or USER == 'pi':
print('Detected Dev User:%s' % (USER))
devq = input('Activate Dev Access and view source code? (Y/n)\n')
if devq == 'Y' or devq == 'y':
print('Dev access Enabled. Code will be displayed below.\n\n\n\n')
try:
fileOutput = open('Updater.py', 'r')
data = fileOutput.read()
fileOutput.close()
print(data)
print('\n')
print('-'*50)
print('\n')
do(msg='Update APT Package Manager',
cmd='run_command("apt update")')
do(msg='Update Computer',
cmd='run_command("sudo apt update && sudo apt upgrade")')
quit()
except OSError:
print('[ %s ]:' % (USER))
print(' %s' % colored("Fail!", "red"))
print(' %s' % colored("Error: File not found!", "red"))
retry = input('Retry without error handler? (Y/n)')
retry = retry.lower()
if retry == 'y':
fileOutput = open('Updater.py', 'r')
data = fileOutput.read()
fileOutput.close()
print(data)
quit()
else:
quit()
else:
print('Dev access Aborted.')
conf = input('Run Updates? (Y/n)\n')
if conf == 'Y' or conf == 'y':
try:
do(msg='Update APT Package Manager',
cmd='run_command("apt update")')
except AttributeError:
print('Update Failed.')
quit()
try:
do(msg='Update Computer',
cmd='run_command("sudo apt update && sudo apt upgrade")')
except AttributeError:
print('Update Failed')
quit()
else:
print('abort')