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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
| | #!/usr/bin/env -S LC_ALL=C LANGUAGE=C awk -E
# SPDX-License-Identifier: EUPL-1.2+
# SPDX-FileCopyrightText: 2025 Demi Marie Obenour <demiobenour@gmail.com>
BEGIN {
RS = "\n";
FS = "\t";
file_count = 0;
symlink_count = 0;
rc_count = 0;
is_rc = 0;
exit_code = 0;
done = 0;
modes["120000"] = "symlink";
modes["040755"] = "directory";
modes["100644"] = "regular";
modes["100755"] = "regular";
}
function fail(msg, status) {
if (status ~ /^([1-9][0-9]?|1[0-9]{2}|2[0-4][1-9]|25[1-5])$/) {
exit_code = status;
} else {
exit_code = 1;
status = 1;
}
print ("FATAL: " msg) > "/dev/stderr";
exit status;
}
done { fail("Junk after DONE", 1); }
/^DONE$/ {
done = 1
next
}
# Make sure git produced valid output.
!/^[0-7]{6}\t[ -~]+$/ {
fail("git ls-files produced invalid output", 1);
}
# Extract data from built-in variables.
{
filename = $2;
raw_mode = $1;
# awk autocreates empty string entries if the key is invalid,
# but the code exits in this case so that is okay.
mode = modes[raw_mode];
}
# Another check for a git bug.
filename ~ /^\/|((^|\/)\.{0,2}($|\/))/ {
fail("git ls-files output non-canonical or absolute path '" filename "'", 1);
}
filename ~ /[^[:alnum:]_.+@/-]/ {
fail("filename '" filename "' has forbidden characters", 1);
}
/\.license$/ {
if (raw_mode != "100644") {
fail("License file '" filename "' is executable or not regular file", 1);
}
next;
}
mode == "directory" { next }
filename ~ /^image\/etc\/s6-rc\// {
if (mode != "regular") {
fail("s6-rc-compile input '" filename "' isn't a regular file");
}
rc_count += 1;
rc_files[rc_count] = filename;
next;
}
mode == "symlink" {
symlink_count += 1;
symlinks[symlink_count] = filename;
next;
}
mode == "regular" {
file_count += 1;
files[file_count] = filename;
next;
}
{ fail("File '" filename "' is not regular file, directory, or symlink (mode " raw_mode ")"); }
END {
if (exit_code) {
exit exit_code;
}
if (!done) {
fail("Did not receive DONE line", 1);
}
printf ("# SPDX-License-Identifier: CC0-1.0\n" \
"# SPDX-FileCopyrightText: 2025 Demi Marie Obenour <demiobenour@gmail.com>\n" \
"# Generated by scripts/genfile.sh. Any changes will be overwritten.\n" \
"FILES ::=") > out_file;
for (array_index = 1; array_index <= file_count; array_index += 1) {
printf " \\\n\t%s", files[array_index] > out_file;
}
printf ("\n\n" \
"# These are separate because they need to be included, but putting\n" \
"# them as make dependencies would confuse make.\n" \
"LINKS ::=") > out_file;
for (array_index = 1; array_index <= symlink_count; array_index += 1) {
printf " \\\n\t%s", symlinks[array_index] > out_file;
}
printf "\n\nS6_RC_FILES ::=" > out_file;
for (array_index = 1; array_index <= rc_count; array_index += 1) {
printf " \\\n\t%s", rc_files[array_index] > out_file;
}
printf "\n" > out_file;
if (close(out_file)) {
print ("Cannot close output file: " ERRNO "\n") > "/dev/stderr";
exit 1;
}
}
|