#!/usr/bin/env bash # # build.sh -- (re)embed the loose deployment files into deploy.sh as a base64 # tar.gz payload after __ARCHIVE_BELOW__. Idempotent: strips any existing # payload first. # # Run this after editing ANY embedded file below, then re-stage deploy.sh -- # the deployed stack uses the EMBEDDED copies, not the loose files. set -euo pipefail DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) SCRIPT="$DIR/deploy.sh" MARKER="__ARCHIVE_BELOW__" # README, cloud-init and the build/deploy scripts are NOT embedded. The generated # cfg/ (copyparty.conf + ftps.pem) is produced on the host at deploy time. FILES=( docker-compose.yml Caddyfile copyparty.conf.example .env.example update.sh ) [[ -f "$SCRIPT" ]] || { echo "deploy.sh not found at $SCRIPT" >&2; exit 1; } for f in "${FILES[@]}"; do [[ -f "$DIR/$f" ]] || { echo "Missing $DIR/$f" >&2; exit 1; } done PAYLOAD=$(tar -czf - -C "$DIR" "${FILES[@]}" | base64) TMP=$(mktemp) trap 'rm -f "$TMP"' EXIT sed "/^${MARKER}\$/,\$d" "$SCRIPT" > "$TMP" { echo "$MARKER" echo "$PAYLOAD" } >> "$TMP" mv "$TMP" "$SCRIPT" chmod +x "$SCRIPT" trap - EXIT size=$(wc -c < "$SCRIPT") echo "Built $SCRIPT (${size} bytes)"