actions-template/docker-runner/common/setup.sh

142 lines
3.8 KiB
Bash

#!/bin/bash
echo "=========================================="
echo " Gitea Runner Installation Script "
echo "=========================================="
echo ""
# 持久化安装路径
INSTALL_PATH="/data/bin/act_runner"
SYSTEM_PATH="/usr/local/bin/act_runner"
# 创建目录
mkdir -p /data/bin
# 检查是否已安装
if [ -f "$INSTALL_PATH" ]; then
CURRENT_VERSION=$($INSTALL_PATH --version 2>/dev/null | grep -oP 'version \K[0-9.]+' || echo "unknown")
echo "⚠ act_runner already installed (version: $CURRENT_VERSION)"
echo " Location: $INSTALL_PATH"
echo ""
read -p "Do you want to reinstall/upgrade? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Installation cancelled."
exit 0
fi
rm -f "$INSTALL_PATH" "$SYSTEM_PATH"
fi
# 获取要安装的版本
echo "Available versions: https://dl.gitea.com/act_runner/"
echo ""
read -p "Enter version to install (default: 0.2.13): " RUNNER_VERSION
RUNNER_VERSION=${RUNNER_VERSION:-0.2.13}
ARCH=$(uname -m)
case "$ARCH" in
x86_64)
RUNNER_ARCH="amd64"
;;
aarch64|arm64)
RUNNER_ARCH="arm64"
;;
armv7l)
RUNNER_ARCH="arm-7"
;;
*)
echo "⚠ Unknown architecture: $ARCH"
RUNNER_ARCH="arm64"
;;
esac
# 确认架构
echo ""
echo "Detected architecture: $ARCH -> $RUNNER_ARCH"
read -p "Is this correct? (Y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Nn]$ ]]; then
echo ""
echo "Available architectures:"
echo " 1. amd64 (x86_64)"
echo " 2. arm64 (aarch64)"
echo " 3. arm-7 (armv7l)"
read -p "Select architecture (1-3): " ARCH_CHOICE
case "$ARCH_CHOICE" in
1) RUNNER_ARCH="amd64" ;;
2) RUNNER_ARCH="arm64" ;;
3) RUNNER_ARCH="arm-7" ;;
*)
echo "Invalid choice. Exiting."
exit 1
;;
esac
fi
DOWNLOAD_URL="https://dl.gitea.com/act_runner/${RUNNER_VERSION}/act_runner-${RUNNER_VERSION}-linux-${RUNNER_ARCH}"
echo ""
echo "Download Configuration:"
echo " Version: $RUNNER_VERSION"
echo " Architecture: $RUNNER_ARCH"
echo " URL: $DOWNLOAD_URL"
echo " Install Location: $INSTALL_PATH (persistent)"
echo ""
read -p "Proceed with download? (Y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Nn]$ ]]; then
echo "Installation cancelled."
exit 0
fi
echo ""
echo "Downloading act_runner..."
echo ""
# 下载到持久化目录
if curl -L "$DOWNLOAD_URL" -o "$INSTALL_PATH"; then
chmod +x "$INSTALL_PATH"
# 同时创建软链接到系统路径
ln -sf "$INSTALL_PATH" "$SYSTEM_PATH"
# 验证安装
if $INSTALL_PATH --version; then
echo ""
echo "=========================================="
echo "✓ act_runner installed successfully!"
echo "=========================================="
echo ""
echo "Version: $($INSTALL_PATH --version)"
echo "Location: $INSTALL_PATH (persistent storage)"
echo ""
echo "Next steps:"
echo "1. Register the runner:"
echo " docker-compose exec gitea-runner /data/register.sh"
echo ""
echo "2. Restart the container:"
echo " docker-compose restart"
echo ""
echo "Note: act_runner is saved in persistent storage"
echo " and will survive container restarts."
echo ""
else
echo ""
echo "✗ Installation verification failed!"
rm -f "$INSTALL_PATH" "$SYSTEM_PATH"
exit 1
fi
else
echo ""
echo "✗ Download failed!"
echo "Please check:"
echo " - Internet connection"
echo " - Version number is correct: $RUNNER_VERSION"
echo " - Architecture is correct: $RUNNER_ARCH"
echo " - URL is accessible: $DOWNLOAD_URL"
echo ""
echo "You can check available versions at:"
echo " https://dl.gitea.com/act_runner/"
exit 1
fi