From 408a0de4f0d22ecc303c50d5a0cab8c27a503df7 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Tue, 20 Apr 2021 20:18:22 -0400
Subject: [PATCH 01/26] appimage: remove node_modules from appdir

The node modules do not need to be deliverer with the appimage. Removing
them from the AppDir saves 50MB.
---
 appimage/build_appimage.sh | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index d4c6b6251..2edc0d15c 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -179,13 +179,21 @@ generate_ssl_cert() {
 }
 
 build_frontend() {
-    pushd "$ISLAND_PATH/cc/ui" || handle_error
-    npm install sass-loader node-sass webpack --save-dev
-    npm update
+  pushd "$ISLAND_PATH/cc/ui" || handle_error
+  npm install sass-loader node-sass webpack --save-dev
+  npm update
 
-    log_message "Generating front end"
-    npm run dist
-    popd || handle_error
+  log_message "Generating front end"
+  npm run dist
+  popd || handle_error
+
+  remove_node_modules
+}
+
+remove_node_modules() {
+  # Node has served its purpose. We don't need to deliver the node modules with
+  # the AppImage.
+  rm -rf "$ISLAND_PATH"/cc/ui/node_modules
 }
 
 add_monkey_icon() {

From c33f9cf83c6b5547967f2895fe8635501e8e77d5 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Wed, 21 Apr 2021 07:32:35 -0400
Subject: [PATCH 02/26] appimage: Upgrade from Python 3.7.9 -> 3.7.10

---
 appimage/build_appimage.sh | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index 2edc0d15c..26f31f094 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -15,7 +15,8 @@ ISLAND_BINARIES_PATH="$ISLAND_PATH/cc/binaries"
 
 NODE_SRC=https://deb.nodesource.com/setup_12.x
 APP_TOOL_URL=https://github.com/AppImage/AppImageKit/releases/download/12/appimagetool-x86_64.AppImage
-PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python3.7.9-cp37-cp37m-manylinux1_x86_64.AppImage"
+PYTHON_VERSION="3.7.10"
+PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python${PYTHON_VERSION}-cp37-cp37m-manylinux1_x86_64.AppImage"
 
 is_root() {
   return "$(id -u)"
@@ -103,7 +104,7 @@ setup_appdir() {
 }
 
 setup_python_37_appdir() {
-    PYTHON_APPIMAGE="python3.7.9_x86_64.AppImage"
+    PYTHON_APPIMAGE="python${PYTHON_VERSION}_x86_64.AppImage"
     rm -rf "$APPDIR" || true
 
     log_message "downloading Python3.7 Appimage"
@@ -204,7 +205,7 @@ add_monkey_icon() {
 }
 
 add_desktop_file() {
-	unlink "$APPDIR"/python3.7.9.desktop
+	unlink "$APPDIR/python${PYTHON_VERSION}.desktop"
 	cp ./infection-monkey.desktop "$APPDIR"/usr/share/applications
 	ln -s "$APPDIR"/usr/share/applications/infection-monkey.desktop "$APPDIR"/infection-monkey.desktop
 }

From 7276760c6a570aeb321c0522fdef0e2521e65318 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Mon, 26 Apr 2021 07:05:05 -0400
Subject: [PATCH 03/26] appimage: Remove unnecessary recursive chmod in
 clone_monkey_repo()

---
 appimage/build_appimage.sh | 2 --
 1 file changed, 2 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index 26f31f094..d04af81cf 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -82,8 +82,6 @@ clone_monkey_repo() {
   log_message "Cloning files from git"
   branch=${1:-"develop"}
   git clone --single-branch --recurse-submodules -b "$branch" "${MONKEY_GIT_URL}" "${REPO_MONKEY_HOME}" 2>&1 || handle_error
-
-  chmod 774 -R "${REPO_MONKEY_HOME}"
 }
 
 setup_appdir() {

From c47f5a59120e788cdd16efc353e45b7154fccc3e Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Thu, 29 Apr 2021 11:50:22 -0400
Subject: [PATCH 04/26] appimage: Relocate squashfs-root/ to same dir as
 build_appimage.sh

---
 appimage/README.md         | 2 +-
 appimage/build_appimage.sh | 3 +--
 appimage/clean.sh          | 2 +-
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/appimage/README.md b/appimage/README.md
index b1c3010e4..95ff4d42d 100644
--- a/appimage/README.md
+++ b/appimage/README.md
@@ -18,7 +18,7 @@ NOTE: This script is intended to be run from a clean VM. You can also manually
 remove build artifacts by removing the following files and directories.
 
 - $HOME/.monkey_island (optional)
-- $HOME/squashfs-root
+- $HOME/appimage/squashfs-root
 - $HOME/git/monkey
 - $HOME/appimage/Infection_Monkey-x86_64.AppImage
 
diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index d04af81cf..d978f2d49 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-APPDIR="$HOME/squashfs-root"
+APPDIR="./squashfs-root"
 CONFIG_URL="https://raw.githubusercontent.com/guardicore/monkey/develop/deployment_scripts/config"
 INSTALL_DIR="$APPDIR/usr/src"
 
@@ -112,7 +112,6 @@ setup_python_37_appdir() {
 
     ./"$PYTHON_APPIMAGE" --appimage-extract
     rm "$PYTHON_APPIMAGE"
-    mv ./squashfs-root "$APPDIR"
     mkdir -p "$INSTALL_DIR"
 }
 
diff --git a/appimage/clean.sh b/appimage/clean.sh
index 45d6e1755..5e2fd443a 100755
--- a/appimage/clean.sh
+++ b/appimage/clean.sh
@@ -4,6 +4,6 @@
 # in order to speed up development and debugging.
 
 rm -rf "$HOME/.monkey_island"
-rm -rf "$HOME/squashfs-root"
+rm -rf "$HOME/appimage/squashfs-root"
 rm -rf "$HOME/git/monkey"
 rm "$HOME/appimage/Infection_Monkey-x86_64.AppImage"

From 1f4af6827840b203389a9266fcbe70b9ac68b663 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Thu, 29 Apr 2021 12:34:04 -0400
Subject: [PATCH 05/26] appimage: Use $WORKSPACE variable if present

Jenkins sets a $WORKSPACE environment variable. We'll use this if it's
been set. Otherwise, use $HOME.
---
 appimage/build_appimage.sh | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index d978f2d49..e39a85454 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -1,10 +1,12 @@
 #!/bin/bash
 
-APPDIR="./squashfs-root"
+WORKSPACE=${WORKSPACE:-$HOME}
+
+APPDIR="$PWD/squashfs-root"
 CONFIG_URL="https://raw.githubusercontent.com/guardicore/monkey/develop/deployment_scripts/config"
 INSTALL_DIR="$APPDIR/usr/src"
 
-GIT=$HOME/git
+GIT=$WORKSPACE/git
 
 REPO_MONKEY_HOME=$GIT/monkey
 REPO_MONKEY_SRC=$REPO_MONKEY_HOME/monkey
@@ -55,13 +57,13 @@ install_build_prereqs() {
 }
 
 install_appimage_tool() {
-    APP_TOOL_BIN=$HOME/bin/appimagetool
+    APP_TOOL_BIN=$WORKSPACE/bin/appimagetool
 
-    mkdir -p "$HOME"/bin
+    mkdir -p "$WORKSPACE"/bin
     curl -L -o "$APP_TOOL_BIN" "$APP_TOOL_URL"
     chmod u+x "$APP_TOOL_BIN"
 
-    PATH=$PATH:$HOME/bin
+    PATH=$PATH:$WORKSPACE/bin
 }
 
 load_monkey_binary_config() {

From 84c875c3969ae6b776eaffa242a1d8bda9a3d79d Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Thu, 29 Apr 2021 12:36:29 -0400
Subject: [PATCH 06/26] appimage: Only load binary config if downloading agent
 binaries

---
 appimage/build_appimage.sh | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index e39a85454..696c35fb2 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -3,7 +3,6 @@
 WORKSPACE=${WORKSPACE:-$HOME}
 
 APPDIR="$PWD/squashfs-root"
-CONFIG_URL="https://raw.githubusercontent.com/guardicore/monkey/develop/deployment_scripts/config"
 INSTALL_DIR="$APPDIR/usr/src"
 
 GIT=$WORKSPACE/git
@@ -15,6 +14,8 @@ ISLAND_PATH="$INSTALL_DIR/monkey_island"
 MONGO_PATH="$ISLAND_PATH/bin/mongodb"
 ISLAND_BINARIES_PATH="$ISLAND_PATH/cc/binaries"
 
+MONKEY_ORIGIN_URL="https://github.com/guardicore/monkey.git"
+CONFIG_URL="https://raw.githubusercontent.com/guardicore/monkey/develop/deployment_scripts/config"
 NODE_SRC=https://deb.nodesource.com/setup_12.x
 APP_TOOL_URL=https://github.com/AppImage/AppImageKit/releases/download/12/appimagetool-x86_64.AppImage
 PYTHON_VERSION="3.7.10"
@@ -66,16 +67,6 @@ install_appimage_tool() {
     PATH=$PATH:$WORKSPACE/bin
 }
 
-load_monkey_binary_config() {
-  tmpfile=$(mktemp)
-
-  log_message "downloading configuration"
-  curl -L -s -o "$tmpfile" "$CONFIG_URL"
-
-  log_message "loading configuration"
-  source "$tmpfile"
-}
-
 clone_monkey_repo() {
   if [[ ! -d ${GIT} ]]; then
     mkdir -p "${GIT}"
@@ -83,7 +74,7 @@ clone_monkey_repo() {
 
   log_message "Cloning files from git"
   branch=${1:-"develop"}
-  git clone --single-branch --recurse-submodules -b "$branch" "${MONKEY_GIT_URL}" "${REPO_MONKEY_HOME}" 2>&1 || handle_error
+  git clone --single-branch --recurse-submodules -b "$branch" "$MONKEY_ORIGIN_URL" "$REPO_MONKEY_HOME" 2>&1 || handle_error
 }
 
 setup_appdir() {
@@ -152,7 +143,10 @@ generate_requirements_from_pipenv_lock () {
 }
 
 download_monkey_agent_binaries() {
-log_message "Downloading monkey agent binaries to ${ISLAND_BINARIES_PATH}"
+  log_message "Downloading monkey agent binaries to ${ISLAND_BINARIES_PATH}"
+
+  load_monkey_binary_config
+
   mkdir -p "${ISLAND_BINARIES_PATH}" || handle_error
   curl -L -o "${ISLAND_BINARIES_PATH}/${LINUX_32_BINARY_NAME}" "${LINUX_32_BINARY_URL}"
   curl -L -o "${ISLAND_BINARIES_PATH}/${LINUX_64_BINARY_NAME}" "${LINUX_64_BINARY_URL}"
@@ -164,6 +158,16 @@ log_message "Downloading monkey agent binaries to ${ISLAND_BINARIES_PATH}"
   chmod a+x "$ISLAND_BINARIES_PATH/$LINUX_64_BINARY_NAME"
 }
 
+load_monkey_binary_config() {
+  tmpfile=$(mktemp)
+
+  log_message "Downloading prebuilt binary configuration"
+  curl -L -s -o "$tmpfile" "$CONFIG_URL"
+
+  log_message "Loading configuration"
+  source "$tmpfile"
+}
+
 install_mongodb() {
   log_message "Installing MongoDB"
 
@@ -233,7 +237,6 @@ fi
 install_build_prereqs
 install_appimage_tool
 
-load_monkey_binary_config
 clone_monkey_repo "$@"
 
 setup_appdir

From 68759e39702ecebe509d3cca294eae5144bdca81 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Thu, 29 Apr 2021 12:54:49 -0400
Subject: [PATCH 07/26] appimage: Make spacing consistent

---
 appimage/build_appimage.sh | 76 +++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 38 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index 696c35fb2..9a3d56de3 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -49,22 +49,22 @@ install_nodejs() {
 }
 
 install_build_prereqs() {
-    sudo apt update
-    sudo apt upgrade -y
+  sudo apt update
+  sudo apt upgrade -y
 
-    # monkey island prereqs
-    sudo apt install -y curl libcurl4 openssl git build-essential moreutils
-    install_nodejs
+  # monkey island prereqs
+  sudo apt install -y curl libcurl4 openssl git build-essential moreutils
+  install_nodejs
 }
 
 install_appimage_tool() {
-    APP_TOOL_BIN=$WORKSPACE/bin/appimagetool
+  APP_TOOL_BIN=$WORKSPACE/bin/appimagetool
 
-    mkdir -p "$WORKSPACE"/bin
-    curl -L -o "$APP_TOOL_BIN" "$APP_TOOL_URL"
-    chmod u+x "$APP_TOOL_BIN"
+  mkdir -p "$WORKSPACE"/bin
+  curl -L -o "$APP_TOOL_BIN" "$APP_TOOL_URL"
+  chmod u+x "$APP_TOOL_BIN"
 
-    PATH=$PATH:$WORKSPACE/bin
+  PATH=$PATH:$WORKSPACE/bin
 }
 
 clone_monkey_repo() {
@@ -78,34 +78,34 @@ clone_monkey_repo() {
 }
 
 setup_appdir() {
-	setup_python_37_appdir
+  setup_python_37_appdir
 
-	copy_monkey_island_to_appdir
-	download_monkey_agent_binaries
+  copy_monkey_island_to_appdir
+  download_monkey_agent_binaries
 
-	install_monkey_island_python_dependencies
-	install_mongodb
+  install_monkey_island_python_dependencies
+  install_mongodb
 
-	generate_ssl_cert
-	build_frontend
+  generate_ssl_cert
+  build_frontend
 
-	add_monkey_icon
-	add_desktop_file
-	add_apprun
+  add_monkey_icon
+  add_desktop_file
+  add_apprun
 }
 
 setup_python_37_appdir() {
-    PYTHON_APPIMAGE="python${PYTHON_VERSION}_x86_64.AppImage"
-    rm -rf "$APPDIR" || true
+  PYTHON_APPIMAGE="python${PYTHON_VERSION}_x86_64.AppImage"
+  rm -rf "$APPDIR" || true
 
-    log_message "downloading Python3.7 Appimage"
-    curl -L -o "$PYTHON_APPIMAGE" "$PYTHON_APPIMAGE_URL"
+  log_message "downloading Python3.7 Appimage"
+  curl -L -o "$PYTHON_APPIMAGE" "$PYTHON_APPIMAGE_URL"
 
-    chmod u+x "$PYTHON_APPIMAGE"
+  chmod u+x "$PYTHON_APPIMAGE"
 
-    ./"$PYTHON_APPIMAGE" --appimage-extract
-    rm "$PYTHON_APPIMAGE"
-    mkdir -p "$INSTALL_DIR"
+  ./"$PYTHON_APPIMAGE" --appimage-extract
+  rm "$PYTHON_APPIMAGE"
+  mkdir -p "$INSTALL_DIR"
 }
 
 copy_monkey_island_to_appdir() {
@@ -201,25 +201,25 @@ remove_node_modules() {
 }
 
 add_monkey_icon() {
-	unlink "$APPDIR"/python.png
-	mkdir -p "$APPDIR"/usr/share/icons
-	cp "$REPO_MONKEY_SRC"/monkey_island/cc/ui/src/images/monkey-icon.svg "$APPDIR"/usr/share/icons/infection-monkey.svg
-	ln -s "$APPDIR"/usr/share/icons/infection-monkey.svg "$APPDIR"/infection-monkey.svg
+  unlink "$APPDIR"/python.png
+  mkdir -p "$APPDIR"/usr/share/icons
+  cp "$REPO_MONKEY_SRC"/monkey_island/cc/ui/src/images/monkey-icon.svg "$APPDIR"/usr/share/icons/infection-monkey.svg
+  ln -s "$APPDIR"/usr/share/icons/infection-monkey.svg "$APPDIR"/infection-monkey.svg
 }
 
 add_desktop_file() {
-	unlink "$APPDIR/python${PYTHON_VERSION}.desktop"
-	cp ./infection-monkey.desktop "$APPDIR"/usr/share/applications
-	ln -s "$APPDIR"/usr/share/applications/infection-monkey.desktop "$APPDIR"/infection-monkey.desktop
+  unlink "$APPDIR/python${PYTHON_VERSION}.desktop"
+  cp ./infection-monkey.desktop "$APPDIR"/usr/share/applications
+  ln -s "$APPDIR"/usr/share/applications/infection-monkey.desktop "$APPDIR"/infection-monkey.desktop
 }
 
 add_apprun() {
-	cp ./AppRun "$APPDIR"
+  cp ./AppRun "$APPDIR"
 }
 
 build_appimage() {
-    log_message "Building AppImage"
-    ARCH="x86_64" appimagetool "$APPDIR"
+  log_message "Building AppImage"
+  ARCH="x86_64" appimagetool "$APPDIR"
 }
 
 if is_root; then

From 8cb47ce3e7c6cbe362efa0e6c54faa0fbb0379a1 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Thu, 29 Apr 2021 13:22:04 -0400
Subject: [PATCH 08/26] appimage: Add cli parameter for specifying the package
 version

---
 appimage/README.md         |  2 +-
 appimage/build_appimage.sh | 22 +++++++++++++++++++++-
 appimage/clean.sh          |  2 +-
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/appimage/README.md b/appimage/README.md
index 95ff4d42d..dfa4731a0 100644
--- a/appimage/README.md
+++ b/appimage/README.md
@@ -20,7 +20,7 @@ remove build artifacts by removing the following files and directories.
 - $HOME/.monkey_island (optional)
 - $HOME/appimage/squashfs-root
 - $HOME/git/monkey
-- $HOME/appimage/Infection_Monkey-x86_64.AppImage
+- $HOME/appimage/Infection_Monkey*x86_64.AppImage
 
 After removing the above files and directories, you can again execute `bash
 build_appimage.sh`.
diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index 9a3d56de3..dcda9ddb0 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -220,6 +220,11 @@ add_apprun() {
 build_appimage() {
   log_message "Building AppImage"
   ARCH="x86_64" appimagetool "$APPDIR"
+  apply_version_to_appimage "$1"
+}
+
+apply_version_to_appimage() {
+  mv "Infection_Monkey-x86_64.AppImage" "Infection_Monkey-$1-x86_64.AppImage"
 }
 
 if is_root; then
@@ -233,6 +238,21 @@ Run \`sudo -v\`, enter your password, and then re-run this script."
   exit 1
 fi
 
+monkey_version="dev"
+
+while (( "$#" )); do
+case "$1" in
+  --version)
+    if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
+      monkey_version=$2
+      shift 2
+    else
+      echo "Error: Argument for $1 is missing" >&2
+      exit 1
+    fi
+  esac
+done
+
 
 install_build_prereqs
 install_appimage_tool
@@ -241,7 +261,7 @@ clone_monkey_repo "$@"
 
 setup_appdir
 
-build_appimage
+build_appimage "$monkey_version"
 
 log_message "Deployment script finished."
 exit 0
diff --git a/appimage/clean.sh b/appimage/clean.sh
index 5e2fd443a..f48837d37 100755
--- a/appimage/clean.sh
+++ b/appimage/clean.sh
@@ -6,4 +6,4 @@
 rm -rf "$HOME/.monkey_island"
 rm -rf "$HOME/appimage/squashfs-root"
 rm -rf "$HOME/git/monkey"
-rm "$HOME/appimage/Infection_Monkey-x86_64.AppImage"
+rm $HOME/appimage/Infection_Monkey*x86_64.AppImage

From 2856b85616812ddc80dbee3c7c4c309303ab4a1f Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Thu, 29 Apr 2021 13:48:19 -0400
Subject: [PATCH 09/26] appimage: Add cli parameter for specifying which agent
 binaries to include

---
 appimage/build_appimage.sh | 44 +++++++++++++++++++++++++++++++-------
 1 file changed, 36 insertions(+), 8 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index dcda9ddb0..56752d64d 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -21,6 +21,11 @@ APP_TOOL_URL=https://github.com/AppImage/AppImageKit/releases/download/12/appima
 PYTHON_VERSION="3.7.10"
 PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python${PYTHON_VERSION}-cp37-cp37m-manylinux1_x86_64.AppImage"
 
+missing_argument() {
+  echo "Error: Argument for $1 is missing" >&2
+  exit 1
+}
+
 is_root() {
   return "$(id -u)"
 }
@@ -81,7 +86,7 @@ setup_appdir() {
   setup_python_37_appdir
 
   copy_monkey_island_to_appdir
-  download_monkey_agent_binaries
+  add_agent_binaries_to_appdir $1
 
   install_monkey_island_python_dependencies
   install_mongodb
@@ -142,7 +147,17 @@ generate_requirements_from_pipenv_lock () {
   cd -
 }
 
-download_monkey_agent_binaries() {
+add_agent_binaries_to_appdir() {
+  if [ -z "$1" ]; then
+    download_monkey_agent_binaries_to_appdir
+  else
+    copy_agent_binaries_to_appdir $1
+  fi
+
+  make_linux_binaries_executable
+}
+
+download_monkey_agent_binaries_to_appdir() {
   log_message "Downloading monkey agent binaries to ${ISLAND_BINARIES_PATH}"
 
   load_monkey_binary_config
@@ -152,10 +167,14 @@ download_monkey_agent_binaries() {
   curl -L -o "${ISLAND_BINARIES_PATH}/${LINUX_64_BINARY_NAME}" "${LINUX_64_BINARY_URL}"
   curl -L -o "${ISLAND_BINARIES_PATH}/${WINDOWS_32_BINARY_NAME}" "${WINDOWS_32_BINARY_URL}"
   curl -L -o "${ISLAND_BINARIES_PATH}/${WINDOWS_64_BINARY_NAME}" "${WINDOWS_64_BINARY_URL}"
+}
 
-  # Allow them to be executed
-  chmod a+x "$ISLAND_BINARIES_PATH/$LINUX_32_BINARY_NAME"
-  chmod a+x "$ISLAND_BINARIES_PATH/$LINUX_64_BINARY_NAME"
+copy_agent_binaries_to_appdir() {
+  cp "$1"/* "$ISLAND_BINARIES_PATH/"
+}
+
+make_linux_binaries_executable() {
+  chmod a+x "$ISLAND_BINARIES_PATH"/monkey-linux-*
 }
 
 load_monkey_binary_config() {
@@ -239,6 +258,7 @@ Run \`sudo -v\`, enter your password, and then re-run this script."
 fi
 
 monkey_version="dev"
+agent_binary_dir=""
 
 while (( "$#" )); do
 case "$1" in
@@ -247,9 +267,17 @@ case "$1" in
       monkey_version=$2
       shift 2
     else
-      echo "Error: Argument for $1 is missing" >&2
-      exit 1
+      missing_argument "$1"
     fi
+    ;;
+  --agent-binary-dir)
+    if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
+      agent_binary_dir=$2
+      shift 2
+    else
+      missing_argument "$1"
+    fi
+    ;;
   esac
 done
 
@@ -259,7 +287,7 @@ install_appimage_tool
 
 clone_monkey_repo "$@"
 
-setup_appdir
+setup_appdir "$agent_binary_dir"
 
 build_appimage "$monkey_version"
 

From e58281b0f0089a33a1e4410bed925efaccbed49a Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Thu, 29 Apr 2021 13:58:30 -0400
Subject: [PATCH 10/26] appimage: Use npm-ci instead of npm-install

---
 appimage/build_appimage.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index 56752d64d..5c3c361bd 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -203,11 +203,11 @@ generate_ssl_cert() {
 
 build_frontend() {
   pushd "$ISLAND_PATH/cc/ui" || handle_error
-  npm install sass-loader node-sass webpack --save-dev
-  npm update
 
   log_message "Generating front end"
+  npm ci
   npm run dist
+
   popd || handle_error
 
   remove_node_modules

From 9c11f239ce96711e52d1f86611ca96fc64a530b7 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Thu, 29 Apr 2021 14:40:52 -0400
Subject: [PATCH 11/26] appimage: Add a cli parameter for for specifying a git
 branch

---
 appimage/build_appimage.sh | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index 5c3c361bd..b77c8fc96 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -78,8 +78,7 @@ clone_monkey_repo() {
   fi
 
   log_message "Cloning files from git"
-  branch=${1:-"develop"}
-  git clone --single-branch --recurse-submodules -b "$branch" "$MONKEY_ORIGIN_URL" "$REPO_MONKEY_HOME" 2>&1 || handle_error
+  git clone --single-branch --recurse-submodules -b "$1" "$MONKEY_ORIGIN_URL" "$REPO_MONKEY_HOME" 2>&1 || handle_error
 }
 
 setup_appdir() {
@@ -259,6 +258,7 @@ fi
 
 monkey_version="dev"
 agent_binary_dir=""
+branch="develop"
 
 while (( "$#" )); do
 case "$1" in
@@ -278,6 +278,13 @@ case "$1" in
       missing_argument "$1"
     fi
     ;;
+   --branch)
+    if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
+      branch=$2
+      shift 2
+    else
+      missing_argument "$1"
+    fi
   esac
 done
 
@@ -285,7 +292,7 @@ done
 install_build_prereqs
 install_appimage_tool
 
-clone_monkey_repo "$@"
+clone_monkey_repo "$branch"
 
 setup_appdir "$agent_binary_dir"
 

From 280b1e280a7640e273d88452aa49aef9a836f284 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Thu, 29 Apr 2021 14:49:51 -0400
Subject: [PATCH 12/26] appimage: Put cli parameters in alphabetical order

---
 appimage/build_appimage.sh | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index b77c8fc96..d2f9a6448 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -262,14 +262,6 @@ branch="develop"
 
 while (( "$#" )); do
 case "$1" in
-  --version)
-    if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
-      monkey_version=$2
-      shift 2
-    else
-      missing_argument "$1"
-    fi
-    ;;
   --agent-binary-dir)
     if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
       agent_binary_dir=$2
@@ -285,6 +277,15 @@ case "$1" in
     else
       missing_argument "$1"
     fi
+	;;
+  --version)
+    if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
+      monkey_version=$2
+      shift 2
+    else
+      missing_argument "$1"
+    fi
+    ;;
   esac
 done
 

From fe25cd257ff8ffb3c202cac6527731ab11832ccc Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Thu, 29 Apr 2021 15:17:02 -0400
Subject: [PATCH 13/26] appimage: Add cli parameter to specify local monkey
 repo dir

---
 appimage/build_appimage.sh | 55 +++++++++++++++++++++++++++-----------
 1 file changed, 40 insertions(+), 15 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index d2f9a6448..849face15 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -7,8 +7,7 @@ INSTALL_DIR="$APPDIR/usr/src"
 
 GIT=$WORKSPACE/git
 
-REPO_MONKEY_HOME=$GIT/monkey
-REPO_MONKEY_SRC=$REPO_MONKEY_HOME/monkey
+DEFAULT_REPO_MONKEY_HOME=$GIT/monkey
 
 ISLAND_PATH="$INSTALL_DIR/monkey_island"
 MONGO_PATH="$ISLAND_PATH/bin/mongodb"
@@ -72,20 +71,35 @@ install_appimage_tool() {
   PATH=$PATH:$WORKSPACE/bin
 }
 
+is_valid_git_repo() {
+  pushd "$1" 2>/dev/null || return 1
+  git status >/dev/null 2>&1
+  success="$?"
+  popd || exit 1
+
+  return $success
+}
+
 clone_monkey_repo() {
-  if [[ ! -d ${GIT} ]]; then
-    mkdir -p "${GIT}"
+  local repo_dir=$1
+  local branch=$2
+
+  if [[ ! -d "$repo_dir" ]]; then
+    mkdir -p "$repo_dir"
   fi
 
   log_message "Cloning files from git"
-  git clone --single-branch --recurse-submodules -b "$1" "$MONKEY_ORIGIN_URL" "$REPO_MONKEY_HOME" 2>&1 || handle_error
+  git clone --single-branch --recurse-submodules -b "$branch" "$MONKEY_ORIGIN_URL" "$repo_dir" 2>&1 || handle_error
 }
 
 setup_appdir() {
+  local agent_binary_dir=$1
+  local monkey_repo=$2
+
   setup_python_37_appdir
 
-  copy_monkey_island_to_appdir
-  add_agent_binaries_to_appdir $1
+  copy_monkey_island_to_appdir "$monkey_repo"/monkey
+  add_agent_binaries_to_appdir "$agent_binary_dir"
 
   install_monkey_island_python_dependencies
   install_mongodb
@@ -93,7 +107,7 @@ setup_appdir() {
   generate_ssl_cert
   build_frontend
 
-  add_monkey_icon
+  add_monkey_icon "$monkey_repo"/monkey
   add_desktop_file
   add_apprun
 }
@@ -113,10 +127,10 @@ setup_python_37_appdir() {
 }
 
 copy_monkey_island_to_appdir() {
-  cp "$REPO_MONKEY_SRC"/__init__.py "$INSTALL_DIR"
-  cp "$REPO_MONKEY_SRC"/monkey_island.py "$INSTALL_DIR"
-  cp -r "$REPO_MONKEY_SRC"/common "$INSTALL_DIR/"
-  cp -r "$REPO_MONKEY_SRC"/monkey_island "$INSTALL_DIR/"
+  cp "$1"/__init__.py "$INSTALL_DIR"
+  cp "$1"/monkey_island.py "$INSTALL_DIR"
+  cp -r "$1"/common "$INSTALL_DIR/"
+  cp -r "$1"/monkey_island "$INSTALL_DIR/"
   cp ./run_appimage.sh "$INSTALL_DIR"/monkey_island/linux/
   cp ./island_logger_config.json "$INSTALL_DIR"/
   cp ./server_config.json.standard "$INSTALL_DIR"/monkey_island/cc/
@@ -221,7 +235,7 @@ remove_node_modules() {
 add_monkey_icon() {
   unlink "$APPDIR"/python.png
   mkdir -p "$APPDIR"/usr/share/icons
-  cp "$REPO_MONKEY_SRC"/monkey_island/cc/ui/src/images/monkey-icon.svg "$APPDIR"/usr/share/icons/infection-monkey.svg
+  cp "$1"/monkey_island/cc/ui/src/images/monkey-icon.svg "$APPDIR"/usr/share/icons/infection-monkey.svg
   ln -s "$APPDIR"/usr/share/icons/infection-monkey.svg "$APPDIR"/infection-monkey.svg
 }
 
@@ -256,6 +270,7 @@ Run \`sudo -v\`, enter your password, and then re-run this script."
   exit 1
 fi
 
+monkey_repo="$DEFAULT_REPO_MONKEY_HOME"
 monkey_version="dev"
 agent_binary_dir=""
 branch="develop"
@@ -278,6 +293,14 @@ case "$1" in
       missing_argument "$1"
     fi
 	;;
+  --monkey-repo)
+    if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
+      monkey_repo=$2
+      shift 2
+    else
+      missing_argument "$1"
+    fi
+    ;;
   --version)
     if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
       monkey_version=$2
@@ -293,9 +316,11 @@ done
 install_build_prereqs
 install_appimage_tool
 
-clone_monkey_repo "$branch"
+if ! is_valid_git_repo "$monkey_repo"; then
+  clone_monkey_repo "$monkey_repo" "$branch"
+fi
 
-setup_appdir "$agent_binary_dir"
+setup_appdir "$agent_binary_dir" "$monkey_repo"
 
 build_appimage "$monkey_version"
 

From f91a52f0c0b9e55f113577b44398e35acd2f5049 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Thu, 29 Apr 2021 15:19:29 -0400
Subject: [PATCH 14/26] appimage: Exit with error if unsupported parameters are
 passed

---
 appimage/build_appimage.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index 849face15..8f9f6b32a 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -309,6 +309,9 @@ case "$1" in
       missing_argument "$1"
     fi
     ;;
+  -*)
+	echo "Error: Unsupported parameter $1" >&2
+	exit 1
   esac
 done
 

From d53ba0e88112c77159085d555467b5e9df67e90e Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Thu, 29 Apr 2021 15:39:17 -0400
Subject: [PATCH 15/26] appimage: Add --help

---
 appimage/build_appimage.sh | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index 8f9f6b32a..9358a12be 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -25,6 +25,34 @@ missing_argument() {
   exit 1
 }
 
+echo_help() {
+  echo "usage: build_appimage.sh [--help] [--agent-binary-dir <PATH>] [--branch <BRANCH>]"
+  echo "                         [--monkey-repo <PATH>] [--version <MONKEY_VERSION>]"
+  echo ""
+  echo "Creates an AppImage package for Infection Monkey."
+  echo ""
+  echo "--agent-binary-dir             A directory containing the agent binaries that"
+  echo "                               you'd like to include with the AppImage. If this"
+  echo "                               parameter is unspecified, the latest release"
+  echo "                               binaries will be downloaded from GitHub."
+  echo ""
+  echo "--branch                       The git branch you'd like the AppImage to be"
+  echo "                               built from. (Default: develop)"
+  echo ""
+  echo "--monkey-repo                  A directory containing the Infection Monkey git"
+  echo "                               repository. If the directory is empty or does"
+  echo "                               not exist, a new repo will be cloned from GitHub."
+  echo "                               If the directory is already a valid GitHub repo,"
+  echo "                               it will be used as-is and the --branch parameter"
+  echo "                               will have no effect."
+  echo "                               (Default: $DEFAULT_REPO_MONKEY_HOME)"
+  echo ""
+  echo "--version                      A version number for the AppImage package."
+  echo "                               (Default: dev)"
+
+  exit 0
+}
+
 is_root() {
   return "$(id -u)"
 }
@@ -293,6 +321,9 @@ case "$1" in
       missing_argument "$1"
     fi
 	;;
+  -h|--help)
+	echo_help
+	;;
   --monkey-repo)
     if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
       monkey_repo=$2
@@ -312,6 +343,7 @@ case "$1" in
   -*)
 	echo "Error: Unsupported parameter $1" >&2
 	exit 1
+	;;
   esac
 done
 

From febad65ff924eadeee9ff21f485c79247385d81e Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Thu, 29 Apr 2021 15:40:38 -0400
Subject: [PATCH 16/26] appimage: Perform root checks after parsing args

---
 appimage/build_appimage.sh | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index 9358a12be..f368ac7ea 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -287,17 +287,6 @@ apply_version_to_appimage() {
   mv "Infection_Monkey-x86_64.AppImage" "Infection_Monkey-$1-x86_64.AppImage"
 }
 
-if is_root; then
-  log_message "Please don't run this script as root"
-  exit 1
-fi
-
-if ! has_sudo; then
-  log_message "You need root permissions for some of this script operations. \
-Run \`sudo -v\`, enter your password, and then re-run this script."
-  exit 1
-fi
-
 monkey_repo="$DEFAULT_REPO_MONKEY_HOME"
 monkey_version="dev"
 agent_binary_dir=""
@@ -347,6 +336,17 @@ case "$1" in
   esac
 done
 
+if is_root; then
+  log_message "Please don't run this script as root"
+  exit 1
+fi
+
+if ! has_sudo; then
+  log_message "You need root permissions for some of this script operations. \
+Run \`sudo -v\`, enter your password, and then re-run this script."
+  exit 1
+fi
+
 
 install_build_prereqs
 install_appimage_tool

From ebd2fddd79f28f32870b4a5076f67cd28231d0a3 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Fri, 30 Apr 2021 07:36:18 -0400
Subject: [PATCH 17/26] appimage: Add --as-root flag

---
 appimage/build_appimage.sh | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index f368ac7ea..f0b299da3 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -36,6 +36,9 @@ echo_help() {
   echo "                               parameter is unspecified, the latest release"
   echo "                               binaries will be downloaded from GitHub."
   echo ""
+  echo "--as-root                      Throw caution to the wind and allow this script"
+  echo "                               to be run as root."
+  echo ""
   echo "--branch                       The git branch you'd like the AppImage to be"
   echo "                               built from. (Default: develop)"
   echo ""
@@ -287,6 +290,7 @@ apply_version_to_appimage() {
   mv "Infection_Monkey-x86_64.AppImage" "Infection_Monkey-$1-x86_64.AppImage"
 }
 
+as_root=false
 monkey_repo="$DEFAULT_REPO_MONKEY_HOME"
 monkey_version="dev"
 agent_binary_dir=""
@@ -302,7 +306,11 @@ case "$1" in
       missing_argument "$1"
     fi
     ;;
-   --branch)
+  --as-root)
+	as_root=true
+	shift
+	;;
+  --branch)
     if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
       branch=$2
       shift 2
@@ -336,7 +344,7 @@ case "$1" in
   esac
 done
 
-if is_root; then
+if ! $as_root && is_root; then
   log_message "Please don't run this script as root"
   exit 1
 fi

From 7ab7e56b4c64040be601096e2c4a9e2cd6743025 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Fri, 30 Apr 2021 07:40:05 -0400
Subject: [PATCH 18/26] appimage: Replace `apt` with `apt-get`

---
 appimage/build_appimage.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index f0b299da3..e48d22617 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -84,11 +84,11 @@ install_nodejs() {
 }
 
 install_build_prereqs() {
-  sudo apt update
-  sudo apt upgrade -y
+  sudo apt-get update
+  sudo apt-get upgrade -y
 
   # monkey island prereqs
-  sudo apt install -y curl libcurl4 openssl git build-essential moreutils
+  sudo apt-get install -y curl libcurl4 openssl git build-essential moreutils
   install_nodejs
 }
 

From 9f150bb51a304d9214f01471962a1dafd9eef8fa Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Fri, 30 Apr 2021 07:49:28 -0400
Subject: [PATCH 19/26] appimage: Remove references to deployment scripts in
 logging

---
 appimage/build_appimage.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index e48d22617..01c7dba44 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -73,7 +73,7 @@ handle_error() {
 
 log_message() {
   echo -e "\n\n"
-  echo -e "DEPLOYMENT SCRIPT: $1"
+  echo -e "APPIMAGE BUILDER: $1"
 }
 
 install_nodejs() {
@@ -344,6 +344,8 @@ case "$1" in
   esac
 done
 
+log_message "Building Monkey Island AppImage package."
+
 if ! $as_root && is_root; then
   log_message "Please don't run this script as root"
   exit 1
@@ -367,5 +369,5 @@ setup_appdir "$agent_binary_dir" "$monkey_repo"
 
 build_appimage "$monkey_version"
 
-log_message "Deployment script finished."
+log_message "AppImage build script finished."
 exit 0

From f87514cbbf816eb7a4536b48cc630e3bd1fe75ff Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Fri, 30 Apr 2021 08:18:55 -0400
Subject: [PATCH 20/26] appimage: Add a few log messages

---
 appimage/build_appimage.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index 01c7dba44..daac6e3a2 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -93,6 +93,7 @@ install_build_prereqs() {
 }
 
 install_appimage_tool() {
+  log_message "Installing appimagetool"
   APP_TOOL_BIN=$WORKSPACE/bin/appimagetool
 
   mkdir -p "$WORKSPACE"/bin
@@ -287,6 +288,7 @@ build_appimage() {
 }
 
 apply_version_to_appimage() {
+  log_message "Renaming Infection_Monkey-x86_64.AppImage -> Infection_Monkey-$1-x86_64.AppImage"
   mv "Infection_Monkey-x86_64.AppImage" "Infection_Monkey-$1-x86_64.AppImage"
 }
 

From c61b551545782ebd84b803f90528dc69f7155256 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Fri, 30 Apr 2021 10:12:24 -0400
Subject: [PATCH 21/26] appimage: Address minor shellcheck findings

---
 appimage/build_appimage.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index daac6e3a2..9520bbbc7 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -179,7 +179,7 @@ install_monkey_island_python_dependencies() {
   "$APPDIR"/AppRun -m pip install pipenv || handle_error
 
   requirements_island="$ISLAND_PATH/requirements.txt"
-  generate_requirements_from_pipenv_lock $requirements_island
+  generate_requirements_from_pipenv_lock "$requirements_island"
 
   log_message "Installing island python requirements"
   "$APPDIR"/AppRun -m pip install -r "${requirements_island}"  --ignore-installed || handle_error
@@ -187,16 +187,16 @@ install_monkey_island_python_dependencies() {
 
 generate_requirements_from_pipenv_lock () {
   log_message "Generating a requirements.txt file with 'pipenv lock -r'"
-  cd $ISLAND_PATH
+  cd "$ISLAND_PATH" || exit 1
   "$APPDIR"/AppRun -m pipenv --python "$APPDIR/AppRun" lock -r > "$1" || handle_error
-  cd -
+  cd - || exit 1
 }
 
 add_agent_binaries_to_appdir() {
   if [ -z "$1" ]; then
     download_monkey_agent_binaries_to_appdir
   else
-    copy_agent_binaries_to_appdir $1
+    copy_agent_binaries_to_appdir "$1"
   fi
 
   make_linux_binaries_executable

From 0192e089002786abf3b59b2c4957e2adde5b2c38 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Fri, 30 Apr 2021 10:15:27 -0400
Subject: [PATCH 22/26] appimage: Replace some tabs with spaces

---
 appimage/build_appimage.sh | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index 9520bbbc7..1244921f0 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -309,9 +309,9 @@ case "$1" in
     fi
     ;;
   --as-root)
-	as_root=true
-	shift
-	;;
+    as_root=true
+    shift
+    ;;
   --branch)
     if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
       branch=$2
@@ -319,10 +319,10 @@ case "$1" in
     else
       missing_argument "$1"
     fi
-	;;
+    ;;
   -h|--help)
-	echo_help
-	;;
+    echo_help
+    ;;
   --monkey-repo)
     if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
       monkey_repo=$2
@@ -340,9 +340,9 @@ case "$1" in
     fi
     ;;
   -*)
-	echo "Error: Unsupported parameter $1" >&2
-	exit 1
-	;;
+    echo "Error: Unsupported parameter $1" >&2
+    exit 1
+    ;;
   esac
 done
 

From de9d750e3cc9e882f6a21c495a1f0fb6248803bf Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Fri, 30 Apr 2021 10:26:01 -0400
Subject: [PATCH 23/26] Add PR #1136 to the changelog

---
 CHANGELOG.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 022fba9e4..deea868b4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - PostgreSQL fingerprinter. #892
 - A runtime-configurable option to specify a data directory where runtime
   configuration and other artifacts can be stored. #994
-- Scripts to build an AppImage for Monkey Island. #1069, #1090
+- Scripts to build an AppImage for Monkey Island. #1069, #1090, #1136
 
 ### Changed
 - server_config.json can be selected at runtime. #963

From 684a6f8171df4fc3379143f03ad070cfad23babd Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Mon, 3 May 2021 07:45:10 -0400
Subject: [PATCH 24/26] appimage: Match any unknown parameters (not just flags)

---
 appimage/build_appimage.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index 1244921f0..c7588e097 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -339,7 +339,7 @@ case "$1" in
       missing_argument "$1"
     fi
     ;;
-  -*)
+  *)
     echo "Error: Unsupported parameter $1" >&2
     exit 1
     ;;

From 998a14d248bd39110715e722fed57557518ea015 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Mon, 3 May 2021 09:28:40 -0400
Subject: [PATCH 25/26] appimage: reduce some duplication in argument parsing

---
 appimage/build_appimage.sh | 53 +++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 29 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index c7588e097..0a258e01d 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -20,9 +20,11 @@ APP_TOOL_URL=https://github.com/AppImage/AppImageKit/releases/download/12/appima
 PYTHON_VERSION="3.7.10"
 PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python${PYTHON_VERSION}-cp37-cp37m-manylinux1_x86_64.AppImage"
 
-missing_argument() {
-  echo "Error: Argument for $1 is missing" >&2
-  exit 1
+exit_if_missing_argument() {
+  if [ -z "$2" ] || [ "${2:0:1}" == "-" ]; then
+    echo "Error: Argument for $1 is missing" >&2
+    exit 1
+  fi
 }
 
 echo_help() {
@@ -292,52 +294,45 @@ apply_version_to_appimage() {
   mv "Infection_Monkey-x86_64.AppImage" "Infection_Monkey-$1-x86_64.AppImage"
 }
 
+agent_binary_dir=""
 as_root=false
+branch="develop"
 monkey_repo="$DEFAULT_REPO_MONKEY_HOME"
 monkey_version="dev"
-agent_binary_dir=""
-branch="develop"
+
 
 while (( "$#" )); do
 case "$1" in
   --agent-binary-dir)
-    if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
-      agent_binary_dir=$2
-      shift 2
-    else
-      missing_argument "$1"
-    fi
+    exit_if_missing_argument "$1" "$2"
+
+    agent_binary_dir=$2
+    shift 2
     ;;
   --as-root)
     as_root=true
     shift
     ;;
   --branch)
-    if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
-      branch=$2
-      shift 2
-    else
-      missing_argument "$1"
-    fi
+    exit_if_missing_argument "$1" "$2"
+
+    branch=$2
+    shift 2
     ;;
   -h|--help)
     echo_help
     ;;
   --monkey-repo)
-    if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
-      monkey_repo=$2
-      shift 2
-    else
-      missing_argument "$1"
-    fi
+    exit_if_missing_argument "$1" "$2"
+
+    monkey_repo=$2
+    shift 2
     ;;
   --version)
-    if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
-      monkey_version=$2
-      shift 2
-    else
-      missing_argument "$1"
-    fi
+    exit_if_missing_argument "$1" "$2"
+
+    monkey_version=$2
+    shift 2
     ;;
   *)
     echo "Error: Unsupported parameter $1" >&2

From f475df7c9c5671f670f31046e647a7108fdaa7bc Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Mon, 3 May 2021 09:32:07 -0400
Subject: [PATCH 26/26] appimage: fix spacing in argument parsing

---
 appimage/build_appimage.sh | 64 +++++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh
index 0a258e01d..866ba5a19 100755
--- a/appimage/build_appimage.sh
+++ b/appimage/build_appimage.sh
@@ -302,42 +302,42 @@ monkey_version="dev"
 
 
 while (( "$#" )); do
-case "$1" in
-  --agent-binary-dir)
-    exit_if_missing_argument "$1" "$2"
+  case "$1" in
+    --agent-binary-dir)
+      exit_if_missing_argument "$1" "$2"
 
-    agent_binary_dir=$2
-    shift 2
-    ;;
-  --as-root)
-    as_root=true
-    shift
-    ;;
-  --branch)
-    exit_if_missing_argument "$1" "$2"
+      agent_binary_dir=$2
+      shift 2
+      ;;
+    --as-root)
+      as_root=true
+      shift
+      ;;
+    --branch)
+      exit_if_missing_argument "$1" "$2"
 
-    branch=$2
-    shift 2
-    ;;
-  -h|--help)
-    echo_help
-    ;;
-  --monkey-repo)
-    exit_if_missing_argument "$1" "$2"
+      branch=$2
+      shift 2
+      ;;
+    -h|--help)
+      echo_help
+      ;;
+    --monkey-repo)
+      exit_if_missing_argument "$1" "$2"
 
-    monkey_repo=$2
-    shift 2
-    ;;
-  --version)
-    exit_if_missing_argument "$1" "$2"
+      monkey_repo=$2
+      shift 2
+      ;;
+    --version)
+      exit_if_missing_argument "$1" "$2"
 
-    monkey_version=$2
-    shift 2
-    ;;
-  *)
-    echo "Error: Unsupported parameter $1" >&2
-    exit 1
-    ;;
+      monkey_version=$2
+      shift 2
+      ;;
+    *)
+      echo "Error: Unsupported parameter $1" >&2
+      exit 1
+      ;;
   esac
 done