#!/bin/sh # Bundle www/ into one self-contained installer: dist/install-cabinchat.sh # Works on Linux, macOS and Termux. Usage: sh build.sh set -e cd "$(dirname "$0")" VERSION=$(tr -d ' \r\n' < www/VERSION) OUT=dist/install-cabinchat.sh DELIM=__CABINCHAT_EOF__ PAYLOAD=dist/.payload mkdir -p dist (cd www && find . -type f ! -path './img/*' ! -name '.*' | sort) | while IFS= read -r f; do f=${f#./} if grep -q "^$DELIM\$" "www/$f"; then echo "build: $f contains the line $DELIM - cannot embed it" >&2 exit 1 fi dir=$(dirname "$f") [ "$dir" = . ] || echo " mkdir -p \"\$STAGE/$dir\"" echo " cat > \"\$STAGE/$f\" <<'$DELIM'" cat "www/$f" [ -z "$(tail -c 1 "www/$f")" ] || echo echo "$DELIM" done > "$PAYLOAD" awk -v v="$VERSION" -v p="$PAYLOAD" ' $0 == "@@PAYLOAD@@" { while ((getline l < p) > 0) print l; next } { gsub(/@@VERSION@@/, v); print } ' installer.sh.in > "$OUT" rm -f "$PAYLOAD" chmod 755 "$OUT" sh -n "$OUT" echo "built $OUT (Cabin Chat $VERSION, $(wc -c < "$OUT" | tr -d ' ') bytes)"