Skip to content

Commit 70465b7

Browse files
committed
cleanup scripts a little
1 parent 2d5d8c9 commit 70465b7

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

001_setup_sd_card

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def parseArgs():
3030
'https://www.iso.org/obp/ui/#search')
3131

3232
if os.getuid() != 0:
33-
print("This script must be run as sudo.\n")
33+
print("This script must be run as sudo.\n", file = sys.stderr)
3434
parser.print_help()
35-
exit(1)
35+
sys.exit(1)
3636

3737
args = parser.parse_args()
3838
args.device_path = args.device_path.rstrip('/')
@@ -54,7 +54,7 @@ def imageSdCard():
5454
break
5555
time.sleep(0.5)
5656
if time.time() > time_limit:
57-
print(f"Failed to remount {args.device_path}.")
57+
print(f"Failed to remount {args.device_path}.", file = sys.stderr)
5858
sys.exit(1)
5959

6060
# prevent weirdness where subsequent writes are flakey?
@@ -76,20 +76,20 @@ def validate():
7676
try:
7777
command(f'sudo ls -l {args.device_path}/cmdline.txt')
7878
except Exception:
79-
print("ERROR: failed to validate raspbian install")
80-
exit(1)
79+
print("ERROR: failed to validate raspbian install", file = sys.stderr)
80+
sys.exit(1)
8181

8282
try:
8383
command(f'sudo ls -l {args.device_path}/ssh')
8484
except Exception:
85-
print("ERROR: failed to validate ssh setup")
86-
exit(1)
85+
print("ERROR: failed to validate ssh setup", file = sys.stderr)
86+
sys.exit(1)
8787

8888
try:
8989
command(f'sudo ls -l {args.device_path}/wpa_supplicant.conf')
9090
except Exception:
91-
print("ERROR: failed to validate wifi setup")
92-
exit(1)
91+
print("ERROR: failed to validate wifi setup", file = sys.stderr)
92+
sys.exit(1)
9393

9494
def finish():
9595
print("Ejecting SD card...")

wifi_config

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import argparse
44
import os
5+
import sys
56

67
def parseArgs():
78
parser = argparse.ArgumentParser(
@@ -33,8 +34,8 @@ def setupWifi():
3334
try:
3435
f = open(f"{args.device_path}/wpa_supplicant.conf", "w")
3536
except PermissionError:
36-
print("This script must be run as sudo")
37-
exit(1)
37+
print("This script must be run as sudo", file = sys.stderr)
38+
sys.exit(1)
3839

3940
f.write(f"""country={args.wifi_country_code}
4041
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
@@ -48,8 +49,8 @@ def setupWifi():
4849

4950

5051
if os.getuid() != 0:
51-
print("This script must be run as sudo")
52-
exit(1)
52+
print("This script must be run as sudo", file = sys.stderr)
53+
sys.exit(1)
5354

5455
args = parseArgs()
5556
setupWifi()

0 commit comments

Comments
 (0)