mirror of
https://github.com/storytold/figcraft.git
synced 2026-12-03 15:31:21 -05:00
64 lines
3.0 KiB
Bash
Executable File
64 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Checks install.sh's Caddyfile and settings handling without installing anything (no root, no
|
|
# network): a Caddyfile with other sites is never replaced, only gains one import line, and stays
|
|
# the same however often install.sh runs; old settings gain max_files once, and an operator's own
|
|
# value (bare or quoted) is kept. Run by the packaging lint workflow.
|
|
#
|
|
# Usage: packaging/server/install-test.sh
|
|
set -euo pipefail
|
|
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
WORK="$(mktemp -d)"
|
|
trap 'rm -rf "$WORK"' EXIT
|
|
FAILED=0
|
|
|
|
main() { local caddyfile="$1"; bash "$HERE/install.sh" --caddy-main "$caddyfile" ops@example.com; }
|
|
fail() { printf 'FAIL: %s\n' "$*" >&2; FAILED=1; }
|
|
|
|
# Missing: ours.
|
|
main "$WORK/none" >"$WORK/out"
|
|
grep -qx 'import figcraft-server.caddy' "$WORK/out" || fail "a new Caddyfile imports our site"
|
|
grep -q 'email ops@example.com' "$WORK/out" || fail "a new Caddyfile has the certificate email"
|
|
|
|
# The example site the package ships: replaced by ours.
|
|
printf '# The Caddyfile is an easy way to configure your Caddy web server.\n:80 {\n\troot * /usr/share/caddy\n\tfile_server\n}\n' >"$WORK/default"
|
|
main "$WORK/default" >"$WORK/out"
|
|
grep -q 'usr/share/caddy' "$WORK/out" && fail "the packaged example site is replaced"
|
|
|
|
# Someone else's sites: kept, one import added, and the next run changes nothing.
|
|
printf 'shop.example.com {\n\treverse_proxy 127.0.0.1:8080\n}\n' >"$WORK/theirs"
|
|
cp "$WORK/theirs" "$WORK/run1"
|
|
main "$WORK/run1" >"$WORK/run2"
|
|
grep -q 'shop.example.com' "$WORK/run2" || fail "the operator's site is kept"
|
|
[[ "$(grep -c 'import figcraft-server.caddy' "$WORK/run2")" = 1 ]] || fail "one import line is added"
|
|
main "$WORK/run2" >"$WORK/run3"
|
|
cmp -s "$WORK/run2" "$WORK/run3" || fail "running again leaves a Caddyfile with other sites as it is"
|
|
main "$WORK/run3" >"$WORK/run4"
|
|
cmp -s "$WORK/run3" "$WORK/run4" || fail "and again"
|
|
|
|
# Ours, run again: unchanged (it imports our site).
|
|
main "$WORK/none" >"$WORK/ours1"
|
|
main "$WORK/ours1" >"$WORK/ours2"
|
|
cmp -s "$WORK/ours1" "$WORK/ours2" || fail "our own Caddyfile stays the same"
|
|
|
|
# Settings from before max_files (#1402): it is added once, at the top, outside any [table].
|
|
upgrade() { bash "$HERE/install.sh" --settings-upgrade "$1"; }
|
|
printf 'listen = "127.0.0.1:47900"
|
|
max_files_per_ip = 20
|
|
[extra]
|
|
x = 1
|
|
' >"$WORK/old"
|
|
upgrade "$WORK/old" >"$WORK/new1"
|
|
[[ "$(head -n 1 "$WORK/new1")" = 'max_files = 50000' ]] || fail "old settings gain max_files at the top"
|
|
tail -n +2 "$WORK/new1" | cmp -s - "$WORK/old" || fail "and keep everything else"
|
|
upgrade "$WORK/new1" >"$WORK/new2"
|
|
cmp -s "$WORK/new1" "$WORK/new2" || fail "running again adds nothing"
|
|
# An operator's own value, however the key is written, is kept as it is.
|
|
for key in 'max_files' '"max_files"' "'max_files'" ' max_files'; do
|
|
printf '%s = 1000
|
|
' "$key" >"$WORK/own"
|
|
upgrade "$WORK/own" | cmp -s - "$WORK/own" || fail "an operator's $key is kept"
|
|
done
|
|
|
|
if [[ "$FAILED" = 0 ]]; then echo "install.sh Caddyfile and settings handling: ok"; fi
|
|
exit "$FAILED"
|