-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysup
More file actions
executable file
·189 lines (164 loc) · 5.71 KB
/
sysup
File metadata and controls
executable file
·189 lines (164 loc) · 5.71 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
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
#!/usr/bin/env python3
import getpass
import os
import platform
import shutil
import subprocess
def os_not_supported_error():
print(" [!] Sorry, Your OS isn't supported.")
print(" If you have the time, please ")
print(" contribute an update snippet at:")
print(" https://github.com/RealFX-Code/scripts")
exit(1)
def find_elevation():
if getpass.getuser() == "root" or getpass.getuser() == "Administrator":
return ""
elif shutil.which("sudo"):
return "sudo"
elif shutil.which("doas"):
return "doas"
else:
print(" [W] No elevation method was detected as installed,")
print(" And you're not running as ROOT.")
print(" ")
print(" THINGS MAY BREAK!")
print(" ")
return ""
def handle_linux_update():
def do_arch_update():
if shutil.which("paru"):
print(" [I] Paru update")
_ = subprocess.run(["paru"])
elif shutil.which("yay"):
print(" [I] Yay update")
_ = subprocess.run(["yay"])
else:
# Fallback to regular Pacman
print(" [W] No AUR Helper was found!")
print(" You won't get AUR Updates from sysup.")
print(" [I] Pacman update")
_ = subprocess.run([find_elevation(), "pacman", "-Syyuu"])
exit(0)
def do_debian_update():
elevation = find_elevation()
_ = subprocess.run([elevation, "apt", "update"])
_ = subprocess.run([elevation, "apt", "upgrade"])
_ = subprocess.run([elevation, "apt", "autoremove"])
exit(0)
def do_fedora_update():
elevation = find_elevation()
_ = subprocess.run([elevation, "dnf", "update"])
exit(0)
def do_gentoo_update():
elevation = find_elevation()
_ = subprocess.run([elevation, "emaint", "--auto", "sync"])
_ = subprocess.run([elevation, "emerge", "-avuDNU", "--with-bdeps=y", "@world"])
_ = subprocess.run([elevation, "emerge", "-ac"])
exit(0)
def do_nixos_update():
elevation = find_elevation()
if os.path.isfile("/etc/nixos/flake.nix"):
_ppwd = os.getcwd()
os.chdir("/etc/nixos")
_ = subprocess.run([elevation, "nix", "flake", "update"])
os.chdir(_ppwd)
else:
_ = subprocess.run([elevation, "nixos-rebuild", "switch", "--upgrade"])
exit(0)
distro = platform.freedesktop_os_release()["NAME"]
match distro:
case "Arch Linux" | "Artix" | "CachyOS Linux" | "EndeavourOS":
print(" [I] Arch-based OS Update")
do_arch_update()
case "Debian GNU/Linux" | "Trisquel" | "Ubuntu":
print(" [I] Debian-based OS Update")
do_debian_update()
case "Fedora Linux":
do_fedora_update()
case "Gentoo" | "Funtoo":
print(" [I] Gentoo-based OS Update")
do_gentoo_update()
case "NixOS":
print(" [I] NixOS Update")
do_nixos_update()
case _:
print(" [F] Your distro isn't supported!")
print(" Current distro: " + distro)
os_not_supported_error()
def handle_freebsd_update():
elevation = find_elevation()
_ = subprocess.run([elevation, "pkg", "update"])
_ = subprocess.run([elevation, "pkg", "upgrade"])
exit(0)
def handle_windows_update():
# This is only for "windows-native" package managers;
# That means that cygwin or msys2 doesn't count.
#
# Windows' quirks:
# - No admin need for most package managers,
# They'll ask for it themselvs.
#
has_updated = False
if shutil.which("winget"):
print(" [I] Upgrading with winget...")
_ = subprocess.run(
["winget", "upgrade", "--all", "--verbose", "--include-unknown"]
)
has_updated = True
if shutil.which("scoop"):
print(" [I] Upgrading with scoop...")
_ = subprocess.run(["scoop", "update", "*"])
has_updated = True
if shutil.which("choco"):
print(" [I] Upgrading with choco...")
_ = subprocess.run(["choco", "upgrade", "all"])
has_updated = True
if has_updated:
exit(0)
else:
print(" [W] Didn't update, as no package manager was found!")
exit(1)
def handle_darwin_update():
has_updated = False
if shutil.which("softwareupdate"):
print(" [I] Forcing system update check...")
_ = subprocess.run(["softwareupdate", "-l"])
has_updated = True
if shutil.which("brew"):
print(" [I] Updating homebrew...")
brew_update_steps = ["update", "upgrade", "autoremove", "cleanup", "doctor"]
for step in brew_update_steps:
_ = subprocess.run(["brew", step])
has_updated = True
if has_updated:
exit(0)
else:
print(" [W] No updates were done.")
exit(1)
def main():
print(" _____ _____ _ _ ___ ")
print(" / __\\ \\ / / __| | | | _ \\")
print(" \\__ \\\\ V /\\__ \\ |_| | _/")
print(" |___/ |_| |___/\\___/|_| ")
print("")
match platform.system():
case "Linux":
handle_linux_update()
case "FreeBSD":
handle_freebsd_update()
case "Darwin":
handle_darwin_update()
case "Windows":
handle_windows_update()
case _:
print(" [F] Your platform isn't supported!")
print(" Platform: " + platform.system())
os_not_supported_error()
print("Somehow, Nothing happened!")
exit(1)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
# CTRL+C shouldn't trigger an exception!
exit(0)