Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit 7b1929a

Browse files
committed
Make sure the tool is run with root
1 parent 042c3fb commit 7b1929a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

ubports-qa

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ GITHUB_API_PULLREQUEST="https://api.github.com/repos/ubports/%s/pulls/%s"
77
JENKINS_API_BUILD="https://ci.ubports.com/blue/rest/organizations/jenkins/pipelines/%s/branches/%s"
88
REPO="http://repo.ubports.com/dists/%s/main/binary-armhf/Packages"
99

10+
is_root = (os.geteuid() == 0)
11+
1012
class Status(Enum):
1113
SUCCESS = 1
1214
BULDING = 2
1315
FAILED = 3
1416

17+
def ensure_root():
18+
if not is_root:
19+
die("Insufficient permissions, please run with sudo.")
20+
1521
def mount():
1622
subprocess.call(["mount", "-o", "rw,remount", "/"])
1723

@@ -78,6 +84,7 @@ def die(m):
7884
exit()
7985

8086
def install(args):
87+
ensure_root()
8188
if args.pr != -1:
8289
ref = get_issue_branch(args.repo, args.pr);
8390
status = get_issue_status(args.repo, ref);
@@ -90,6 +97,7 @@ def install(args):
9097
apt_upgrade()
9198

9299
def remove(args):
100+
ensure_root()
93101
if not list_exists(args.repo):
94102
die("Repo %s is not installed" % args.repo)
95103
remove_list(args.repo)
@@ -98,6 +106,7 @@ def list(args):
98106
print(" ".join(list_lists()))
99107

100108
def update(args):
109+
ensure_root()
101110
mount()
102111
apt_update()
103112
apt_upgrade()
@@ -124,7 +133,9 @@ parser_update.set_defaults(func=update)
124133
try:
125134
args = parser.parse_args()
126135
args.func(args)
127-
except:
128-
try: args
129-
except: pass
130-
else: parser.print_help()
136+
except IOError as e:
137+
ensure_root()
138+
die(e)
139+
except AttributeError as e:
140+
parser.print_help()
141+
exit()

0 commit comments

Comments
 (0)