57 lines
2.1 KiB
Bash
57 lines
2.1 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# AUTHOR: Clemens Schwaighofer
|
|
# DATE: 2025/7/4
|
|
# DESC: Initial setup of the webhook clone folder structure
|
|
|
|
BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
|
|
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;
|
|
|
|
# Define base folders
|
|
CLONE_BASE="clone-base/"
|
|
LOG_FOLDER="log/"
|
|
SCRIPT_FOLDER="scripts/"
|
|
WWW_WEBHOOK_INCOMING="/www/webhook-incoming";
|
|
WWW_ADMIN="/www/admin";
|
|
|
|
# add trailing slash if missing
|
|
GIT_REPOSITORY_FOLDER="${GIT_REPOSITORY_FOLDER%/}/"
|
|
|
|
if [ -d "${GIT_REPOSITORY_FOLDER}" ]; then
|
|
echo "Base folder already exists, update check";
|
|
exit;
|
|
else
|
|
echo "=> Create new folder structure";
|
|
echo "+ Add user ${WWW_GROUP}:${SUDO_USER} with base folder ${GIT_REPOSITORY_FOLDER}";
|
|
# User for sudo
|
|
useradd -d "${GIT_REPOSITORY_FOLDER}" -m -s /usr/sbin/nologin -G "${WWW_GROUP}" "${SUDO_USER}"
|
|
setfacl -m u:"${SUDO_USER}":rwx -R "${GIT_REPOSITORY_FOLDER}"
|
|
setfacl -m g:"${WWW_GROUP}":r.x -R "${GIT_REPOSITORY_FOLDER}"
|
|
# SSH
|
|
echo "+ Add .ssh folder"
|
|
sudo -u "${SUDO_USER}" mkdir "${GIT_REPOSITORY_FOLDER}"/.ssh/
|
|
sudo -u "${SUDO_USER}" touch "${GIT_REPOSITORY_FOLDER}"/.ssh/config
|
|
sudo -u "${SUDO_USER}" chmod 700 "${GIT_REPOSITORY_FOLDER}"/.ssh/
|
|
sudo -u "${SUDO_USER}" chmod 600 "${GIT_REPOSITORY_FOLDER}"/.ssh/config
|
|
# All other FOLDER
|
|
echo "+ Other folders for clone base: ${CLONE_BASE}, logs, scripts, www/webhook-incoming"
|
|
sudo -u "${SUDO_USER}" \
|
|
mkdir -p \
|
|
"${GIT_REPOSITORY_FOLDER}${CLONE_BASE}" \
|
|
"${GIT_REPOSITORY_FOLDER}${LOG_FOLDER}" \
|
|
"${GIT_REPOSITORY_FOLDER}${SCRIPT_FOLDER}" \
|
|
"${GIT_REPOSITORY_FOLDER}${WWW_WEBHOOK_INCOMING}" \
|
|
"${GIT_REPOSITORY_FOLDER}${WWW_ADMIN}";
|
|
setfacl -m u:"${SUDO_USER}":rwx -R "${GIT_REPOSITORY_FOLDER}${CLONE_BASE}"
|
|
setfacl -d -m u:"${SUDO_USER}":rwx -R "${GIT_REPOSITORY_FOLDER}${CLONE_BASE}"
|
|
setfacl -m g:"${WWW_GROUP}":rwx -R "${GIT_REPOSITORY_FOLDER}${CLONE_BASE}"
|
|
setfacl -d -m g:"${WWW_GROUP}":rwx -R "${GIT_REPOSITORY_FOLDER}${CLONE_BASE}"
|
|
fi;
|
|
|
|
# __END__
|