-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrvup
More file actions
executable file
·93 lines (81 loc) · 2.92 KB
/
Copy pathsrvup
File metadata and controls
executable file
·93 lines (81 loc) · 2.92 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
#!/usr/bin/env python3
from getpass import getpass
from enum import Enum
import shutil
import subprocess
class OS(Enum):
Fedora = 1
Ubuntu = 2
Proxmox = 3
LXC_Debian = 4
class Server:
def __init__(self, ip, os, user, nickname, docker_path=""):
self.ip = ip
self.os = os
self.user = user
self.nickname = nickname
self.docker_path = docker_path
def __str__(self):
return f"{self.user}@{self.ip} ({self.os})"
servers = [
Server("192.168.68.112", OS.Proxmox, "leah", "PVE Hypervisor"),
Server("192.168.68.129", OS.LXC_Debian, "root", "The Lounge"),
Server("192.168.68.109", OS.LXC_Debian, "root", "Wireguard"),
# Temporarily disable deluge, I need to figure out mounting my NAS.
# Server("192.168.68.130", OS.LXC_Debian, "root", "Deluge"),
Server("192.168.68.114", OS.Fedora, "leah", "Alpha Proxy"),
Server("192.168.68.107", OS.Fedora, "leah", "Alpha Wiki"),
Server("192.168.68.120", OS.Ubuntu, "leah", "Jellyfin"),
Server("192.168.68.126", OS.Fedora, "leah", "Miniflux"),
]
def main():
if not shutil.which("sshpass"):
print("You need sshpass!!!")
exit(1)
failed_servers = []
# I use the same password for them all XD
password = getpass("Password for servers: ")
for server in servers:
print(f" [I] Updating {server}!")
update_cmds = []
match server.os:
case OS.Fedora:
update_cmds = [f"echo {password} | sudo -S dnf update -y"]
case OS.Ubuntu:
update_cmds = [
f"echo {password} | sudo -S apt update",
f"echo {password} | sudo -S apt dist-upgrade -y",
]
case OS.Proxmox:
update_cmds = [
f"echo {password} | sudo -S apt update",
f"echo {password} | sudo -S apt dist-upgrade -y",
]
case OS.LXC_Debian:
update_cmds = ["apt update", "apt dist-upgrade -y"]
for update_cmd in update_cmds:
cmd = [
"sshpass",
f"-p{password}",
"ssh",
"-t",
f"{server.user}@{server.ip}",
update_cmd,
]
print(f" [V] Running: {str(cmd).replace(password, '__PASSWORD__')}")
proc = subprocess.run(cmd)
if proc.returncode != 0:
print(f" [E] Server {server} failed!")
failed_servers.append(server)
print(f" [I] Done with {server}!")
if len(failed_servers) != 0:
print(f" [E] {str(len(failed_servers))} servers failed! Failed servers:")
for server in failed_servers:
print(f" - {server}")
print(" [I] Chances are, You don't have it authorized in ~/.ssh/known_hosts")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\n:(")
exit(0)