add root check

This commit is contained in:
JerryXiao 2021-01-16 00:12:17 +08:00
parent 57e96c2650
commit 7083d4b41b
Signed by: Jerry
GPG key ID: 9D9CE43650FF2BAA

View file

@ -5,7 +5,7 @@ import subprocess
import logging import logging
from re import match from re import match
import json import json
from os import environ from os import environ, getuid
import traceback import traceback
import pyalpm import pyalpm
import pycman import pycman
@ -169,6 +169,8 @@ def main() -> None:
logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s') logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s')
if args.action == 'run': if args.action == 'run':
if getuid() != 0:
parser.error('you need to be root')
if prev_err := has_previous_error(): if prev_err := has_previous_error():
logger.error(f'Cannot continue, a previous error {prev_err} is still present. Please resolve this issue and run fail-reset.') logger.error(f'Cannot continue, a previous error {prev_err} is still present. Please resolve this issue and run fail-reset.')
else: else:
@ -199,6 +201,8 @@ def main() -> None:
break break
print() print()
elif args.action == 'fail-reset': elif args.action == 'fail-reset':
if getuid() != 0:
parser.error('you need to be root')
if prev_err := has_previous_error(): if prev_err := has_previous_error():
write_db(None) write_db(None)
logger.info(f'reset previous error {prev_err}') logger.info(f'reset previous error {prev_err}')