67 lines
2.1 KiB
Bash
Executable File
67 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
set -Eeuo pipefail
|
|
|
|
# Installs artifacts uploaded by `make production/deploy`. Run as root or as an
|
|
# administrator with passwordless sudo.
|
|
if [[ $(id -u) -ne 0 ]]; then
|
|
exec sudo -n "$0" "$@"
|
|
fi
|
|
|
|
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
|
APPLICATION_DIR=/opt/gardomatic
|
|
STATE_DIR=/var/lib/gardomatic
|
|
ENV_FILE=/etc/gardomatic/gardomatic.env
|
|
|
|
required_files=(
|
|
api
|
|
web
|
|
cli
|
|
api.service
|
|
web.service
|
|
create-admin.sh
|
|
)
|
|
for file in "${required_files[@]}"; do
|
|
[[ -f "$SCRIPT_DIR/$file" ]] || {
|
|
printf 'Missing deployment artifact: %s\n' "$file" >&2
|
|
exit 1
|
|
}
|
|
done
|
|
[[ -d "$SCRIPT_DIR/migrations" ]] || {
|
|
printf 'Missing deployment artifact: migrations\n' >&2
|
|
exit 1
|
|
}
|
|
[[ -f "$ENV_FILE" ]] || {
|
|
printf 'Missing runtime configuration: %s; run production/provision first.\n' "$ENV_FILE" >&2
|
|
exit 1
|
|
}
|
|
id gardomatic >/dev/null 2>&1 || {
|
|
printf 'Missing service user gardomatic; run production/provision first.\n' >&2
|
|
exit 1
|
|
}
|
|
|
|
install -d -m 0755 -o root -g root "$APPLICATION_DIR"
|
|
install -d -m 0750 -o gardomatic -g gardomatic "$STATE_DIR"
|
|
install -m 0755 -o root -g root "$SCRIPT_DIR/api" /usr/local/bin/gardomatic-api
|
|
install -m 0755 -o root -g root "$SCRIPT_DIR/web" /usr/local/bin/gardomatic-web
|
|
install -m 0755 -o root -g root "$SCRIPT_DIR/cli" /usr/local/bin/gardomatic-cli
|
|
install -d -m 0755 -o root -g root "$APPLICATION_DIR/migrations"
|
|
rsync --archive --delete "$SCRIPT_DIR/migrations/" "$APPLICATION_DIR/migrations/"
|
|
|
|
install -m 0644 -o root -g root "$SCRIPT_DIR/api.service" /etc/systemd/system/api.service
|
|
install -m 0644 -o root -g root "$SCRIPT_DIR/web.service" /etc/systemd/system/web.service
|
|
install -m 0755 -o root -g root "$SCRIPT_DIR/create-admin.sh" /usr/local/sbin/gardomatic-create-admin
|
|
|
|
# provision-server.sh writes a file compatible with systemd and Bash. Loading it
|
|
# here keeps the database DSN out of command-line arguments and process listings.
|
|
set -a
|
|
# shellcheck disable=SC1091
|
|
source "$ENV_FILE"
|
|
set +a
|
|
migrate -path "$APPLICATION_DIR/migrations" -database "$GARDOMATIC_DB_DSN" up
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable api web
|
|
systemctl restart api web
|
|
|
|
printf 'Gardomatic deployment complete.\n'
|