2021-07-28 02:04:35 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-07-29 03:54:20 +08:00
|
|
|
LINUXDEPLOY_URL="https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage"
|
2022-03-23 07:34:25 +08:00
|
|
|
PYTHON_VERSION="3.7.13"
|
2021-07-28 02:04:35 +08:00
|
|
|
PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python${PYTHON_VERSION}-cp37-cp37m-manylinux1_x86_64.AppImage"
|
2022-06-09 23:25:25 +08:00
|
|
|
APPIMAGE_DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
|
2021-07-29 03:54:20 +08:00
|
|
|
APPDIR="$APPIMAGE_DIR/squashfs-root"
|
|
|
|
BUILD_DIR="$APPDIR/usr/src"
|
|
|
|
|
|
|
|
ICON_PATH="$BUILD_DIR/monkey_island/cc/ui/src/images/monkey-icon.svg"
|
|
|
|
MONGO_PATH="$BUILD_DIR/monkey_island/bin/mongodb"
|
2021-07-28 02:04:35 +08:00
|
|
|
|
|
|
|
source "$APPIMAGE_DIR/../common.sh"
|
|
|
|
|
|
|
|
install_package_specific_build_prereqs() {
|
2021-07-29 03:54:20 +08:00
|
|
|
log_message "Installing linuxdeploy"
|
2021-07-28 02:04:35 +08:00
|
|
|
WORKSPACE_BIN_DIR="$1/bin"
|
2021-07-29 03:54:20 +08:00
|
|
|
LINUXDEPLOY_BIN="$WORKSPACE_BIN_DIR/linuxdeploy"
|
2021-07-28 02:04:35 +08:00
|
|
|
|
|
|
|
mkdir -p "$WORKSPACE_BIN_DIR"
|
2021-07-29 03:54:20 +08:00
|
|
|
curl -L -o "$LINUXDEPLOY_BIN" "$LINUXDEPLOY_URL"
|
|
|
|
chmod u+x "$LINUXDEPLOY_BIN"
|
2021-07-28 02:04:35 +08:00
|
|
|
|
|
|
|
PATH=$PATH:$WORKSPACE_BIN_DIR
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_build_dir() {
|
|
|
|
local agent_binary_dir=$1
|
|
|
|
local monkey_repo=$2
|
2021-09-15 20:13:26 +08:00
|
|
|
local deployment_type=$3
|
2022-04-12 20:43:15 +08:00
|
|
|
local is_release_build=$4
|
2021-07-28 02:04:35 +08:00
|
|
|
|
2022-06-09 23:22:37 +08:00
|
|
|
pushd "$APPIMAGE_DIR" || handle_error
|
2021-07-28 02:04:35 +08:00
|
|
|
|
2021-07-29 03:54:20 +08:00
|
|
|
setup_python_37_appdir
|
2021-07-28 02:04:35 +08:00
|
|
|
|
2021-07-29 03:54:20 +08:00
|
|
|
mkdir -p "$BUILD_DIR"
|
2021-07-28 02:04:35 +08:00
|
|
|
|
2021-07-29 03:54:20 +08:00
|
|
|
copy_monkey_island_to_build_dir "$monkey_repo/monkey" "$BUILD_DIR"
|
|
|
|
copy_server_config_to_build_dir
|
2022-05-02 07:35:06 +08:00
|
|
|
copy_infection_monkey_service_to_build_dir
|
2021-09-15 20:13:26 +08:00
|
|
|
modify_deployment "$deployment_type" "$BUILD_DIR"
|
2021-07-29 03:54:20 +08:00
|
|
|
add_agent_binaries_to_build_dir "$agent_binary_dir" "$BUILD_DIR"
|
2021-07-28 02:04:35 +08:00
|
|
|
|
2021-07-29 03:54:20 +08:00
|
|
|
install_monkey_island_python_dependencies
|
|
|
|
install_mongodb
|
2021-07-28 02:04:35 +08:00
|
|
|
|
2021-07-29 03:54:20 +08:00
|
|
|
generate_ssl_cert "$BUILD_DIR"
|
2022-04-12 20:43:15 +08:00
|
|
|
build_frontend "$BUILD_DIR" "$is_release_build"
|
2021-07-28 02:04:35 +08:00
|
|
|
|
2021-07-29 03:54:20 +08:00
|
|
|
remove_python_appdir_artifacts
|
2021-07-28 02:04:35 +08:00
|
|
|
|
2022-06-09 23:18:18 +08:00
|
|
|
popd || handle_error
|
2021-07-28 02:04:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
setup_python_37_appdir() {
|
|
|
|
PYTHON_APPIMAGE="python${PYTHON_VERSION}_x86_64.AppImage"
|
|
|
|
|
|
|
|
log_message "downloading Python3.7 Appimage"
|
|
|
|
curl -L -o "$PYTHON_APPIMAGE" "$PYTHON_APPIMAGE_URL"
|
|
|
|
|
|
|
|
chmod u+x "$PYTHON_APPIMAGE"
|
|
|
|
|
|
|
|
"./$PYTHON_APPIMAGE" --appimage-extract
|
|
|
|
rm "$PYTHON_APPIMAGE"
|
|
|
|
}
|
|
|
|
|
2022-05-02 07:35:06 +08:00
|
|
|
copy_infection_monkey_service_to_build_dir() {
|
|
|
|
cp "$APPIMAGE_DIR"/install-infection-monkey-service.sh "$APPDIR"
|
|
|
|
}
|
|
|
|
|
2021-07-28 02:04:35 +08:00
|
|
|
copy_server_config_to_build_dir() {
|
2022-05-02 07:35:06 +08:00
|
|
|
cp "$APPIMAGE_DIR"/server_config.json.standard "$BUILD_DIR"/monkey_island/cc/server_config.json
|
2021-07-28 02:04:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
install_monkey_island_python_dependencies() {
|
|
|
|
log_message "Installing island requirements"
|
|
|
|
|
|
|
|
log_message "Installing pipenv"
|
2022-08-17 20:29:23 +08:00
|
|
|
"$APPDIR"/AppRun -m pip install pipenv==2022.7.4 || handle_error
|
2022-08-17 20:52:17 +08:00
|
|
|
export CI=1
|
2021-07-28 02:04:35 +08:00
|
|
|
|
2022-06-09 23:15:07 +08:00
|
|
|
log_message "Installing dependencies"
|
|
|
|
pushd "$BUILD_DIR/monkey_island" || handle_error
|
|
|
|
"$APPDIR"/AppRun -m pipenv --python "$APPDIR/AppRun" sync --system || handle_error
|
|
|
|
popd || handle_error
|
2022-06-09 23:27:41 +08:00
|
|
|
|
|
|
|
log_message "Uninstalling pipenv (build dependency only)"
|
2022-06-09 23:35:25 +08:00
|
|
|
"$APPDIR"/AppRun -m pip uninstall --yes pipenv virtualenv || handle_error
|
2021-07-28 02:04:35 +08:00
|
|
|
}
|
|
|
|
|
2021-07-29 03:54:20 +08:00
|
|
|
|
2021-07-28 02:04:35 +08:00
|
|
|
install_mongodb() {
|
|
|
|
log_message "Installing MongoDB"
|
|
|
|
|
2021-07-29 03:54:20 +08:00
|
|
|
mkdir -p "$MONGO_PATH"
|
|
|
|
"$BUILD_DIR/monkey_island/linux/install_mongo.sh" "${MONGO_PATH}" || handle_error
|
2021-07-28 02:04:35 +08:00
|
|
|
}
|
|
|
|
|
2021-07-29 03:54:20 +08:00
|
|
|
remove_python_appdir_artifacts() {
|
|
|
|
rm "$APPDIR"/python.png
|
|
|
|
rm "$APPDIR"/python*.desktop
|
|
|
|
rm "$APPDIR"/AppRun
|
2021-07-28 02:04:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
build_package() {
|
2022-06-03 19:10:47 +08:00
|
|
|
local version=$1
|
|
|
|
local dist_dir=$2
|
2021-07-29 03:54:20 +08:00
|
|
|
|
2021-07-28 02:04:35 +08:00
|
|
|
log_message "Building AppImage"
|
2021-10-22 00:19:08 +08:00
|
|
|
|
2022-06-09 23:18:18 +08:00
|
|
|
pushd "$APPIMAGE_DIR" || handle_error
|
2021-07-29 03:54:20 +08:00
|
|
|
ARCH="x86_64" linuxdeploy \
|
|
|
|
--appdir "$APPIMAGE_DIR/squashfs-root" \
|
|
|
|
--icon-file "$ICON_PATH" \
|
|
|
|
--desktop-file "$APPIMAGE_DIR/infection-monkey.desktop" \
|
|
|
|
--custom-apprun "$APPIMAGE_DIR/AppRun" \
|
|
|
|
--deploy-deps-only="$MONGO_PATH/bin/mongod"\
|
|
|
|
--output appimage
|
2021-07-28 19:53:33 +08:00
|
|
|
|
2021-10-22 00:19:08 +08:00
|
|
|
dst_name="InfectionMonkey-$version.AppImage"
|
2022-06-09 23:22:37 +08:00
|
|
|
move_package_to_dist_dir "$dist_dir" "$dst_name"
|
2021-07-28 02:04:35 +08:00
|
|
|
|
2022-06-09 23:18:18 +08:00
|
|
|
popd || handle_error
|
2021-07-28 02:04:35 +08:00
|
|
|
}
|
|
|
|
|
2021-07-28 19:53:33 +08:00
|
|
|
move_package_to_dist_dir() {
|
2021-10-21 23:25:00 +08:00
|
|
|
mv Infection*Monkey*.AppImage "$1/$2"
|
2021-07-28 19:53:33 +08:00
|
|
|
}
|
2022-06-03 19:10:47 +08:00
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
echo "Cleaning appimage build dirs"
|
|
|
|
|
|
|
|
rm -rf "$APPIMAGE_DIR/squashfs-root"
|
|
|
|
}
|