60 lines
2.0 KiB
Bash
60 lines
2.0 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
cd -- "$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
|
|
|
if ! command -v docker >/dev/null 2>&1; then
|
|
echo "Docker is not installed. Enable Docker/Compose on OMV, then run this command again." >&2
|
|
exit 1
|
|
fi
|
|
USE_SUDO=0
|
|
if ! docker info >/dev/null 2>&1; then
|
|
if command -v sudo >/dev/null 2>&1; then
|
|
echo "Docker access requires administrator permissions. Enter the server password in this terminal if prompted."
|
|
sudo docker info >/dev/null
|
|
USE_SUDO=1
|
|
else
|
|
echo "Docker is unavailable. Run this script as a user with Docker access." >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
compose() {
|
|
if [ "$USE_SUDO" = 1 ]; then
|
|
sudo docker compose -f compose.server.yaml "$@"
|
|
else
|
|
docker compose -f compose.server.yaml "$@"
|
|
fi
|
|
}
|
|
compose version >/dev/null
|
|
MODE="${1:---public}"
|
|
case "$MODE" in
|
|
--public) PROFILE=public ;;
|
|
--lan) PROFILE=local ;;
|
|
*) echo "Usage: sh start-server.sh [--public|--lan]" >&2; exit 1 ;;
|
|
esac
|
|
|
|
compose config --quiet
|
|
if [ "$PROFILE" = public ]; then
|
|
compose --profile public up -d --pull always
|
|
else
|
|
compose --profile public stop public
|
|
compose up -d --pull always web library
|
|
fi
|
|
compose ps
|
|
printf '\nSite on the server: http://192.168.0.181:8080/\n'
|
|
if [ "$PROFILE" = public ]; then
|
|
echo "Waiting for the public HTTPS address..."
|
|
attempt=0
|
|
while [ "$attempt" -lt 30 ]; do
|
|
public_url="$(compose logs --no-color --tail=100 public 2>/dev/null | grep -Eo 'https://[a-z0-9-]+\.trycloudflare\.com' | tail -n 1 || true)"
|
|
if [ -n "$public_url" ]; then
|
|
printf '\nPUBLIC SITE: %s\n' "$public_url"
|
|
echo "Anyone can open this address. It changes when the tunnel restarts."
|
|
echo "Keep the OMV server running; this SSH terminal may be closed."
|
|
exit 0
|
|
fi
|
|
attempt=$((attempt + 1))
|
|
sleep 2
|
|
done
|
|
echo "No public address yet. Inspect: docker compose -f compose.server.yaml --profile public logs --tail=100 public" >&2
|
|
exit 1
|
|
fi |