Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
69 lines (60 loc) · 2.75 KB
/
Copy pathbuild.sh
File metadata and controls
69 lines (60 loc) · 2.75 KB
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
#!/bin/bash
#
# build.sh - package the source/ tree into an Unraid .txz and update the .plg MD5.
#
# Produces packages/pangolin_cli-<version>.txz where <version> is read from the
# .plg, then writes the package MD5 back into the .plg so the two stay in sync.
#
# Refuses to overwrite an existing .txz with different content (a same-version
# package with a new MD5 would break installs of the already-published release);
# pass --force to overwrite anyway.
#
set -euo pipefail
FORCE=0
if [ "${1:-}" = "--force" ]; then FORCE=1; fi
HERE="$(cd "$(dirname "$0")" && pwd)"
NAME="pangolin_cli"
PLG="${HERE}/${NAME}.plg"
SRC="${HERE}/source"
OUT="${HERE}/packages"
VERSION="$(grep -oP '<!ENTITY version\s+"\K[^"]+' "$PLG")"
TXZ="${OUT}/${NAME}-${VERSION}.txz"
mkdir -p "$OUT"
# Executable bits for shipped scripts. tar packs whatever mode the source
# tree has (an SMB/FAT working copy drops exec bits), and /update.php runs the
# webGui wrapper directly - packed as 0644 it makes the Connect button fail
# silently. So assert the modes here, right before packing.
chmod 0755 "${SRC}/etc/rc.d/rc.pangolin" \
"${SRC}/usr/local/emhttp/plugins/${NAME}/scripts/rc.pangolin"
# Build the package. Slackware packages are xz tarballs rooted at /.
# Pack to a temp file first so an existing (possibly published) .txz is never
# clobbered before the overwrite guard below has compared it.
#
# --mode=go-w strips the group/other write bits from every archived member.
# The working copy sits on a share that reports 0666 for files and 0777 for
# directories, and tar otherwise packs exactly that, so installs ended up with
# a world-writable /etc/logrotate.d/pangolin_cli. logrotate refuses such a
# config outright ("Ignoring pangolin_cli because it is writable by group or
# others"), which both mails the daily cron error to the user and leaves the
# log unrotated. The change is symbolic, so the exec bits set above survive,
# and it applies only to the archive - the working copy is left alone.
echo "Building ${TXZ} ..."
( cd "$SRC" && tar --owner=0 --group=0 --mode='go-w' -cJf "${TXZ}.tmp" . )
if [ -e "$TXZ" ] && [ "$FORCE" = "0" ]; then
OLD_MD5="$(md5sum "$TXZ" | cut -d' ' -f1)"
NEW_MD5="$(md5sum "${TXZ}.tmp" | cut -d' ' -f1)"
if [ "$OLD_MD5" != "$NEW_MD5" ]; then
rm -f "${TXZ}.tmp"
echo "ERROR: ${TXZ} already exists with different content (${OLD_MD5})." >&2
echo "Bump <!ENTITY version> in ${NAME}.plg (e.g. add an a/b suffix for a" >&2
echo "same-day rebuild) or rerun with --force to overwrite it." >&2
exit 1
fi
fi
mv -f "${TXZ}.tmp" "$TXZ"
MD5="$(md5sum "$TXZ" | cut -d' ' -f1)"
echo "Package MD5: ${MD5}"
# Update the MD5 entity in the .plg.
sed -i -E "s#(<!ENTITY md5\s+\")[^\"]*(\">)#\1${MD5}\2#" "$PLG"
echo "Updated ${NAME}.plg with new MD5."
echo "Done."