about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xbuild.sh11
-rwxr-xr-xchroot_file_list.sh35
-rwxr-xr-x[-rw-r--r--]config.sh27
-rwxr-xr-xdscip51
-rwxr-xr-xpost.sh16
-rwxr-xr-xpre.sh9
6 files changed, 126 insertions, 23 deletions
diff --git a/build.sh b/build.sh
index 044a189..be7672e 100755
--- a/build.sh
+++ b/build.sh
@@ -1,4 +1,11 @@
 #!/bin/sh
 
-# Insert build commands in here. #
-gmake -j4
+set -e
+
+# Insert build commands in here.                                               #
+# Below are example commands.                                                  #
+./configure
+make
+make DESTDIR=app install
+
+exit 0
diff --git a/chroot_file_list.sh b/chroot_file_list.sh
new file mode 100755
index 0000000..3a46a2b
--- /dev/null
+++ b/chroot_file_list.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+# You should probably have DSCIP_DISREGARD_COMMIT_CHECK set to true until you  #
+# get all the correct files in the chroot jail.                                #
+
+set -u
+
+# Defaults should allow anything to build, but is a bit excessive. Change to   #
+# needs.                                                                       #
+export CHROOT_FILES="/lib
+/lib64
+/usr/include
+/usr/lib64
+/usr/lib
+/usr/local/lib
+/usr/bin
+/bin
+"
+
+rm -rf "$WORKING_DIRECTORY"/jail
+mkdir -p "$WORKING_DIRECTORY"/jail
+
+printf "%s" "$CHROOT_FILES" |
+		while IFS='' read -r directory
+		do
+				echo "Copying $directory into jail..."
+				if [ ! -L "$directory" ]; then
+					mkdir -p "$WORKING_DIRECTORY"/jail/"$directory"
+				fi
+				
+				if [ -L "$directory" ]; then
+					cp -r "$directory" "$WORKING_DIRECTORY"/jail/"$directory"
+				elif [ -d "$directory" ]; then
+					cp -r "$directory"/* "$WORKING_DIRECTORY"/jail/"$directory"
+				fi
+		done
diff --git a/config.sh b/config.sh
index 321235b..ee9a640 100644..100755
--- a/config.sh
+++ b/config.sh
@@ -1,24 +1,29 @@
+#!/bin/sh
 # Variables that control the program. #
 # GIT Repo #
-DSCIP_GITREPO="https://www.example.com/example/example.git"
+export 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"
+export DSCIP_GITMODE="clone"
 # Branch to check #
-DSCIP_BRANCH="master"
+export DSCIP_BRANCH="master"
 WORKING_DIRECTORY="$(pwd -P)"
+export WORKING_DIRECTORY
 # Commands to run before building. #
-DSCIP_PRE_CMD="$WORKING_DIRECTORY/pre.sh"
+export DSCIP_PRE_CMD="$WORKING_DIRECTORY/pre.sh"
 # Commands to run to build program. #
-DSCIP_BUILD_CMD="$WORKING_DIRECTORY/build.sh"
+export DSCIP_BUILD_CMD="$WORKING_DIRECTORY/build.sh"
 # Commands to run after building is done. #
-DSCIP_POST_CMD="$WORKING_DIRECTORY/post.sh"
+export DSCIP_POST_CMD="$WORKING_DIRECTORY/post.sh"
+# chroot mode #
+export DSCIP_CHROOT="false"
+export DSCIP_CHROOT_USER="dscip"
 # Daemon mode options #
-DSCIP_DAEMON="false" # If daemon mode should be enabled or not. #
-DSCIP_DAEMON_FORK="true" # If the daemon should run in the background. #
-DSCIP_SLEEP="60" # How many seconds before the daemon re-runs itself. #
+export DSCIP_DAEMON="false" # If daemon mode should be enabled or not. #
+export DSCIP_DAEMON_FORK="true" # If the daemon should run in the background. #
+export DSCIP_SLEEP="60" # How many seconds before the daemon re-runs itself. #
 # etc #
-DSCIP_DISREGARD_COMMIT_CHECK="false" # If the script should just rebuild even #
+export DSCIP_DISREGARD_COMMIT_CHECK="false" # If the script should just rebuild even #
 # if upstream has not updated. #
-DSCIP_OUTPUT_TO="$WORKING_DIRECTORY/output.log" # Output to file, default is stdout. 
+export DSCIP_OUTPUT_TO="$WORKING_DIRECTORY/output.log" # Output to file, default is stdout.
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.
diff --git a/post.sh b/post.sh
index 1d048f9..ccd097b 100755
--- a/post.sh
+++ b/post.sh
@@ -1,5 +1,19 @@
 #!/bin/sh
+set -e
 
-# Execute commands after building. Like pushing to an FTP server. #
+# Execute commands after building. Like pushing to an FTP server.              #
+# Below is an example of what commands you could use.                          #
+
+bsdtar -a -cvf program-$CURRENT_COMMIT.tar.gz app/
+ftp -in <<EOF
+open 192.168.1.1
+user example password
+mkdir $CURRENT_COMMIT
+cd $CURRENT_COMMIT
+put program-$CURRENT_COMMIT.tar.gz program-$CURRENT_COMMIT.tar.gz
+put $WORKING_DIRECTORY/output.log output.log
+close
+bye
+EOF
 
 exit 0
diff --git a/pre.sh b/pre.sh
index 0d614ed..28e6f2b 100755
--- a/pre.sh
+++ b/pre.sh
@@ -1,5 +1,12 @@
 #!/bin/sh
+set -e
 
-# Execute commands before building. #
+# Execute commands before building.                                            #
+# Below is an example.                                                         #
+
+sudo apt update
+sudo apt upgrade
+wget https://example.com/game_assets.zip
+unzip game_assets.zip
 
 exit 0