feat: add updater to install script
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Kasper Juul Hermansen 2025-01-11 13:02:57 +01:00
parent ef6ae3f2b1
commit 1508fbb2bf
Signed by: kjuulh
SSH Key Fingerprint: SHA256:RjXh0p7U6opxnfd3ga/Y9TCo18FYlHFdSpRIV72S/QM

View File

@ -11,12 +11,18 @@ SERVICE_NAME="${APP_NAME}.service"
INSTALL_DIR="/usr/local/bin" INSTALL_DIR="/usr/local/bin"
CONFIG_DIR="/etc/${APP_NAME}" CONFIG_DIR="/etc/${APP_NAME}"
CHURN_DISCOVERY="https://churn.prod.kjuulh.app" CHURN_DISCOVERY="https://churn.prod.kjuulh.app"
LOG="/var/log/churn-install.log"
# Colors for output # Colors for output
RED='\033[0;31m' RED='\033[0;31m'
GREEN='\033[0;32m' GREEN='\033[0;32m'
NC='\033[0m' # No Color NC='\033[0m' # No Color
exec > >(tee -i ${LOG})
exec 2>&1
echo "Starting churn install $(date)"
# Check if running as root # Check if running as root
if [ "$EUID" -ne 0 ]; then if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Please run as root${NC}" echo -e "${RED}Please run as root${NC}"
@ -75,12 +81,44 @@ Environment=RUST_LOG=h2=warn,hyper=warn,churn=debug,warn
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
echo "Creating churn update service..."
cat > "/etc/systemd/system/${SERVICE_NAME}-update" <<EOF
[Unit]
Description=Daily Churn Update Service
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'curl -s https://git.front.kjuulh.io/kjuulh/churn-v2/raw/branch/main/install.sh | bash'
User=root
[Install]
WantedBy=multi-user.target
EOF
cat > "/etc/systemd/system/${SERVICE_NAME}-update.timer" <<EOF
[Unit]
Description=Run Churn Update Daily
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
EOF
# Reload systemd and enable service # Reload systemd and enable service
echo "Configuring systemd service..." echo "Configuring systemd service..."
systemctl daemon-reload systemctl daemon-reload
systemctl enable "${SERVICE_NAME}" systemctl enable "${SERVICE_NAME}"
systemctl start "${SERVICE_NAME}" systemctl start "${SERVICE_NAME}"
systemctl enable "${SERVICE_NAME}-update.timer"
systemctl start "${SERVICE_NAME}-update.timer"
# Check service status # Check service status
if systemctl is-active --quiet "${SERVICE_NAME}"; then if systemctl is-active --quiet "${SERVICE_NAME}"; then
echo -e "${GREEN}Installation successful! ${APP_NAME} is running.${NC}" echo -e "${GREEN}Installation successful! ${APP_NAME} is running.${NC}"