59 lines
2.6 KiB
Bash
59 lines
2.6 KiB
Bash
#!/bin/bash
|
|||
|
|
#
|
||
|
|
# Take the translation server off the NAS.
|
||
|
|
#
|
||
|
|
# The app hosts its own server now — each campus runs a self-contained copy —
|
||
|
|
# so nothing needs to live on the NAS any more.
|
||
|
|
#
|
||
|
|
# Stops and removes the container and its image. Deliberately LEAVES
|
||
|
|
# /volume2/docker/church-translate/data alone: it holds the service transcripts,
|
||
|
|
# and deleting those is not a decision a cleanup script gets to make.
|
||
|
|
#
|
||
|
|
set -euo pipefail
|
||
|
|
ROOT="$(cd "$(dirname "$0")" && pwd)"
|
||
|
|
NAS_HOST="${NAS_HOST:-10.1.1.5}"; NAS_USER="${NAS_USER:-Christian}"
|
||
|
|
NAS_PATH="${NAS_PATH:-/volume2/docker/church-translate}"
|
||
|
|
CRED_FILE="$HOME/.church-translate-deploy"
|
||
|
|
LEGACY="$HOME/Documents/recurring-checklist-app/build-deploy.sh"
|
||
|
|
|
||
|
|
[ -z "${NAS_PASS:-}" ] && [ -r "$CRED_FILE" ] && NAS_PASS="$(head -n1 "$CRED_FILE")"
|
||
|
|
[ -z "${NAS_PASS:-}" ] && [ -r "$LEGACY" ] && NAS_PASS="$(sed -n "s/^NAS_PASS='\(.*\)'$/\1/p" "$LEGACY" | head -n1)"
|
||
|
|
if [ -z "${NAS_PASS:-}" ] && [ -t 0 ]; then
|
||
|
|
printf 'Password for %s@%s: ' "$NAS_USER" "$NAS_HOST"; stty -echo; read -r NAS_PASS; stty echo; printf '\n'
|
||
|
|
fi
|
||
|
|
[ -n "${NAS_PASS:-}" ] || { echo "No NAS password available." >&2; exit 1; }
|
||
|
|
|
||
|
|
EXP="$(mktemp /tmp/ct-rm.XXXXXX)"
|
||
|
|
cat > "$EXP" <<'EXPEOF'
|
||
|
|
#!/usr/bin/expect -f
|
||
|
|
set timeout 300
|
||
|
|
log_user 1
|
||
|
|
set pass $env(CT_PASS)
|
||
|
|
spawn -noecho bash -c [lindex $argv 0]
|
||
|
|
expect { -nocase "password:" { send "$pass\r"; exp_continue } eof }
|
||
|
|
catch wait result
|
||
|
|
exit [lindex $result 3]
|
||
|
|
EXPEOF
|
||
|
|
chmod +x "$EXP"; trap 'rm -f "$EXP" /tmp/ct-rm-remote.sh' EXIT
|
||
|
|
|
||
|
|
cat > /tmp/ct-rm-remote.sh <<REMOTEEOF
|
||
|
|
set -e
|
||
|
|
cd "$NAS_PATH" 2>/dev/null || { echo "nothing deployed at $NAS_PATH"; exit 0; }
|
||
|
|
echo "--- stopping ---"
|
||
|
|
# docker stop + rm rather than 'compose down --rmi': removing the image pulls in
|
||
|
|
# a layer sweep that can run for many minutes on a NAS, and the container's
|
||
|
|
# restart policy is 'unless-stopped', so stopping it is what actually keeps it
|
||
|
|
# down across reboots.
|
||
|
|
echo "\$REMOTE_PASS" | sudo -S /usr/local/bin/docker stop -t 5 church-translate 2>&1 | tail -2 || true
|
||
|
|
echo "\$REMOTE_PASS" | sudo -S /usr/local/bin/docker rm church-translate 2>&1 | tail -2 || true
|
||
|
|
echo "--- remaining containers ---"
|
||
|
|
echo "\$REMOTE_PASS" | sudo -S /usr/local/bin/docker ps -a --filter name=church-translate --format "{{.Names}} {{.Status}}" || true
|
||
|
|
echo "--- data left in place ---"
|
||
|
|
ls -la data/ 2>/dev/null | head -5 || echo "(no data dir)"
|
||
|
|
REMOTEEOF
|
||
|
|
|
||
|
|
echo "==> Removing the translation container from $NAS_HOST"
|
||
|
|
CT_PASS="$NAS_PASS" expect "$EXP" \
|
||
|
|
"ssh -o StrictHostKeyChecking=accept-new $NAS_USER@$NAS_HOST 'REMOTE_PASS=\"$NAS_PASS\" bash -s' < /tmp/ct-rm-remote.sh"
|
||
|
|
echo "==> Done. Transcripts remain in $NAS_PATH/data if you want them."
|