diff options
Diffstat (limited to 'dscip')
-rwxr-xr-x | dscip | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/dscip b/dscip index fb09c62..fadb9ef 100755 --- a/dscip +++ b/dscip @@ -30,6 +30,22 @@ if [ "$DSCIP_DAEMON" = "true" ]; then fi fi +# If chroot is on, check if the user running this script is root. # +# Root is needed for chroot to work. # +if [ "$DSCIP_CHROOT" = "true" ]; then + if [ ! "$(whoami)" = "root" ]; then + echo "You need to run this script as root to use chroot." + exit 1 + fi + if [ ! "$DSCIP_GITMODE" = "clone" ]; then + echo "DSCIP_GITMODE needs to be in clone mode to use chroot." + exit 1 + fi + CHROOT_DIRECTORY="jail/" +else + CHROOT_DIRECTORY="" +fi + # Check if script is currently running, and if not, reset LOCK # if [ -f "$WORKING_DIRECTORY/LOCK" ]; then LOCKED_PID=$(cat "$WORKING_DIRECTORY/LOCK") @@ -68,11 +84,16 @@ build () { # Grab remote sources # if [ "$DSCIP_GITMODE" = "clone" ]; then - rm -rf "$WORKING_DIRECTORY/wrkdir" # Clean Up # - git clone --depth 1 -b "$DSCIP_BRANCH" "$DSCIP_GITREPO" wrkdir >> "$DSCIP_OUTPUT_TO" 2>&1 # Clone git # + if [ "$DSCIP_CHROOT" = "true" ]; then + . "$WORKING_DIRECTORY"/chroot_file_list.sh >> "$DSCIP_OUTPUT_TO" + git clone --depth 1 -b "$DSCIP_BRANCH" "$DSCIP_GITREPO" "$WORKING_DIRECTORY/$CHROOT_DIRECTORY/wrkdir" >> "$DSCIP_OUTPUT_TO" 2>&1 + else + rm -rf "$WORKING_DIRECTORY/$CHROOT_DIRECTORY/wrkdir" # Clean Up # + git clone --depth 1 -b "$DSCIP_BRANCH" "$DSCIP_GITREPO" "$WORKING_DIRECTORY"/wrkdir >> "$DSCIP_OUTPUT_TO" 2>&1 # Clone git # + fi elif [ "$DSCIP_GITMODE" = "pull" ]; then - if [ ! -d "$WORKING_DIRECTORY/wrkdir" ]; then - git clone --depth 1 -b "$DSCIP_BRANCH" "$DSCIP_GITREPO" wrkdir >> "$DSCIP_OUTPUT_TO" 2>&1 + if [ ! -d "$WORKING_DIRECTORY/$CHROOT_DIRECTORY/wrkdir" ]; then + git clone --depth 1 -b "$DSCIP_BRANCH" "$DSCIP_GITREPO" "$WORKING_DIRECTORY"/wrkdir >> "$DSCIP_OUTPUT_TO" 2>&1 fi cd wrkdir git pull >> "$DSCIP_OUTPUT_TO" 2>&1 @@ -80,15 +101,27 @@ build () { echo "Invalid GITMODE, choose either 'clone' or 'pull'" 2>> "$DSCIP_OUTPUT_TO" exit 1 fi + + if [ "$DSCIP_CHROOT" = "true" ]; then + chroot () { + cp "$DSCIP_BUILD_CMD" "$WORKING_DIRECTORY/$CHROOT_DIRECTORY/build.sh" + "$(which chroot)" "$WORKING_DIRECTORY/$CHROOT_DIRECTORY" sh -xc "cd wrkdir && . /build.sh" + } + else + chroot () { + . "$1" + } + fi + { - cd "$WORKING_DIRECTORY/wrkdir"; + cd "$WORKING_DIRECTORY/$CHROOT_DIRECTORY/wrkdir"; echo "Running pre-build commands..."; "$DSCIP_PRE_CMD"; echo "Running build commands..."; - cd "$WORKING_DIRECTORY/wrkdir"; - "$DSCIP_BUILD_CMD"; + cd "$WORKING_DIRECTORY/$CHROOT_DIRECTORY/wrkdir"; + chroot "$DSCIP_BUILD_CMD"; echo "Running post-build commands..."; - cd "$WORKING_DIRECTORY/wrkdir"; + cd "$WORKING_DIRECTORY/$CHROOT_DIRECTORY/wrkdir"; "$DSCIP_POST_CMD"; } >> "$DSCIP_OUTPUT_TO" 2>&1 echo "$CURRENT_COMMIT" > "$WORKING_DIRECTORY/LAST_COMMIT" # Save commit # @@ -101,10 +134,12 @@ run () { # Loads last commit hash if it exists. # if [ -f "$WORKING_DIRECTORY/LAST_COMMIT" ]; then LAST_COMMIT="$(cat "$WORKING_DIRECTORY/LAST_COMMIT")" + export LAST_COMMIT fi # Loads current commit hash # CURRENT_COMMIT=$(git ls-remote "$DSCIP_GITREPO" | awk "/refs\/(heads|tags)\/$DSCIP_BRANCH/{print \$1}") + export CURRENT_COMMIT # If LAST_COMMIT doesn't exist, that means it's a first run and we can go ahead and build. # # Or skip the commit check if DSCIP_DISREGARD_COMMIT_CHECK is set to true. |