201 lines
7.1 KiB
Bash
201 lines
7.1 KiB
Bash
#!/usr/bin/env bash
|
|
_CS_DEFAULT_URL="${COMMUNITY_SCRIPTS_URL:-${_CS_DEFAULT_URL:-https://git.mattway.com.au/matt/gitea-runner-script/raw/branch/main}}"
|
|
_cs_boot="${COMMUNITY_SCRIPTS_CORE_DIR:-$(dirname "${BASH_SOURCE[0]}")/../../core}/core/build.func"
|
|
source "$_cs_boot" 2>/dev/null || source <(curl -fsSL "${COMMUNITY_SCRIPTS_CORE_URL:-https://raw.githubusercontent.com/community-scripts/core/main}/core/build.func")
|
|
# Copyright (c) 2021-2026 community-scripts ORG
|
|
# Author: mattyway
|
|
# License: MIT | https://git.mattway.com.au/matt/gitea-runner-script/raw/branch/main/LICENSE
|
|
# Source: https://about.gitea.com/ | Github: https://gitea.com/gitea/act_runner
|
|
|
|
APP="Gitea Runner"
|
|
var_tags="${var_tags:-gitea;runner;docker;ci-cd}"
|
|
var_arm64="${var_arm64:-yes}"
|
|
var_unprivileged="${var_unprivileged:-1}"
|
|
var_keyctl="${var_keyctl:-1}"
|
|
|
|
if [[ -z "${var_os:-}" ]] && command -v pveversion >/dev/null 2>&1; then
|
|
var_os=$(msg_menu "Choose the container OS" \
|
|
"debian" "Debian 12/13 (Recommended for Docker actions)" \
|
|
"alpine" "Alpine (Minimal footprint)")
|
|
fi
|
|
|
|
if [[ "${var_os:-}" == "alpine" ]]; then
|
|
var_cpu="${var_cpu:-2}"
|
|
var_ram="${var_ram:-1024}"
|
|
var_disk="${var_disk:-10}"
|
|
var_version="${var_version:-3.24}"
|
|
else
|
|
var_cpu="${var_cpu:-2}"
|
|
var_ram="${var_ram:-2048}"
|
|
var_disk="${var_disk:-15}"
|
|
var_version="${var_version:-13}"
|
|
fi
|
|
|
|
header_info "$APP"
|
|
variables
|
|
NSAPP="gitea-runner"
|
|
var_install="${NSAPP}-install"
|
|
color
|
|
catch_errors
|
|
|
|
update_deb_based() {
|
|
if [[ ! -f /usr/local/bin/gitea-runner && ! -f /usr/local/bin/act_runner ]]; then
|
|
msg_error "No ${APP} installation found!"
|
|
exit 1
|
|
fi
|
|
|
|
msg_info "Updating base system"
|
|
apt_update_safe
|
|
$STD apt-get upgrade -y
|
|
msg_ok "Base system updated"
|
|
|
|
if dpkg-query -W -f='${Status}' docker-ce 2>/dev/null | grep -q "ok installed"; then
|
|
USE_DOCKER_REPO="true" setup_docker
|
|
fi
|
|
|
|
msg_info "Checking for Gitea Runner updates"
|
|
local runner_bin
|
|
if [[ -f /usr/local/bin/gitea-runner ]]; then
|
|
runner_bin="/usr/local/bin/gitea-runner"
|
|
else
|
|
runner_bin="/usr/local/bin/act_runner"
|
|
fi
|
|
|
|
local current_version
|
|
current_version=$("$runner_bin" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || echo "0.0.0")
|
|
|
|
local release_json
|
|
release_json=$(curl -fsSL --connect-timeout 10 "https://gitea.com/api/v1/repos/gitea/act_runner/releases/latest" 2>/dev/null || true)
|
|
if [[ -z "$release_json" ]]; then
|
|
release_json=$(curl -fsSL --connect-timeout 10 "https://gitea.com/api/v1/repos/gitea/runner/releases/latest" 2>/dev/null || true)
|
|
fi
|
|
|
|
if [[ -n "$release_json" ]]; then
|
|
local latest_version
|
|
latest_version=$(echo "$release_json" | jq -r '.tag_name // empty' | tr -d 'v')
|
|
local clean_current="${current_version#v}"
|
|
|
|
if [[ -n "$latest_version" && "$latest_version" != "$clean_current" ]]; then
|
|
msg_info "Updating Gitea Runner (${clean_current} -> ${latest_version})"
|
|
local arch
|
|
case "$(uname -m)" in
|
|
x86_64) arch="amd64" ;;
|
|
aarch64|arm64) arch="arm64" ;;
|
|
armv7l) arch="arm-7" ;;
|
|
*) arch="amd64" ;;
|
|
esac
|
|
|
|
local dl_url
|
|
dl_url=$(echo "$release_json" | jq -r --arg a "linux-$arch" '.assets[] | select(.name | endswith($a)) | .browser_download_url' | head -1)
|
|
|
|
if [[ -n "$dl_url" && "$dl_url" != "null" ]]; then
|
|
systemctl stop gitea-runner 2>/dev/null || systemctl stop act_runner 2>/dev/null || true
|
|
curl -fsSL "$dl_url" -o "${runner_bin}.new"
|
|
chmod +x "${runner_bin}.new"
|
|
mv "${runner_bin}.new" "$runner_bin"
|
|
[[ ! -f /usr/local/bin/act_runner ]] && ln -sf "$runner_bin" /usr/local/bin/act_runner
|
|
[[ ! -f /usr/local/bin/gitea-runner ]] && ln -sf "$runner_bin" /usr/local/bin/gitea-runner
|
|
|
|
systemctl start gitea-runner 2>/dev/null || systemctl start act_runner 2>/dev/null || true
|
|
msg_ok "Updated Gitea Runner to v${latest_version}"
|
|
else
|
|
msg_warn "Could not resolve release download URL for architecture: linux-$arch"
|
|
fi
|
|
else
|
|
msg_ok "Gitea Runner is up to date (v${clean_current})"
|
|
fi
|
|
else
|
|
msg_warn "Could not reach Gitea API to check for updates"
|
|
fi
|
|
|
|
msg_ok "Updated successfully!"
|
|
}
|
|
|
|
update_alpine() {
|
|
msg_info "Updating Alpine packages"
|
|
$STD apk -U upgrade
|
|
msg_ok "Updated Alpine packages"
|
|
|
|
if command -v docker &>/dev/null; then
|
|
msg_info "Updating Docker"
|
|
$STD apk add --upgrade docker
|
|
msg_ok "Docker updated"
|
|
fi
|
|
|
|
msg_info "Checking for Gitea Runner updates"
|
|
local runner_bin
|
|
if [[ -f /usr/local/bin/gitea-runner ]]; then
|
|
runner_bin="/usr/local/bin/gitea-runner"
|
|
else
|
|
runner_bin="/usr/local/bin/act_runner"
|
|
fi
|
|
|
|
local current_version
|
|
current_version=$("$runner_bin" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || echo "0.0.0")
|
|
|
|
local release_json
|
|
release_json=$(curl -fsSL --connect-timeout 10 "https://gitea.com/api/v1/repos/gitea/act_runner/releases/latest" 2>/dev/null || true)
|
|
if [[ -z "$release_json" ]]; then
|
|
release_json=$(curl -fsSL --connect-timeout 10 "https://gitea.com/api/v1/repos/gitea/runner/releases/latest" 2>/dev/null || true)
|
|
fi
|
|
|
|
if [[ -n "$release_json" ]]; then
|
|
local latest_version
|
|
latest_version=$(echo "$release_json" | jq -r '.tag_name // empty' | tr -d 'v')
|
|
local clean_current="${current_version#v}"
|
|
|
|
if [[ -n "$latest_version" && "$latest_version" != "$clean_current" ]]; then
|
|
msg_info "Updating Gitea Runner (${clean_current} -> ${latest_version})"
|
|
local arch
|
|
case "$(uname -m)" in
|
|
x86_64) arch="amd64" ;;
|
|
aarch64|arm64) arch="arm64" ;;
|
|
armv7l) arch="arm-7" ;;
|
|
*) arch="amd64" ;;
|
|
esac
|
|
|
|
local dl_url
|
|
dl_url=$(echo "$release_json" | jq -r --arg a "linux-$arch" '.assets[] | select(.name | endswith($a)) | .browser_download_url' | head -1)
|
|
|
|
if [[ -n "$dl_url" && "$dl_url" != "null" ]]; then
|
|
rc-service gitea-runner stop 2>/dev/null || true
|
|
curl -fsSL "$dl_url" -o "${runner_bin}.new"
|
|
chmod +x "${runner_bin}.new"
|
|
mv "${runner_bin}.new" "$runner_bin"
|
|
[[ ! -f /usr/local/bin/act_runner ]] && ln -sf "$runner_bin" /usr/local/bin/act_runner
|
|
[[ ! -f /usr/local/bin/gitea-runner ]] && ln -sf "$runner_bin" /usr/local/bin/gitea-runner
|
|
|
|
rc-service gitea-runner start 2>/dev/null || true
|
|
msg_ok "Updated Gitea Runner to v${latest_version}"
|
|
else
|
|
msg_warn "Could not resolve release download URL for architecture: linux-$arch"
|
|
fi
|
|
else
|
|
msg_ok "Gitea Runner is up to date (v${clean_current})"
|
|
fi
|
|
else
|
|
msg_warn "Could not reach Gitea API to check for updates"
|
|
fi
|
|
|
|
msg_ok "Updated successfully!"
|
|
}
|
|
|
|
function update_script() {
|
|
header_info
|
|
check_container_storage
|
|
check_container_resources
|
|
run_os_update
|
|
}
|
|
|
|
start
|
|
build_container
|
|
description
|
|
|
|
msg_ok "Completed successfully!\n"
|
|
echo -e "${CREATING}${GN}${APP} LXC container has been successfully created!${CL}"
|
|
echo -e "${INFO}${YW}Container IP: ${GN}${IP}${CL}\n"
|
|
echo -e "${TAB}To register the runner with your Gitea instance:"
|
|
echo -e "${TAB}${TAB}${GN}pct exec ${CTID} -- gitea-runner-register${CL}"
|
|
echo -e "${TAB}Or open the container console and execute:"
|
|
echo -e "${TAB}${TAB}${GN}gitea-runner-register${CL}\n"
|