Mark error messages better, update new clone script

This commit is contained in:
2025-07-04 13:26:54 +09:00
parent 6e89841a15
commit c80a4a9c17
3 changed files with 29 additions and 11 deletions

View File

@@ -16,26 +16,26 @@ fi;
error=0;
if [ -z "${GIT_WEBHOOK_BASE_FOLDER}" ]; then
echo "Missing GIT_WEBHOOK_BASE_FOLDER entry";
echo "[!] Missing GIT_WEBHOOK_BASE_FOLDER entry";
error=1;
fi;
if [ -z "${WWW_GROUP}" ]; then
echo "Missing WWW_GROUP entry";
echo "[!] Missing WWW_GROUP entry";
error=1;
elif ! getent group "${WWW_GROUP}" > /dev/null 2>&1; then
echo "Group ${WWW_GROUP} does not exist. Is it the Apache web group?";
echo "[!] Group ${WWW_GROUP} does not exist. Is it the Apache web group?";
error=1;
fi;
if [ -z "${SUDO_USER}" ]; then
echo "Missing SUDO_USER entry";
echo "[!] Missing SUDO_USER entry";
error=1;
elif [ "${USE_SUDO}" = "0" ] && ! id "${SUDO_USER}" &>/dev/null; then
echo "SUDO is off, user must exist in system";
echo "[!] SUDO is off, user must exist in system";
error=1;
fi;
# this script has to be run as root
if [ "$(whoami)" != "root" ]; then
echo "Script must be run as root user";
echo "[!] Script must be run as root user";
error=1;
fi;

View File

@@ -17,7 +17,7 @@ BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
# check that repository path exists
REPOSITORY_PATH="${GIT_WEBHOOK_BASE_FOLDER}${CLONE_BASE}${REPOSITORY}";
if [ ! -d "${REPOSITORY_PATH}$" ]; then
echo "${REPOSITORY} not found in clone folder";
echo "[!] ${REPOSITORY} not found in clone folder";
exit;
fi;
LOG_FILE="${GIT_WEBHOOK_BASE_FOLDER}${LOG_FOLDER}${REPOSITORY}.log";

View File

@@ -16,16 +16,34 @@ BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
. "${BASE_FOLDER}init.sh";
if [ -z "${REMOTE_HOST}" ]; then
echo "Must set a remote host for the repository";
echo "[!] Must set a remote host for the repository";
exit;
fi;
error=0
echo "* Validate SSH PEM Key exist and SSH config";
# grep "Host ${REMOTE}"
# grep "IdentityFile" in this
if ! grep "Host ${REMOTE}" "${GIT_WEBHOOK_BASE_FOLDER}"/.ssh/config; then
echo "ssh config entry for Host ${REMOTE} is missing";
error=1;
else
# make sure the identiy file is there
# grep "IdentityFile" in this
result=$(ssh "${REMOTE_HOST}");
validate_string="You've successfully authenticated with the key"
if [[ "$result" != *"$validate_string"* ]]; then
echo "Could not connect to ${REMOTE_HOST}: ${result}";
error=1;
fi;
fi;
echo "New clone";
if [ $error -eq 1 ]; then
exit;
fi;
# from the repository get the last path without the .git so we have the target folder
GIT_REPOSITORY_FOLDER=$(basename "${REPOSITORY}" .git);
echo "* New clone from ${REMOTE_HOST}:${REPOSITORY}/${BRANCH} into ${GIT_REPOSITORY_FOLDER}";
GIT_COMMAND=("${GIT_COMMAND_BASE[@]}" "clone" "-b" "${BRANCH}" "--single-branch" "--depth" "1" "--origin" "${REMOTE}" "${REMOTE_HOST}:${REPOSITORY}" "${GIT_WEBHOOK_BASE_FOLDER}${CLONE_BASE}")
echo "Command: ${GIT_COMMAND[*]}"
# echo ${GIT_COMMAND_BASE} clone -b "${BRANCH}" --single-branch --depth 1 --origin "${REMOTE}" "${REMOTE_HOST}:${REPOSITORY}" "${GIT_WEBHOOK_BASE_FOLDER}${CLONE_BASE}";