#!/usr/bin/env bash set -euo pipefail if [[ $EUID -ne 0 || $# -gt 1 || ( $# -eq 1 && $1 != status ) ]]; then echo "This fixed receiver is owner-run as root and accepts its request only on stdin." >&2 exit 1 fi helper=/usr/local/lib/akyldash/gitea-api token_file=/etc/akyldash/gitea-api-token origins_file=/etc/akyldash/gitea-download-origins if [[ -L $helper || ! -x $helper || $(stat -c %U:%a "$helper") != root:750 ]]; then echo "The reviewed root-owned Gitea helper is not installed." >&2 exit 1 fi if [[ -L $token_file || ! -f $token_file || $(stat -c %U:%a "$token_file") != root:600 ]]; then echo "A root-owned mode-0600 read-only Gitea API token file is required." >&2 exit 1 fi GITEA_TOKEN=$(< "$token_file") if [[ ! $GITEA_TOKEN =~ ^[A-Za-z0-9_-]+$ ]]; then echo "The Gitea API token file is empty or has an invalid format." >&2 exit 1 fi GITEA_DOWNLOAD_ORIGINS= if [[ -e $origins_file || -L $origins_file ]]; then if [[ -L $origins_file || ! -f $origins_file || $(stat -c %U:%a "$origins_file") != root:600 ]]; then echo "Gitea artifact redirect origins must be a root-owned mode-0600 file." >&2 exit 1 fi while IFS= read -r origin || [[ -n $origin ]]; do [[ -z $origin ]] && continue if [[ ! $origin =~ ^https://[A-Za-z0-9.-]+(:[0-9]+)?$ ]]; then echo "Gitea artifact redirect origin configuration is invalid." >&2 exit 1 fi if [[ -n $GITEA_DOWNLOAD_ORIGINS ]]; then GITEA_DOWNLOAD_ORIGINS+=, fi GITEA_DOWNLOAD_ORIGINS+=$origin done < "$origins_file" fi export GITEA_URL=https://git.vakanaut.ru export GITEA_TOKEN GITEA_DOWNLOAD_ORIGINS export PATH=/usr/local/lib/akyldash:/usr/bin:/bin if [[ $# -eq 1 ]]; then exec /usr/bin/python3 /usr/local/lib/akyldash/external_status.py fi exec /usr/bin/python3 /usr/local/lib/akyldash/external_deploy.py