Fix missing sudo command for new clone ssh test

This commit is contained in:
2025-07-04 13:52:16 +09:00
parent 221d1b3d35
commit d60ed41100
2 changed files with 6 additions and 3 deletions

View File

@@ -22,10 +22,12 @@ if [ -z "$(command -v git)" ]; then
error=1;
fi;
GIT_COMMAND_BASE=("git");
SUDO_COMMAND=()
if [ -n "${USE_SUDO}" ]; then
# if we are root -> ok, else we must be SUDO USER
if [ "$(whoami)" = "root" ]; then
GIT_COMMAND_BASE=("sudo" "-u" "${SUDO_USER}" "git");
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;

View File

@@ -44,7 +44,8 @@ if ! grep "Host ${REMOTE_HOST}" "${GIT_WEBHOOK_BASE_FOLDER}"/.ssh/config; then
else
# make sure the identiy file is there
# grep "IdentityFile" in this
result=$(ssh "${REMOTE_HOST}");
SSH_TEST=("${SUDO_COMMAND[@]}" "ssh" "${REMOTE_HOST}");
result=$("${SSH_TEST[@]}");
validate_string="You've successfully authenticated with the key"
if [[ "$result" != *"$validate_string"* ]]; then
echo "Could not connect to ${REMOTE_HOST}: ${result}";
@@ -62,6 +63,6 @@ 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_NAME}" "${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}";
# "${GIT_COMMAND[@]}";
# __END__