summaryrefslogtreecommitdiffstats
path: root/scripts/lib/ptxd_lib_check_dir_permissions.awk
blob: a669b429bdde655f12c0cb18ea421189d314dd07 (plain)
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
#!/usr/bin/awk -f

BEGIN {
	FS = "\x1F";
}

function check(path, perm, implicit) {
	if ((path in perms) && (perms[path] != perm)) {
		if (implicit && (pkg == names[path]))
			return;
		print("\nIncompatible ownership or permissions for '" path "':")
		print(names[path] ": " perms[path] (imp[path] ? " (implicit from " imp[path]")" : ""))
		print(pkg ": " perm (implicit ? " (implicit)" : ""))
		print("\nOne of these packages must be fixed!\n")
		exit 1
	}
	if (!(path in perms)) {
		names[path] = pkg
		perms[path] = perm
		imp[path] = implicit
	}
}

FNR == 1 {
	for (path in dirs)
		check(path, dirs[path], imps[path])
	pkg = gensub(/.*\/(.*).perms/, "\\1", 1, FILENAME)
	delete dirs
	delete imps
}

function push_parents(base) {
	path = base
	while (1) {
		path = gensub(/\/[^/]*$/,"",1,path)
		if (path == "")
			break;
		if (!(path in dirs)) {
			dirs[path] = "0.0 0755"
			imps[path] = base
		}
	}
}

$1 ~ "d" {
	path = gensub(/\/$/,"",1,$2)
	perm = $3 "." $4 " " sprintf("%04o", strtonum("0" $5))
	dirs[path] = perm
	imps[path] = ""
	push_parents(path)
}

$1 ~ "f" {
	path = $2
	push_parents(path)
}