-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperms.py
executable file
·84 lines (68 loc) · 3.07 KB
/
perms.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
import subprocess
import re
REGEXTYPE = "sed"
WEEK = 11
allowlist = [
"\.",
".*/*.html", # html files
".*/script\.js", # js script for site
".*/css/*",
".*/css/.*", # css stylesheets
".*/assets/*",
".*/assets/.*", # site resources
".*/stuff/*",
".*/stuff/era/*",
".*/stuff/era/resources/.*",
#".*/stuff/era/era_slides_w\(0[1-9]\|1[0-4]\).*"
".*/stuff/era2\?/era2\?_slides_w0[1-"+str(WEEK)+"].*", # all slides + texs up to week n
".*/stuff/era2\?/era2\?_slides_w1[0-"+str(WEEK%10)+"].*", # all slides + texs up to week n
".*/stuff/era2\?/era2\?_slides_w13.*", # additional slides + texs
".*/stuff/era2\?/era2\?_tutor0[1-"+str(WEEK-1)+"]_clean\.pdf", # writeups up to week n-1
".*/stuff/era2\?/era2\?_tutor1[0-"+str((WEEK-1)%10)+"]_clean\.pdf", # writeups up to week n-1
".*/stuff/era2\?/era2\?_tutor13_clean\.pdf", # additional writeups
".*/stuff/era2\?/era2\?_quiz_w0[1-"+str(WEEK-1)+"].*", # all quizzes up to week n-1
".*/stuff/era2\?/w0[1-"+str(WEEK-1)+"]_code/*", # all code dirs up to week n-1
".*/stuff/era2\?/w0[1-"+str(WEEK-1)+"]_code/.*",
".*/stuff/era2\?/w0[1-"+str(WEEK-1)+"]_circuits/*", # all circuit dirs up to week n-1
".*/stuff/era2\?/w0[1-"+str(WEEK-1)+"]_circuits/.*" ,
".*/stuff/era2\?/w0[1-"+str(WEEK)+"]_templates/*", # all template dirs up to week n
".*/stuff/era2\?/w0[1-"+str(WEEK)+"]_templates/.*" ,
".*/stuff/gra/*",
".*/stuff/gra/.*", # gra files
".*/bn_.*" # bonus files
]
denylist = [
".*/\.git/*", # .git parent dirs
".*/\.git/.*", # files in .git dirs
".*/\.gitignore",
".*/README.md",
".*/perm\.sh",
".*/perms\.py",
".*/stuff/era/era_slides_w0"+str(WEEK)+".*", # ordering between era and era2 changed
".*/stuff/era/era_tutor0"+str(WEEK-1)+"_clean\.pdf",
".*/stuff/era/w0"+str(WEEK-1)+"_code/.*",
".*/stuff/era/w0"+str(WEEK-1)+"_circuits/.*",
".*/stuff/era/.*w09.*",
".*/stuff/era/.*w11.*"
]
allowperms = "o+rx"
denyperms = "o-rwx"
def main():
print("Adding all permissions for owner")
cmd = ["find", ".", "-exec", "chmod", "u+rwx", "{}", ";"]
subprocess.run(cmd)
print("Removing other write permissions for all files")
cmd = ["find", ".", "-exec", "chmod", "o-w", "{}", ";"]
subprocess.run(cmd)
print(f"Setting permissions for objects in allowlist: {allowperms}")
for regobj in allowlist:
cmd = ["find", ".", "-regextype", REGEXTYPE, "-regex", regobj, "-exec", "chmod", allowperms, "{}", ";"]
subprocess.run(cmd)
print(f"Setting permissions for objects in denylist: {denyperms}")
for regobj in denylist:
cmd = ["find", ".", "-regextype", REGEXTYPE, "-regex", regobj, "-exec", "chmod", denyperms, "{}", ";"]
subprocess.run(cmd)
print("Done!")
if __name__ == "__main__":
main()