fix: Alpine-compatible install script — no sudo, doas, curl pre-installed
CI / lint (push) Successful in 29s
CI / security (push) Successful in 14s
CI / test (push) Successful in 29s
CI / build (push) Successful in 14s
CI / e2e (push) Failing after 20s

- Changed shebang to /bin/sh for wider compatibility
- Script requires root (sudo/doas) — all privileged ops work directly
- Alpine: installs curl+docker before download (was failing silently)
- Alpine: writes OpenRC init directly (no sudo/tee permission issue)
- Debian: auto-detects SUDO_USER for WorkingDirectory instead of hardcoded /home/bruno
- All OS: prerequisites (curl, docker) installed in unified step [1/5]
This commit is contained in:
2026-07-25 09:24:10 -04:00
parent d37010c6ae
commit b2e9b8aecc
+59 -62
View File
@@ -1,13 +1,18 @@
#!/bin/bash #!/bin/sh
# ================================================================ # ================================================================
# install-gitea-runner.sh # install-gitea-runner.sh
# Installation automatisée d'un runner Gitea Actions # Installation automatisée d'un runner Gitea Actions
# #
# Usage: # Usage:
# ./install-gitea-runner.sh <TOKEN> <NAME> <LABELS> # sudo ./install-gitea-runner.sh <TOKEN> <NAME> <LABELS>
# #
# Exemple: # Exemple (Alpine) :
# ./install-gitea-runner.sh abc123 "dev-lab" "self-hosted,lab,docker,obsigate" # doas ./install-gitea-runner.sh abc123 "dev-lab" "self-hosted,lab,docker,obsigate"
#
# Exemple (Debian) :
# sudo ./install-gitea-runner.sh abc123 "dev-lab" "self-hosted,lab,docker,obsigate"
#
# ⚠️ Doit être exécuté en root (sudo / doas)
# ================================================================ # ================================================================
set -e set -e
@@ -16,21 +21,16 @@ NAME="$2"
LABELS="$3" LABELS="$3"
if [ -z "$TOKEN" ] || [ -z "$NAME" ] || [ -z "$LABELS" ]; then if [ -z "$TOKEN" ] || [ -z "$NAME" ] || [ -z "$LABELS" ]; then
echo "❌ Usage: ./install-gitea-runner.sh <TOKEN> <NAME> <LABELS>" echo "❌ Usage: sudo ./install-gitea-runner.sh <TOKEN> <NAME> <LABELS>"
echo " Example: ./install-gitea-runner.sh abc123 dev-lab 'self-hosted,lab,docker,obsigate'" echo " Example: sudo ./install-gitea-runner.sh abc123 dev-lab 'self-hosted,lab,docker,obsigate'"
exit 1 exit 1
fi fi
echo "=============================================" # ── 0. Detect OS + privilege elevation method ──────────────────────
echo " Gitea Runner Installer"
echo " Server : $NAME"
echo " Labels : $LABELS"
echo "============================================="
echo ""
# ── 1. Detect OS ─────────────────────────────────────────────────
if [ -f /etc/alpine-release ]; then if [ -f /etc/alpine-release ]; then
OS="alpine" OS="alpine"
# Alpine: utilise doas, mais si on est déjà root (via doas), on continue
# On vérifie juste que curl et les outils de base sont là
elif [ -f /etc/debian_version ]; then elif [ -f /etc/debian_version ]; then
OS="debian" OS="debian"
elif [ -f /etc/arch-release ]; then elif [ -f /etc/arch-release ]; then
@@ -41,28 +41,23 @@ else
fi fi
echo "🖥️ Detected OS: $OS" echo "🖥️ Detected OS: $OS"
# ── 2. Ensure Docker ───────────────────────────────────────────── # ── 1. Install prerequisites ──────────────────────────────────────
echo "[1/4] Checking Docker..." echo "[1/5] Installing prerequisites..."
if ! command -v docker &>/dev/null; then if [ "$OS" = "alpine" ]; then
echo " Installing Docker..." apk add --no-cache curl docker > /dev/null 2>&1
if [ "$OS" = "alpine" ]; then rc-update add docker boot 2>/dev/null || true
apk add --no-cache docker curl service docker start 2>/dev/null || true
rc-update add docker boot elif [ "$OS" = "debian" ]; then
service docker start apt-get update -qq
elif [ "$OS" = "debian" ]; then apt-get install -y -qq docker.io curl
sudo apt-get update -qq elif [ "$OS" = "arch" ]; then
sudo apt-get install -y -qq docker.io curl pacman -S --noconfirm docker curl
sudo usermod -aG docker "$USER" systemctl enable --now docker
elif [ "$OS" = "arch" ]; then
sudo pacman -S --noconfirm docker curl
sudo systemctl enable --now docker
sudo usermod -aG docker "$USER"
fi
fi fi
echo " ✅ Docker OK" echo " ✅ Prerequisites OK (curl, docker)"
# ── 3. Download & install runner ────────────────────────────────── # ── 2. Download runner ─────────────────────────────────────────────
echo "[2/4] Downloading Gitea act_runner..." echo "[2/5] Downloading Gitea act_runner v0.2.11..."
ARCH=$(uname -m) ARCH=$(uname -m)
case "$ARCH" in case "$ARCH" in
x86_64) RUNNER_ARCH="amd64" ;; x86_64) RUNNER_ARCH="amd64" ;;
@@ -72,42 +67,44 @@ case "$ARCH" in
esac esac
RUNNER_URL="https://dl.gitea.com/act_runner/0.2.11/act_runner-0.2.11-linux-${RUNNER_ARCH}" RUNNER_URL="https://dl.gitea.com/act_runner/0.2.11/act_runner-0.2.11-linux-${RUNNER_ARCH}"
sudo curl -sL -o /usr/local/bin/act_runner "$RUNNER_URL" curl -sL -o /usr/local/bin/act_runner "$RUNNER_URL"
sudo chmod +x /usr/local/bin/act_runner chmod +x /usr/local/bin/act_runner
echo " ✅ act_runner installed ($(/usr/local/bin/act_runner --version 2>&1 | head -1))" echo " ✅ act_runner v0.2.11 installed"
# ── 4. Register ─────────────────────────────────────────────────── # ── 3. Register ────────────────────────────────────────────────────
echo "[3/4] Registering runner with Gitea..." echo "[3/5] Registering runner with Gitea..."
/usr/local/bin/act_runner register \ /usr/local/bin/act_runner register \
--no-interactive \
--instance https://git.dracodev.net \ --instance https://git.dracodev.net \
--token "$TOKEN" \ --token "$TOKEN" \
--name "$NAME" \ --name "$NAME" \
--labels "$LABELS" \ --labels "$LABELS"
--no-interactive
echo " ✅ Runner registered" echo " ✅ Runner registered"
# ── 5. Install as service ──────────────────────────────────────── # ── 4. Install as service ─────────────────────────────────────────
echo "[4/4] Installing as system service..." echo "[4/5] Installing as system service..."
if [ "$OS" = "alpine" ]; then if [ "$OS" = "alpine" ]; then
# Alpine OpenRC # Alpine OpenRC — le script est exécuté en root via doas
sudo tee /etc/init.d/gitea-runner > /dev/null <<EOF cat > /etc/init.d/gitea-runner <<'OPENRC_EOF'
#!/sbin/openrc-run #!/sbin/openrc-run
name="Gitea Actions Runner ($NAME)" name="Gitea Actions Runner"
command="/usr/local/bin/act_runner" command="/usr/local/bin/act_runner"
command_args="daemon" command_args="daemon"
command_background=true command_background=true
pidfile="/run/\${RC_SVCNAME}.pid" pidfile="/run/${RC_SVCNAME}.pid"
output_log="/var/log/gitea-runner.log" output_log="/var/log/gitea-runner.log"
error_log="/var/log/gitea-runner.log" error_log="/var/log/gitea-runner.log"
EOF OPENRC_EOF
sudo chmod +x /etc/init.d/gitea-runner chmod +x /etc/init.d/gitea-runner
sudo rc-update add gitea-runner default rc-update add gitea-runner default
sudo service gitea-runner start service gitea-runner start
else else
# Systemd (Debian, Arch) # Systemd (Debian, Arch)
# Note: act_runner cherche .runner dans WorkingDirectory → doit être le home # act_runner cherche .runner dans WorkingDirectory → home de l'utilisateur
sudo tee /etc/systemd/system/gitea-runner.service > /dev/null <<EOF TARGET_USER="${SUDO_USER:-bruno}"
TARGET_HOME=$(eval echo "~$TARGET_USER")
cat > /etc/systemd/system/gitea-runner.service <<SYSTEMD_EOF
[Unit] [Unit]
Description=Gitea Actions Runner ($NAME) Description=Gitea Actions Runner ($NAME)
After=network.target docker.service After=network.target docker.service
@@ -115,26 +112,26 @@ Requires=docker.service
[Service] [Service]
ExecStart=/usr/local/bin/act_runner daemon ExecStart=/usr/local/bin/act_runner daemon
WorkingDirectory=/home/bruno WorkingDirectory=$TARGET_HOME
User=bruno User=$TARGET_USER
Restart=always Restart=always
RestartSec=5 RestartSec=5
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
EOF SYSTEMD_EOF
sudo systemctl daemon-reload systemctl daemon-reload
sudo systemctl enable --now gitea-runner systemctl enable --now gitea-runner
fi fi
echo " ✅ Service installed and started" echo " ✅ Service installed and started"
# ── 6. Verify ───────────────────────────────────────────────────── # ── 5. Verify ──────────────────────────────────────────────────────
echo "" echo "[5/5] Verifying..."
sleep 2 sleep 2
if [ "$OS" = "alpine" ]; then if [ "$OS" = "alpine" ]; then
sudo service gitea-runner status 2>&1 | head -3 service gitea-runner status 2>&1 | head -3
else else
sudo systemctl status gitea-runner --no-pager -l 2>&1 | head -5 systemctl status gitea-runner --no-pager -l 2>&1 | head -5
fi fi
echo "" echo ""