diff options
Diffstat (limited to 'dscip')
-rwxr-xr-x | dscip | 68 |
1 files changed, 46 insertions, 22 deletions
diff --git a/dscip b/dscip index 8d8b33c..db7726e 100755 --- a/dscip +++ b/dscip @@ -17,53 +17,77 @@ ################################################################################ set -e -. "$(dirname "$0")/config.sh" +. "$(dirname "$(realpath "$0")")/config.sh" ################################################################################ +# Move script to background if DSCIP_DAEMON_FORK is set to true # +if [ "$DSCIP_DAEMON" = "true" ]; then + if [ "$DSCIP_DAEMON_FORK" = "true" ] && [ ! "$FORKED" = "true" ]; then + FORKED=true nohup "$0" "$@" > /dev/null 2>&1 + exit 0 + fi +fi + # Check if script is currently running, and if not, reset LOCK # if [ -f "$WORKING_DIRECTORY/LOCK" ]; then LOCKED_PID=$(cat "$WORKING_DIRECTORY/LOCK") if ps -p "$LOCKED_PID"; then - echo "Script still running. Exiting..." 2>> "$DSCIP_OUTPUT_TO" + echo "Script still running. Exiting..." exit 0 else - echo "Script not running, resetting lock..." 2>> "$DSCIP_OUTPUT_TO" + echo "Script not running, resetting lock..." rm "$WORKING_DIRECTORY/LOCK" fi fi echo "$$" > "$WORKING_DIRECTORY/LOCK" -if [ "$DSCIP_DAEMON" = "true" ]; then - if [ "$DSCIP_DAEMON_FORK" = "true" ] && [ ! "$FORKED" = "true" ]; then - FORKED=true nohup "$0" "$@" > /dev/null 2>&1 - exit 0 - fi -fi +# Print variables +{ +echo "################################################################################"; +date; +echo "################################################################################"; +echo "DSCIP_GITREPO=$DSCIP_GITREPO"; +echo "DSCIP_GITMODE=$DSCIP_GITMODE"; +echo "DSCIP_BRANCH=$DSCIP_BRANCH"; +echo "WORKING_DIRECTORY=$WORKING_DIRECTORY"; +echo "DSCIP_PRE_CMD=$DSCIP_PRE_CMD"; +echo "DSCIP_BUILD_CMD=$DSCIP_BUILD_CMD"; +echo "DSCIP_POST_CMD=$DSCIP_POST_CMD"; +echo "DSCIP_DAEMON=$DSCIP_DAEMON"; +echo "DSCIP_DAEMON_FORK=$DSCIP_DAEMON_FORK"; +echo "DSCIP_SLEEP=$DSCIP_SLEEP"; +echo "DSCIP_DISREGARD_COMMIT_CHECK=$DSCIP_DISREGARD_COMMIT_CHECK"; +echo "DSCIP_OUTPUT_TO=$DSCIP_OUTPUT_TO" +} >> "$DSCIP_OUTPUT_TO" build () { if [ "$DSCIP_GITMODE" = "clone" ]; then rm -rf "$WORKING_DIRECTORY/wrkdir" # Clean Up # - git clone -b "$DSCIP_BRANCH" "$DSCIP_GITREPO" wrkdir 2>> "$DSCIP_OUTPUT_TO" # Clone git # + git clone -b "$DSCIP_BRANCH" "$DSCIP_GITREPO" wrkdir >> "$DSCIP_OUTPUT_TO" 2>&1 # Clone git # elif [ "$DSCIP_GITMODE" = "pull" ]; then if [ ! -d "$WORKING_DIRECTORY/wrkdir" ]; then - git clone -b "$DSCIP_BRANCH" "$DSCIP_GITREPO" wrkdir 2>> "$DSCIP_OUTPUT_TO" + git clone -b "$DSCIP_BRANCH" "$DSCIP_GITREPO" wrkdir >> "$DSCIP_OUTPUT_TO" 2>&1 fi cd wrkdir - git pull 2>> "$DSCIP_OUTPUT_TO" + git pull >> "$DSCIP_OUTPUT_TO" 2>&1 else echo "Invalid GITMODE, choose either 'clone' or 'pull'" 2>> "$DSCIP_OUTPUT_TO" exit 1 fi - cd "$WORKING_DIRECTORY/wrkdir" - $DSCIP_PRE_CMD 2>> "$DSCIP_OUTPUT_TO" - cd "$WORKING_DIRECTORY/wrkdir" - $DSCIP_BUILD_CMD 2>> "$DSCIP_OUTPUT_TO" - cd "$WORKING_DIRECTORY/wrkdir" - $DSCIP_POST_CMD 2>> "$DSCIP_OUTPUT_TO" - mkdir -p "$WORKING_DIRECTORY/meta" - echo "$CURRENT_COMMIT" > "$WORKING_DIRECTORY/meta/LAST_COMMIT" # Save commit # + { + cd "$WORKING_DIRECTORY/wrkdir"; + echo "Running pre-build commands..."; + $DSCIP_PRE_CMD; + echo "Running build commands..."; + cd "$WORKING_DIRECTORY/wrkdir"; + $DSCIP_BUILD_CMD; + echo "Running post-build commands..."; + cd "$WORKING_DIRECTORY/wrkdir"; + $DSCIP_POST_CMD; + } >> "$DSCIP_OUTPUT_TO" 2>&1 + echo "$CURRENT_COMMIT" > "$WORKING_DIRECTORY/LAST_COMMIT" # Save commit # } run () { @@ -71,7 +95,7 @@ run () { cd "$WORKING_DIRECTORY" # Loads last commit hash if it exists. # - if [ -f "$WORKING_DIRECTORY/meta/LAST_COMMIT" ]; then + if [ -f "$WORKING_DIRECTORY/LAST_COMMIT" ]; then LAST_COMMIT="$(cat "$WORKING_DIRECTORY/meta/LAST_COMMIT")" fi @@ -90,7 +114,7 @@ run () { build fi rm "$WORKING_DIRECTORY/LOCK" # Remove lock # - echo "Done." 2>> "$DSCIP_OUTPUT_TO" + printf "Done.\n\n" >> "$DSCIP_OUTPUT_TO" } run |