40 lines
1.1 KiB
Bash
Executable File
40 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# deploy_website.sh
|
|
# Builds the Hugo site and rsyncs ./public/ to saboserver:/srv/www.
|
|
# Works from any machine that has the repo + an ssh alias for "saboserver".
|
|
#
|
|
# Usage:
|
|
# ./deploy_website.sh # build + deploy
|
|
# ./deploy_website.sh --dry-run # build + show what rsync WOULD transfer
|
|
# ./deploy_website.sh --no-build # skip hugo build, just rsync existing public/
|
|
|
|
set -euo pipefail
|
|
|
|
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
LOCAL_DIR="${REPO_DIR}/public"
|
|
REMOTE_HOST="saboserver"
|
|
REMOTE_DIR="/srv/www"
|
|
|
|
DRY=""
|
|
DO_BUILD=1
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--dry-run) DRY="--dry-run" ;;
|
|
--no-build) DO_BUILD=0 ;;
|
|
*) echo "Unknown arg: $arg" >&2; exit 2 ;;
|
|
esac
|
|
done
|
|
|
|
if [[ "$DO_BUILD" -eq 1 ]]; then
|
|
echo "==> Building site (hugo)"
|
|
(cd "$REPO_DIR" && hugo --minify)
|
|
fi
|
|
|
|
if [[ ! -d "$LOCAL_DIR" ]]; then
|
|
echo "ERROR: $LOCAL_DIR does not exist. Run hugo first." >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "==> rsync ${LOCAL_DIR}/ -> ${REMOTE_HOST}:${REMOTE_DIR}/ ${DRY:+(dry-run)}"
|
|
rsync -avz --delete $DRY -e ssh "${LOCAL_DIR}/" "${REMOTE_HOST}:${REMOTE_DIR}/"
|