Files
hub/deploy/run.sh
T

108 lines
2.6 KiB
Bash

#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")"
host="root@hub.hordelab.com"
remote_path="/var/horde/hub/"
run_nginx() {
echo "Uploading nginx config file"
scp template/nginx.conf "$host:/etc/nginx/sites-enabled/hub.hordelab.com"
ssh "$host" -t "
nginx -s reload
# full process is currently broken
#certbot --keep -d hub.hordelab.com
# uncomment if needed
#certbot certonly -d hub.hordelab.com
#nginx -s reload
"
}
run_service() {
echo "Uploading Launcher and Service"
scp template/launch-hub.sh "$host:/var/horde/launch-hub.sh"
scp template/systemd.service "$host:/etc/systemd/system/horde-hub.service"
ssh "$host" -t "
systemctl daemon-reload
systemctl enable horde-hub.service
systemctl start horde-hub.service
"
}
run_update() {
echo "Updating repository"
ssh "$host" -t "
source ~/.nvm/nvm.sh #?
cd /var/horde/hub
git pull
make install
make web
"
}
run_dist() {
echo "Uploading frontend/dist to $host:/var/frontend/dist"
ssh "$host" "rm -rf $remote_path/frontend/dist && mkdir $remote_path/frontend/dist"
scp -r ../frontend/dist "$host:$remote_path/frontend/"
}
restart_service() {
echo "Restarting horde-hub.service"
ssh "$host" -t "systemctl restart horde-hub.service"
}
# Determine which stages to run
stages=()
do_restart=0
if [[ $# -eq 0 ]]; then
# Interactive prompts when no arguments are given
read -p "Run nginx deployment? [Y/n] " choice
if [[ -z "$choice" || "$choice" =~ ^[Yy]$ ]]; then
stages+=(nginx)
fi
read -p "Run service deployment? [Y/n] " choice
if [[ -z "$choice" || "$choice" =~ ^[Yy]$ ]]; then
stages+=(service)
fi
read -p "Run update (git pull + make install)? [Y/n] " choice
if [[ -z "$choice" || "$choice" =~ ^[Yy]$ ]]; then
stages+=(update)
fi
else
# Parse arguments
for arg in "$@"; do
case "$arg" in
nginx|service|update|dist)
stages+=("$arg")
do_restart=1
;;
--dist)
stages+=("dist")
;;
*)
echo "Unknown argument: $arg" >&2
exit 1
;;
esac
done
fi
# Execute selected stages
for stage in "${stages[@]}"; do
case "$stage" in
nginx) run_nginx ;;
service) run_service ;;
update) run_update ;;
dist) run_dist ;;
esac
done
# Final stage: always restart the systemd service at the end
if [[ $do_restart -eq 1 ]]; then restart_service; fi