-
Notifications
You must be signed in to change notification settings - Fork 0
/
update
executable file
·80 lines (69 loc) · 2.16 KB
/
update
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
#!/bin/sh -eu
#
# s6-rc preprocessor and updater frontend
# Copyright © 2016 Samuel Holland <[email protected]>
# See LICENSE in the project directory for license terms.
# vim: expandtab:sts=2:sw=2:ts=8:tw=110
#
base=/etc/rc
date=$(TZ=UTC0 date +%Y%m%dT%H%M%SZ)
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' HUP INT QUIT TERM
for svcdir in "$base"/source/* ; do
if test -r "$svcdir"/disabled ; then
continue
elif test -r "$svcdir"/contents ; then
svcname=${svcdir##*/}
outdir=${tmpdir}/${svcname}
mkdir "$outdir"
printf 'bundle\n' > "$outdir"/type
while read -r member ; do
if ! test -r "${base}/source/${member}"/disabled ; then
printf '%s\n' "$member" >> "${outdir}/contents"
fi
done < "$svcdir"/contents
elif test -r "$svcdir"/instances ; then
svcname=${svcdir##*/}
outdir=${tmpdir}/${svcname}
mkdir "$outdir"
printf 'bundle\n' > "$outdir"/type
sed -e "s/^/${svcname}@/" -e "s@/@-@g" "$svcdir"/instances > "$outdir"/contents
while read -r instance ; do
outdir=${tmpdir}/${svcname}@$(echo "${instance}" | tr / -)
cp -pR "$svcdir" "$outdir"
find "$outdir" -type f -exec sed -i "s@%I@${instance}@g" {} +
done < "$svcdir"/instances
else
cp -pR "$svcdir" "$tmpdir"
fi
done
for svcdir in "$tmpdir"/* ; do
if test -r "$svcdir"/logdir ; then
svcname=${svcdir##*/}
logname="${svcname}-log"
outdir=${tmpdir}/${logname}
logdir=/var/log/$(cat "$svcdir"/logdir)
mkdir "$outdir"
printf '%s\n' "$logname" > "${svcdir}/producer-for"
printf '%s\n' "$svcname" > "${outdir}/consumer-for"
printf 'filesystems\n' > "$outdir"/dependencies
printf '3\n' > "$outdir"/notification-fd
cat > "$outdir"/run << EOF
#!/bin/execlineb -P
if { install -d -m 0750 -o log -g log ${logdir} }
umask 027
s6-setuidgid log
s6-log -d3 -- !zstd t ${logdir}
EOF
chmod +x "$outdir"/run
printf 'longrun\n' > "$outdir"/type
fi
done
if s6-rc-compile -h nobody "${base}/compiled.${date}" "$tmpdir"; then
if test -d "${base}/compiled" ; then
s6-rc-update "${base}/compiled.${date}"
fi
rm -rf "${base}/compiled"
ln -fns "compiled.${date}" "${base}/compiled"
fi
rm -rf "$tmpdir"