diff options
Diffstat (limited to 'dscip')
-rwxr-xr-x | dscip | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/dscip b/dscip new file mode 100755 index 0000000..8b4eb94 --- /dev/null +++ b/dscip @@ -0,0 +1,75 @@ +#!/bin/sh +set -e +# Variables that control the program. # +# GIT Repo # +DSCIP_GITREPO="https://www.example.com/example/example.git" +# GIT MODE: # +# pull: Doesn't delete previous clone and just pulls changes. # +# clone: Deletes previous clone, and creates a fresh clone. # +DSCIP_GITMODE="clone" +# Branch to check # +DSCIP_BRANCH="master" +WORKING_DIRECTORY="/tmp/example" +# Commands to run before building. # +DSCIP_PRE_CMD="$WORKING_DIRECTORY/pre.sh" +# Commands to run to build program. # +DSCIP_BUILD_CMD="$WORKING_DIRECTORY/build.sh" +# Commands to run after building is done. # +DSCIP_POST_CMD="$WORKING_DIRECTORY/post.sh" +# Daemon mode options # +DSCIP_DAEMON="false" +DSCIP_SLEEP="60" # How many seconds before the daemon re-runs itself. # + +################################################################################ + +build () { + if [ "$DSCIP_GITMODE" = "clone" ]; then + rm -rf "$WORKING_DIRECTORY/wrkdir" # Clean Up # + git clone -b $DSCIP_BRANCH $DSCIP_GITREPO wrkdir # Clone git # + elif [ "$DSCIP_GITMODE" = "pull" ]; then + if [ ! -d "$WORKING_DIRECTORY/wrkdir" ]; then + git clone -b $DSCIP_BRANCH $DSCIP_GITREPO wrkdir + fi + cd wrkdir + git pull + else + echo "Invalid GITMODE, choose either 'clone' or 'pull'" + exit 1 + fi + cd $WORKING_DIRECTORY/wrkdir + $DSCIP_PRE_CMD + cd $WORKING_DIRECTORY/wrkdir + $DSCIP_BUILD_CMD + cd $WORKING_DIRECTORY/wrkdir + $DSCIP_POST_CMD + mkdir -p $WORKING_DIRECTORY/meta + echo "$CURRENT_COMMIT" > $WORKING_DIRECTORY/meta/LAST_COMMIT # Save commit # +} + +run () { + mkdir -p $WORKING_DIRECTORY + cd $WORKING_DIRECTORY + + # Loads last commit hash if it exists. # + if [ -f "$WORKING_DIRECTORY/meta/LAST_COMMIT" ]; then + LAST_COMMIT="$(cat $WORKING_DIRECTORY/meta/LAST_COMMIT)" + fi + + # Loads current commit hash # + CURRENT_COMMIT=$(git ls-remote $DSCIP_GITREPO | awk "/refs\/(heads|tags)\/$DSCIP_BRANCH/{print \$1}") + + # If LAST_COMMIT doesn't exist, that means it's a first run and we can go ahead and build. # + if [ -z "$LAST_COMMIT" ]; then + build + elif [ ! "$LAST_COMMIT" = "$CURRENT_COMMIT" ]; then # If the last commit and current commit don't match, then we go ahead and build. + build + fi +} + +run +while [ "$DSCIP_DAEMON" = "true" ]; do + sleep $DSCIP_SLEEP + run +done + +exit 0 |