All checks were successful
Deploy ACT Runner Installer / deploy (push) Successful in 10s
137 lines
4.1 KiB
Bash
137 lines
4.1 KiB
Bash
#!/bin/bash
|
|
|
|
check_command() {
|
|
command -v "$1" >/dev/null 2>&1
|
|
}
|
|
|
|
check_version() {
|
|
act_runner_version=$(act_runner -v | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+')
|
|
echo "$act_runner_version"
|
|
}
|
|
|
|
# Ensure jq is installed (attempt auto-install on common distros)
|
|
ensure_jq() {
|
|
if check_command jq; then
|
|
return 0
|
|
fi
|
|
|
|
echo "jq not found. Attempting to install..."
|
|
|
|
SUDO=""
|
|
if [ "$EUID" -ne 0 ]; then
|
|
if check_command sudo; then
|
|
SUDO="sudo"
|
|
else
|
|
echo "Error: jq is required and sudo is not available. Please install jq manually and re-run."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
if check_command apt-get; then
|
|
$SUDO apt-get update -y && $SUDO apt-get install -y jq
|
|
elif check_command dnf; then
|
|
$SUDO dnf install -y jq
|
|
elif check_command yum; then
|
|
$SUDO yum install -y jq
|
|
elif check_command apk; then
|
|
$SUDO apk add --no-cache jq
|
|
elif check_command pacman; then
|
|
$SUDO pacman -Sy --noconfirm jq
|
|
elif check_command zypper; then
|
|
$SUDO zypper install -y jq
|
|
else
|
|
echo "Error: Unsupported package manager. Please install 'jq' manually and re-run."
|
|
exit 1
|
|
fi
|
|
|
|
if ! check_command jq; then
|
|
echo "Error: Failed to install 'jq'. Please install it manually and re-run."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
ensure_jq
|
|
|
|
if check_command act_runner; then
|
|
current_version=$(check_version)
|
|
echo "Current act_runner version: $current_version"
|
|
fi
|
|
|
|
required_commands=("curl" "jq" "wget" "unxz" "sha256sum")
|
|
for cmd in "${required_commands[@]}"; do
|
|
if ! check_command "$cmd"; then
|
|
echo "Error: '$cmd' command not found. Please make sure all required commands are installed."
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
arch=$(uname -m)
|
|
if [ "$arch" = "x86_64" ]; then
|
|
arch="amd64"
|
|
fi
|
|
|
|
json=$(curl -s https://gitea.com/api/v1/repos/gitea/act_runner/releases/latest)
|
|
latest_version=$(echo "$json" | jq -r '.tag_name')
|
|
url_checksum=$(echo "$json" | jq -r '.assets[] | select(.name | contains("linux-'"$arch"'") and contains(".xz.sha256")) | .browser_download_url')
|
|
url_binary=$(echo "$json" | jq -r '.assets[] | select(.name | contains("linux-'"$arch"'") and contains(".xz")) | .browser_download_url')
|
|
checksum_filename=$(basename "$url_checksum")
|
|
filename=$(basename "$url_binary")
|
|
|
|
if [ -z "$current_version" ] || [ "$current_version" != "$latest_version" ]; then
|
|
echo "Updating act_runner to version: $latest_version"
|
|
wget "$url_binary"
|
|
wget "$url_checksum"
|
|
sha256sum -c "$checksum_filename"
|
|
rm "$checksum_filename"
|
|
unxz "$filename"
|
|
filename=${filename%.xz}
|
|
mv "$filename" '/usr/local/bin/act_runner'
|
|
chmod +x /usr/local/bin/act_runner
|
|
echo "Update completed."
|
|
else
|
|
echo "act_runner is up to date."
|
|
fi
|
|
|
|
# Generate default configuration after install and before setting up systemd
|
|
mkdir -p /etc/act_runner /var/lib/act_runner
|
|
if [ ! -f /etc/act_runner/config.yaml ]; then
|
|
echo "Generating default configuration at /etc/act_runner/config.yaml"
|
|
/usr/local/bin/act_runner generate-config >/etc/act_runner/config.yaml
|
|
else
|
|
echo "Existing configuration detected at /etc/act_runner/config.yaml, skipping generation"
|
|
fi
|
|
|
|
# Install systemd service for act_runner
|
|
if command -v systemctl >/dev/null 2>&1; then
|
|
mkdir -p /var/lib/act_runner /etc/act_runner
|
|
chown -R root:root /var/lib/act_runner /etc/act_runner
|
|
|
|
service_path="/etc/systemd/system/act-runner.service"
|
|
cat >"$service_path" <<'EOF'
|
|
[Unit]
|
|
Description=Gitea Actions runner
|
|
Documentation=https://gitea.com/gitea/act_runner
|
|
After=docker.service
|
|
|
|
[Service]
|
|
ExecStart=/usr/local/bin/act_runner daemon --config /etc/act_runner/config.yaml
|
|
ExecReload=/bin/kill -s HUP $MAINPID
|
|
WorkingDirectory=/var/lib/act_runner
|
|
TimeoutSec=0
|
|
RestartSec=10
|
|
Restart=always
|
|
User=root
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable act-runner
|
|
if [ -f /etc/act_runner/config.yaml ]; then
|
|
systemctl start act-runner
|
|
else
|
|
echo "Systemd service installed. Create /etc/act_runner/config.yaml then run: systemctl start act-runner"
|
|
fi
|
|
fi
|