64 lines
2.4 KiB
Bash
64 lines
2.4 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
MODE="${MODE:-github}" # github|docker|url
|
|
ED_VER="${ED_VER:-v4}" # v3|v4
|
|
OUTDIR="${OUTDIR:-/out}"
|
|
case "$ED_VER" in
|
|
v3) APP_DIR="Avida-ED"; GITHUB_REPO="https://github.com/Avida-ED/Avida-ED3.git" ;;
|
|
v4) APP_DIR="Avida-ED-Eco"; GITHUB_REPO="https://github.com/Avida-ED/Avida-ED4.git" ;;
|
|
*) echo "Unknown ED_VER=$ED_VER" >&2; exit 2 ;;
|
|
esac
|
|
|
|
mkdir -p "$OUTDIR"
|
|
case "$MODE" in
|
|
github)
|
|
TMPDIR="$(mktemp -d)"
|
|
trap 'rm -rf "$TMPDIR"' EXIT
|
|
git clone --depth 1 "$GITHUB_REPO" "$TMPDIR/source"
|
|
rm -rf "$OUTDIR/$APP_DIR"
|
|
mkdir -p "$OUTDIR/$APP_DIR"
|
|
if command -v rsync >/dev/null 2>&1; then
|
|
rsync -a --exclude .git "$TMPDIR/source"/ "$OUTDIR/$APP_DIR"/
|
|
else
|
|
(cd "$TMPDIR/source" && tar --exclude .git -cf - .) | (cd "$OUTDIR/$APP_DIR" && tar -xf -)
|
|
fi
|
|
;;
|
|
docker)
|
|
# 1) Start your aed-docker container and copy its served webroot
|
|
# Expectation: container serves Avida-ED-Eco at /usr/share/nginx/html/Avida-ED-Eco
|
|
if ! CID="$(docker create --name aedtmp_$ED_VER welsberr/aed-docker:$ED_VER)"; then
|
|
echo "Could not create welsberr/aed-docker:$ED_VER. The canonical source is GitHub; try make fetch-$ED_VER." >&2
|
|
exit 1
|
|
fi
|
|
trap 'docker rm -f aedtmp_'"$ED_VER"' >/dev/null 2>&1 || true' EXIT
|
|
docker cp "aedtmp_$ED_VER:/usr/share/nginx/html/." "$OUTDIR/"
|
|
;;
|
|
url)
|
|
URL="${URL:-https://avida-ed.msu.edu/app4/}"
|
|
apk add --no-cache wget >/dev/null 2>&1 || true
|
|
WGET_STATUS=0
|
|
wget --recursive --no-parent --page-requisites --adjust-extension \
|
|
--compression=auto --convert-links --timestamping \
|
|
--directory-prefix "$OUTDIR" \
|
|
"$URL" || WGET_STATUS=$?
|
|
# normalize into the directory shape expected by the Rust injection step
|
|
if [ ! -d "$OUTDIR/$APP_DIR" ]; then
|
|
SUB="$(find "$OUTDIR" -type f -name index.html | head -n1)"
|
|
if [ -n "$SUB" ]; then
|
|
if command -v rsync >/dev/null 2>&1; then
|
|
rsync -a "$(dirname "$SUB")"/ "$OUTDIR/$APP_DIR"/
|
|
else
|
|
cp -R "$(dirname "$SUB")"/. "$OUTDIR/$APP_DIR"/
|
|
fi
|
|
fi
|
|
fi
|
|
if [ ! -f "$OUTDIR/$APP_DIR/index.html" ]; then
|
|
echo "URL fetch failed: no normalized $OUTDIR/$APP_DIR/index.html found. wget exit status: $WGET_STATUS" >&2
|
|
exit "${WGET_STATUS:-1}"
|
|
fi
|
|
;;
|
|
*) echo "Unknown MODE=$MODE" >&2; exit 1;;
|
|
esac
|
|
|
|
echo "Assets fetched to $OUTDIR"
|