addet forgejo-runner installation script
This commit is contained in:
parent
14afc57f44
commit
5c73a27e26
1 changed files with 160 additions and 0 deletions
160
installs/forgejo-runner.sh
Executable file
160
installs/forgejo-runner.sh
Executable file
|
@ -0,0 +1,160 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# ─< ANSI color codes >───────────────────────────────────────────────────────────────────
|
||||||
|
RED='\033[0;31m'
|
||||||
|
CYAN='\033[0;36m'
|
||||||
|
YELLOW='\033[0;33m'
|
||||||
|
LIGHT_GREEN='\033[0;92m'
|
||||||
|
BOLD='\033[1m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
# ─< Initialize storage variables >───────────────────────────────────────────────────────
|
||||||
|
_STORED_ERRORS=""
|
||||||
|
_STORED_WARNINGS=""
|
||||||
|
_STORED_INFOS=""
|
||||||
|
_STORED_NOTES=""
|
||||||
|
|
||||||
|
# ─< echo functions that store and display messages >────────────────────────────
|
||||||
|
echo_error() {
|
||||||
|
local message="${RED}$1${NC}\n"
|
||||||
|
printf "$message" >&2
|
||||||
|
_STORED_ERRORS="${_STORED_ERRORS}${message}"
|
||||||
|
}
|
||||||
|
|
||||||
|
echo_warning() {
|
||||||
|
local message="${YELLOW}$1${NC}\n"
|
||||||
|
printf "$message"
|
||||||
|
_STORED_WARNINGS="${_STORED_WARNINGS}${message}"
|
||||||
|
}
|
||||||
|
|
||||||
|
echo_info() {
|
||||||
|
local message="${CYAN}$1${NC}\n"
|
||||||
|
printf "$message"
|
||||||
|
_STORED_INFOS="${_STORED_INFOS}${message}"
|
||||||
|
}
|
||||||
|
|
||||||
|
echo_note() {
|
||||||
|
local message="${LIGHT_GREEN}$1${NC}\n"
|
||||||
|
printf "$message"
|
||||||
|
_STORED_NOTES="${_STORED_NOTES}${message}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ─< Improved display function that only shows categories with content >──────────────────
|
||||||
|
display_stored_messages() {
|
||||||
|
local has_messages=0
|
||||||
|
|
||||||
|
# ─< First check if we have any messages at all >─────────────────────────────────────────
|
||||||
|
if [ -z "$_STORED_ERRORS" ] && [ -z "$_STORED_WARNINGS" ] && [ -z "$_STORED_INFOS" ] && [ -z "$_STORED_NOTES" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ─< Now display each non-empty category with proper spacing >────────────────────────────
|
||||||
|
if [ -n "$_STORED_ERRORS" ]; then
|
||||||
|
printf "\n${BOLD}${RED}=== Errors ===${NC}\n"
|
||||||
|
printf "$_STORED_ERRORS"
|
||||||
|
has_messages=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$_STORED_WARNINGS" ]; then
|
||||||
|
[ "$has_messages" -eq 1 ] && printf "\n"
|
||||||
|
printf "${BOLD}${YELLOW}=== Warnings ===${NC}\n"
|
||||||
|
printf "$_STORED_WARNINGS"
|
||||||
|
has_messages=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$_STORED_INFOS" ]; then
|
||||||
|
[ "$has_messages" -eq 1 ] && printf "\n"
|
||||||
|
printf "${BOLD}${CYAN}=== Info ===${NC}\n"
|
||||||
|
printf "$_STORED_INFOS"
|
||||||
|
has_messages=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$_STORED_NOTES" ]; then
|
||||||
|
[ "$has_messages" -eq 1 ] && printf "\n"
|
||||||
|
printf "${BOLD}${LIGHT_GREEN}=== Notes ===${NC}\n"
|
||||||
|
printf "$_STORED_NOTES"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_exit() {
|
||||||
|
display_stored_messages
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
||||||
|
command_exists() {
|
||||||
|
command -v "$@" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# ─< Check if the user is root and set sudo variable if necessary >───────────────────────
|
||||||
|
check_root() {
|
||||||
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
if command_exists sudo; then
|
||||||
|
echo_info "User is not root. Using sudo for privileged operations."
|
||||||
|
_sudo="sudo"
|
||||||
|
else
|
||||||
|
echo_error "No sudo found and you're not root! Can't install packages."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo_info "Root access confirmed."
|
||||||
|
_sudo=""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
getRunner() {
|
||||||
|
# ╭─────────────────────────────────────────────────────────╮
|
||||||
|
# │ should output something like this │
|
||||||
|
# │ ╭─────────────────────────────────────────────────────╮ │
|
||||||
|
# │ │ Good signature from "Forgejo <contact@forgejo.org>" │ │
|
||||||
|
# │ │ aka "Forgejo Releases <release@forgejo.org>" │ │
|
||||||
|
# │ ╰─────────────────────────────────────────────────────╯ │
|
||||||
|
# ╰─────────────────────────────────────────────────────────╯
|
||||||
|
#
|
||||||
|
# ─< get the runner version >─────────────────────────────────────────────────────────────
|
||||||
|
export RUNNER_VERSION=$(curl -X 'GET' https://data.forgejo.org/api/v1/repos/forgejo/runner/releases/latest | jq .name -r | cut -c 2-)
|
||||||
|
# ─< get the runner binary >──────────────────────────────────────────────────────────────
|
||||||
|
wget -O forgejo-runner https://code.forgejo.org/forgejo/runner/releases/download/v${RUNNER_VERSION}/forgejo-runner-${RUNNER_VERSION}-linux-amd64
|
||||||
|
# ─< make it executable >─────────────────────────────────────────────────────────────────
|
||||||
|
chmod +x forgejo-runner
|
||||||
|
# ─< get the verification hashes >────────────────────────────────────────────────────────
|
||||||
|
wget -O forgejo-runner.asc https://code.forgejo.org/forgejo/runner/releases/download/v${RUNNER_VERSION}/forgejo-runner-${RUNNER_VERSION}-linux-amd64.asc
|
||||||
|
gpg --keyserver keys.openpgp.org --recv EB114F5E6C0DC2BCDD183550A4B61A2DC5923710
|
||||||
|
gpg --verify forgejo-runner.asc forgejo-runner
|
||||||
|
}
|
||||||
|
|
||||||
|
userCreation() {
|
||||||
|
$_sudo useradd --create-home runner
|
||||||
|
$_sudo usermod -aG docker runner
|
||||||
|
}
|
||||||
|
|
||||||
|
envCheck() {
|
||||||
|
if ! command_exists curl; then
|
||||||
|
echo_error "You have no curl installed"
|
||||||
|
_exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command_exists wget; then
|
||||||
|
echo_error "You have no wget installed"
|
||||||
|
_exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command_exists docker; then
|
||||||
|
echo_warning "Sorry, you have no docker installed.."
|
||||||
|
_exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command_exists forgejo-runner; then
|
||||||
|
echo_warning "forgejo-runner binary is already callable.."
|
||||||
|
_exit
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if envCheck; then
|
||||||
|
getRunner
|
||||||
|
if ! grep -iq "runner" /etc/passwd; then
|
||||||
|
userCreation
|
||||||
|
fi
|
||||||
|
|
||||||
|
forgejo-runner generate-config >config.yml && $_sudo rsync -avP config.yml /home/runner/config.yml
|
||||||
|
fi
|
Loading…
Add table
Add a link
Reference in a new issue