Make sure correct user runs the scripts
This commit is contained in:
@@ -33,6 +33,11 @@ elif [ "${USE_SUDO}" = "0" ] && ! id "${SUDO_USER}" &>/dev/null; then
|
||||
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";
|
||||
error=1;
|
||||
fi;
|
||||
|
||||
if [ $error -eq 1 ]; then
|
||||
exit;
|
||||
@@ -94,7 +99,8 @@ Host UdonGitJump
|
||||
Port 37337
|
||||
EOF
|
||||
if [ -f "${PEM_BASE}${JUMP_PEM_FILE}" ]; then
|
||||
cp "${PEM_BASE}${JUMP_PEM_FILE}" "${GIT_REPOSITORY_FOLDER}"/.ssh/;
|
||||
sudo -u "${SUDO_USER}" cp "${PEM_BASE}${JUMP_PEM_FILE}" "${GIT_REPOSITORY_FOLDER}"/.ssh/;
|
||||
sudo -u "${SUDO_USER}" chmod 600 "${GIT_REPOSITORY_FOLDER}/.ssh/${JUMP_PEM_FILE}"
|
||||
else
|
||||
echo "PEM FILE ${JUMP_PEM_FILE} must be added manually"
|
||||
fi;
|
||||
@@ -110,7 +116,7 @@ EOF
|
||||
"${GIT_REPOSITORY_FOLDER}${WWW_WEBHOOK_INCOMING}" \
|
||||
"${GIT_REPOSITORY_FOLDER}${WWW_ADMIN}";
|
||||
# set basic folder rights, clone folder is excluded
|
||||
chmod 700 \
|
||||
sudo -u "${SUDO_USER}" chmod 700 \
|
||||
"${GIT_REPOSITORY_FOLDER}${LOG_FOLDER}" \
|
||||
"${GIT_REPOSITORY_FOLDER}${SCRIPT_FOLDER}" \
|
||||
"${GIT_REPOSITORY_FOLDER}${CONFIG_FOLDER}" \
|
||||
@@ -124,8 +130,8 @@ EOF
|
||||
# Copy files
|
||||
echo "+ Copy basic script and config files";
|
||||
# git_pull.sh, init.sh, new_clone.sh, webhook.default.cfg
|
||||
cp "${BASE_FOLDER}new_clone.sh" "${BASE_FOLDER}init.sh" "${BASE_FOLDER}git_clone.sh" "${GIT_REPOSITORY_FOLDER}${SCRIPT_FOLDER}";
|
||||
cp "${CONFIG_BASE}/webhook.default.cfg" "${GIT_REPOSITORY_FOLDER}${CONFIG_FOLDER}";
|
||||
sudo -u "${SUDO_USER}"cp "${BASE_FOLDER}new_clone.sh" "${BASE_FOLDER}init.sh" "${BASE_FOLDER}git_clone.sh" "${GIT_REPOSITORY_FOLDER}${SCRIPT_FOLDER}";
|
||||
sudo -u "${SUDO_USER}"cp "${CONFIG_BASE}/webhook.default.cfg" "${GIT_REPOSITORY_FOLDER}${CONFIG_FOLDER}";
|
||||
fi;
|
||||
|
||||
# __END__
|
||||
|
||||
@@ -10,19 +10,26 @@ if [ -f "${CONFIG_BASE}webhook.cfg" ]; then
|
||||
# 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";
|
||||
exit;
|
||||
error=1;
|
||||
fi;
|
||||
# check that user exist
|
||||
# check that git exists
|
||||
if [ -z "$(command -v git)" ]; then
|
||||
echo "git is not installed";
|
||||
exit;
|
||||
error=1;
|
||||
fi;
|
||||
GIT_COMMAND_BASE=("git");
|
||||
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");.
|
||||
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
|
||||
@@ -33,24 +40,29 @@ LOG_FOLDER="log/"
|
||||
# base folder does not exist
|
||||
if [ ! -d "${GIT_REPOSITORY_FOLDER}" ]; then
|
||||
echo "Base folder: ${GIT_REPOSITORY_FOLDER} not found";
|
||||
exit;
|
||||
error=1;
|
||||
fi;
|
||||
|
||||
# branch name not set
|
||||
if [ -n "${BRANCH}" ]; then
|
||||
echo "No branch name given";
|
||||
exit;
|
||||
error=1;
|
||||
fi;
|
||||
|
||||
# check that log folder exists
|
||||
if [ ! -d "${GIT_REPOSITORY_FOLDER}${LOG_FOLDER}" ]; then
|
||||
echo "Log folder does not exist: ${GIT_REPOSITORY_FOLDER}${LOG_FOLDER}";
|
||||
exit;
|
||||
error=1;
|
||||
fi;
|
||||
|
||||
# check that the base clone folder exists
|
||||
if [ ! -d "${GIT_REPOSITORY_FOLDER}${CLONE_BASE}" ]; then
|
||||
echo "Clone base folder does not exist: ${GIT_REPOSITORY_FOLDER}${CLONE_BASE}";
|
||||
error=1;
|
||||
fi;
|
||||
|
||||
# exit on error
|
||||
if [ $error -eq 1 ]; then
|
||||
exit;
|
||||
fi;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user