-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimg-recovery.py
executable file
·68 lines (48 loc) · 1.65 KB
/
img-recovery.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
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
#! /bin/env python
"""After the ./ you have to type in the save/write path. For example /home/USER/FOLDER/NAME.img.gz"""
import subprocess
import sys
def save_img_sdX(literal, image_path):
subprocess.run(["sudo", "dd", f"if=/dev/sd{literal}", "|", "gzip", ">", image_path], stdout=subprocess.PIPE)
def write_on_sdX(literal, image_path):
subprocess.run(["sudo", "cat", image_path, "|", "gunzip", "|", "dd", f"of=/dev/sd{literal}"])
def lsblk():
print("Take a short look where your sd-card is:")
print((subprocess.run(["lsblk"], stdout=subprocess.PIPE)).stdout.decode("utf-8"))
def end():
sys.exit(0)
def start():
if len(sys.argv) > 1:
image_path = sys.argv[1]
else:
print("No image-path given, program will end.\n", __doc__)
end()
return
print("What do you want? Save or write?\n")
print("1. Save image")
print("2. Write image\n")
print("99. Quit")
user_input1 = int(input("Choose a number: "))
if user_input1 == 1:
lsblk()
print("\nWhere to save? Prompt: <sdX> Choose a literal for X, like a.")
user_input2 = input("a-z, q for quit.")
print()
if user_input2 == 'q':
end()
else:
save_img_sdX(user_input2, image_path)
elif user_input1 == 2:
lsblk()
print()
print("Where to write? Prompt: <sdX> Choose a literal for X, like a.")
user_input3 = input("a-z, q for quit.")
print()
if user_input3 == 'q':
end()
else:
write_on_sdX(user_input3, image_path)
elif user_input1 == 99:
end()
if __name__ == "__main__":
start()