-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
33 lines (30 loc) · 1.19 KB
/
setup.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
# First boot - Base setup
# wget https://raw.githubusercontent.com/cms66/rpi-pyhome/main/setup.py; sudo python ./setup.py
# Assumes
# - rpi imager or SDM used to configure
# - user/password
# - hostname
# Imports
import subprocess, sys, os, urllib.request
def main():
bashfile = "base_setup.sh"
bashurl = "https://raw.githubusercontent.com/cms66/rpi-pyhome/main/" + bashfile
print("Python setup")
try:
urllib.request.urlretrieve(bashurl, bashfile) # Download bash script
subprocess.run(["sudo", "bash", "./" + bashfile], check=True) # Sudo run bash script
subprocess.run(["sudo", "rm", "-f", "./" + bashfile], check=True) # Delete bash script
usropt=input("Base seup done, press p to poweroff or any other key to reboot: ").lower()
os.remove(__file__) # Delete python script
if usropt == 'p':
print ("Poweroff selected")
subprocess.call(["shutdown", "-s", "now"])
else:
print ("Reboot selected")
subprocess.call(["shutdown", "-r", "now"])
except Exception as e:
print("Error:", e)
sys.exit(1)
print("Python setup done")
if __name__ == "__main__":
main()