Script checks for root if run in restore mode. This might help with using it correctly

This commit is contained in:
2021-12-09 23:31:03 +01:00
parent 1b2dcc022e
commit f3c24be9a3

35
main.py
View File

@@ -32,23 +32,26 @@ def save_settings():
def restore():
global packagelist, config
try:
os.chdir(backupdir)
except FileNotFoundError:
print("Backup directory not found! Does it really exist? Please check for correct order of arguments: "
"-d/--backup-dir -r/--restore!")
exit(2)
try:
packagelist = open("packages.txt", "r")
except FileNotFoundError:
print("No packages.txt in your backup directory! Did you specify the right directory? Please check for "
"correct order of arguments: first -d/--backup-dir then -r/--restore!")
packagelist.close()
exit(2)
if os.getuid() == 0:
try:
os.chdir(backupdir)
except FileNotFoundError:
print("Backup directory not found! Does it really exist? Please check for correct order of arguments: "
"-d/--backup-dir -r/--restore!")
exit(2)
try:
packagelist = open("packages.txt", "r")
except FileNotFoundError:
print("No packages.txt in your backup directory! Did you specify the right directory? Please check for "
"correct order of arguments: first -d/--backup-dir then -r/--restore!")
packagelist.close()
exit(2)
else:
subprocess.call(["dpkg", "--set-selections"], stdin=packagelist)
subprocess.call(["apt-get", "dselect-upgrade"])
packagelist.close()
else:
subprocess.call(["dpkg", "--set-selections"], stdin=packagelist)
subprocess.call(["apt-get", "dselect-upgrade"])
packagelist.close()
print("You're not root! You can't restore packages unless you are root!")
try:
config = open("dconf_out.txt", "r")
except FileNotFoundError: