#!/usr/bin/env bash # AUTHOR: Clemens Schwaighofer # DATE: 2025/6/27 # DESC: Setup basic variables CONFIG_BASE="${BASE_FOLDER}../config/"; if [ -f "${CONFIG_BASE}webhook.cfg" ]; then # shellcheck source=../config/webhook.cfg" # shellcheck disable=SC1091 source <(grep "=" "${CONFIG_BASE}webhook.cfg" | sed 's/ *= */=/g') fi; error=0; if [ "${USE_SUDO}" != "0" ] && ! id "${SUDO_USER}" &>/dev/null; then echo "[!] sudo user ${SUDO_USER} does not exist"; error=1; fi; # check that user exist # check that git exists if [ -z "$(command -v git)" ]; then echo "[!] git is not installed"; error=1; fi; GIT_COMMAND_BASE=("git"); SUDO_COMMAND=() if [ "${USE_SUDO}" == 1 ]; then # if we are root -> ok, else we must be SUDO USER if [ "$(whoami)" = "root" ]; then SUDO_COMMAND=("sudo" "-u" "${SUDO_USER}"); GIT_COMMAND_BASE=("${SUDO_COMMAND[@]}" "git"); elif [ "$(whoami)" != "${SUDO_USER}" ]; then echo "[!] Script must be run as root or as the ${SUDO_USER}"; error=1; fi; fi; # add trailing slash if not set GIT_WEBHOOK_BASE_FOLDER="${GIT_WEBHOOK_BASE_FOLDER%/}/" CLONE_BASE="clone-base/" LOG_FOLDER="log/" # base folder does not exist if [ ! -d "${GIT_WEBHOOK_BASE_FOLDER}" ]; then echo "[!] Base folder: ${GIT_WEBHOOK_BASE_FOLDER} not found"; error=1; fi; # branch name not set if [ -z "${BRANCH}" ]; then echo "[!] No branch name given"; error=1; fi; # check that log folder exists if [ ! -d "${GIT_WEBHOOK_BASE_FOLDER}${LOG_FOLDER}" ]; then echo "[!] Log folder does not exist: ${GIT_WEBHOOK_BASE_FOLDER}${LOG_FOLDER}"; error=1; fi; # check that the base clone folder exists if [ ! -d "${GIT_WEBHOOK_BASE_FOLDER}${CLONE_BASE}" ]; then echo "[!] Clone base folder does not exist: ${GIT_WEBHOOK_BASE_FOLDER}${CLONE_BASE}"; error=1; fi; # exit on error if [ $error -eq 1 ]; then exit; fi; export GIT_COMMAND_BASE;