check for image, write 'ssh' dir
This commit is contained in:
22
flash.py
22
flash.py
@@ -6,10 +6,13 @@ from queue import Queue
|
||||
import subprocess
|
||||
import time
|
||||
import fourletterphat as flp
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
#--
|
||||
q = Queue()
|
||||
t = loader.bgload(3, .1)
|
||||
IMAGE = "image.img"
|
||||
#--
|
||||
|
||||
def disp_string(string):
|
||||
@@ -37,9 +40,17 @@ def get_mounted_devs():
|
||||
def flash(dev):
|
||||
loader.q.put(dev)
|
||||
try:
|
||||
flash_cmd = ["/bin/dd", "if=/home/pi/Downloads/2019-07-10-raspbian-buster-lite.img", f"of={dev}"]
|
||||
flash_cmd = ["/bin/dd", f"if=./{IMAGE}", f"of={dev}"]
|
||||
output = subprocess.check_output(flash_cmd).decode("utf-8")
|
||||
print(output)
|
||||
with tempfile.TemporaryDirectory() as tempdir:
|
||||
mount_cmd = ["mount",f"{dev}2", tempdir]
|
||||
umount_cmd = ["umount", tempdir]
|
||||
|
||||
subprocess.run(mount_cmd)
|
||||
os.chdir(tempdir)
|
||||
os.mkdir("ssh")
|
||||
subprocess.run(umount_cmd)
|
||||
|
||||
return True
|
||||
except BaseException as err:
|
||||
print(err)
|
||||
@@ -49,6 +60,13 @@ def flash(dev):
|
||||
|
||||
if __name__=="__main__":
|
||||
|
||||
while True:
|
||||
if os.path.isfile(IMAGE):
|
||||
break
|
||||
else:
|
||||
disp_string("IMG")
|
||||
time.sleep(1)
|
||||
|
||||
disp_string("GO")
|
||||
|
||||
done = set()
|
||||
|
||||
Reference in New Issue
Block a user