Basic script check in
This is not completed and under development
This commit is contained in:
10
ReadMe.md
Normal file
10
ReadMe.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Github webhook scripts
|
||||||
|
|
||||||
|
These are scripts to setup the basic webhook folder for one campaign and a simple crontab script to pull data from the repository
|
||||||
|
|
||||||
|
This will not do the basic setup, this only sets up a new folder with a basic clone run
|
||||||
|
|
||||||
|
## Scripts
|
||||||
|
|
||||||
|
- git_pull.sh
|
||||||
|
- init_new_clone.sh
|
||||||
2
bin/.shellcheckrc
Normal file
2
bin/.shellcheckrc
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
shell=bash
|
||||||
|
external-sources=true
|
||||||
33
bin/git_pull.sh
Executable file
33
bin/git_pull.sh
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# fetch and merge from a remote repositry
|
||||||
|
|
||||||
|
REPOSITORY="$1";
|
||||||
|
BRANCH="$2";
|
||||||
|
REMOTE="$3";
|
||||||
|
if [ -n "${REMOTE}" ]; then
|
||||||
|
REMOTE="origin"
|
||||||
|
fi;
|
||||||
|
# BASE_FOLDER="${HOME}/tmp/git-clone/";
|
||||||
|
BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
|
||||||
|
# shellcheck source=init.sh
|
||||||
|
. "${BASE_FOLDER}init.sh";
|
||||||
|
|
||||||
|
# check that repository path exists
|
||||||
|
REPOSITORY_PATH="${GIT_REPOSITORY_FOLDER}${CLONE_BASE}${REPOSITORY}";
|
||||||
|
if [ ! -d "${REPOSITORY_PATH}$" ]; then
|
||||||
|
echo "${REPOSITORY} not found in clone folder";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
|
LOG_FILE="${GIT_REPOSITORY_FOLDER}${LOG_FOLDER}${REPOSITORY}.log";
|
||||||
|
|
||||||
|
# fetch to null
|
||||||
|
${GIT_COMMAND} -C "${REPOSITORY_PATH}" fetch -q "${REMOTE}" "${BRANCH}";
|
||||||
|
changes=$(${GIT_COMMAND} -C "${REPOSITORY_PATH}" diff --stat HEAD "${REMOTE}"/"${BRANCH}");
|
||||||
|
if [ -n "${changes}" ]; then
|
||||||
|
echo "[$(date +"%Y-%m-%d %H:%M:%S")] Changes" &>> "$LOG_FILE";
|
||||||
|
${GIT_COMMAND} -C "/${REPOSITORY_PATH}" merge "${REMOTE}"/"${BRANCH}"
|
||||||
|
echo "=[END]===>" &>> "$LOG_FILE";
|
||||||
|
fi;
|
||||||
|
|
||||||
|
# __END__
|
||||||
50
bin/init.sh
Normal file
50
bin/init.sh
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
CONFIG_BASE="${BASE_FOLDER}../config/";
|
||||||
|
echo "CONFIG: ${CONFIG_BASE} ";
|
||||||
|
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;
|
||||||
|
if [ "${USE_SUDO}" != "0" ] && ! id "${SUDO_USER}" &>/dev/null; then
|
||||||
|
echo "sudo user ${SUDO_USER} does not exist";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
|
# check that user exist
|
||||||
|
# check that git exists
|
||||||
|
if [ -z "$(command -v git)" ]; then
|
||||||
|
echo "git is not installed";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
|
GIT_COMMAND="git";
|
||||||
|
if [ -n "${USE_SUDO}" ]; then
|
||||||
|
GIT_COMMAND="sudo -u ${SUDO_USER} git";
|
||||||
|
fi;
|
||||||
|
|
||||||
|
# branch name not set
|
||||||
|
if [ -n "${BRANCH}" ]; then
|
||||||
|
echo "No branch name given";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
# base folder does not exist
|
||||||
|
if [ ! -d "${GIT_REPOSITORY_FOLDER}" ]; then
|
||||||
|
echo "Base folder: ${GIT_REPOSITORY_FOLDER} not found";
|
||||||
|
exit;
|
||||||
|
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;
|
||||||
|
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}";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
export GIT_COMMAND;
|
||||||
|
|
||||||
23
bin/new_clone.sh
Executable file
23
bin/new_clone.sh
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
REPOSITORY="$1";
|
||||||
|
BRANCH="$2";
|
||||||
|
REMOTE_HOST="$3";
|
||||||
|
REMOTE="$4";
|
||||||
|
if [ -n "${REMOTE}" ]; then
|
||||||
|
REMOTE="origin"
|
||||||
|
fi;
|
||||||
|
BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
|
||||||
|
# shellcheck source=init.sh
|
||||||
|
. "${BASE_FOLDER}init.sh";
|
||||||
|
|
||||||
|
if [ -z "${REMOTE_HOST}" ]; then
|
||||||
|
echo "Must set a remote host for the repository";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
echo "New clone";
|
||||||
|
|
||||||
|
echo ${GIT_COMMAND} clone -b "${BRANCH}" --single-branch --depth 1 --origin "${REMOTE}" "${REMOTE_HOST}:${REPOSITORY}" "${GIT_REPOSITORY_FOLDER}${CLONE_BASE}";
|
||||||
|
|
||||||
|
# __END__
|
||||||
2
config/.gitignore
vendored
Normal file
2
config/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
Reference in New Issue
Block a user