forked from p15670423/monkey
Merge branch 'package-appimage-with-linuxdeploy' into develop
Pull Request #1381
This commit is contained in:
commit
1194834fea
|
@ -1,20 +1,25 @@
|
|||
#!/bin/bash
|
||||
|
||||
APP_TOOL_URL=https://github.com/AppImage/AppImageKit/releases/download/12/appimagetool-x86_64.AppImage
|
||||
LINUXDEPLOY_URL="https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage"
|
||||
PYTHON_VERSION="3.7.11"
|
||||
PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python${PYTHON_VERSION}-cp37-cp37m-manylinux1_x86_64.AppImage"
|
||||
APPIMAGE_DIR="$(realpath $(dirname $BASH_SOURCE[0]))"
|
||||
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"
|
||||
|
||||
source "$APPIMAGE_DIR/../common.sh"
|
||||
|
||||
install_package_specific_build_prereqs() {
|
||||
log_message "Installing appimagetool"
|
||||
log_message "Installing linuxdeploy"
|
||||
WORKSPACE_BIN_DIR="$1/bin"
|
||||
APP_TOOL_BIN="$WORKSPACE_BIN_DIR/appimagetool"
|
||||
LINUXDEPLOY_BIN="$WORKSPACE_BIN_DIR/linuxdeploy"
|
||||
|
||||
mkdir -p "$WORKSPACE_BIN_DIR"
|
||||
curl -L -o "$APP_TOOL_BIN" "$APP_TOOL_URL"
|
||||
chmod u+x "$APP_TOOL_BIN"
|
||||
curl -L -o "$LINUXDEPLOY_BIN" "$LINUXDEPLOY_URL"
|
||||
chmod u+x "$LINUXDEPLOY_BIN"
|
||||
|
||||
PATH=$PATH:$WORKSPACE_BIN_DIR
|
||||
}
|
||||
|
@ -22,28 +27,24 @@ install_package_specific_build_prereqs() {
|
|||
setup_build_dir() {
|
||||
local agent_binary_dir=$1
|
||||
local monkey_repo=$2
|
||||
local appdir=$APPIMAGE_DIR/squashfs-root
|
||||
local build_dir="$appdir/usr/src"
|
||||
|
||||
pushd $APPIMAGE_DIR
|
||||
|
||||
setup_python_37_appdir $build_dir
|
||||
setup_python_37_appdir
|
||||
|
||||
mkdir -p "$build_dir"
|
||||
mkdir -p "$BUILD_DIR"
|
||||
|
||||
copy_monkey_island_to_build_dir "$monkey_repo/monkey" $build_dir
|
||||
copy_server_config_to_build_dir $build_dir
|
||||
add_agent_binaries_to_build_dir "$agent_binary_dir" "$build_dir"
|
||||
copy_monkey_island_to_build_dir "$monkey_repo/monkey" "$BUILD_DIR"
|
||||
copy_server_config_to_build_dir
|
||||
add_agent_binaries_to_build_dir "$agent_binary_dir" "$BUILD_DIR"
|
||||
|
||||
install_monkey_island_python_dependencies "$appdir" "$build_dir"
|
||||
install_mongodb "$build_dir"
|
||||
install_monkey_island_python_dependencies
|
||||
install_mongodb
|
||||
|
||||
generate_ssl_cert "$build_dir"
|
||||
build_frontend "$build_dir"
|
||||
generate_ssl_cert "$BUILD_DIR"
|
||||
build_frontend "$BUILD_DIR"
|
||||
|
||||
add_monkey_icon "$appdir" "$monkey_repo"
|
||||
add_desktop_file "$appdir"
|
||||
add_apprun "$appdir"
|
||||
remove_python_appdir_artifacts
|
||||
|
||||
popd
|
||||
}
|
||||
|
@ -61,75 +62,61 @@ setup_python_37_appdir() {
|
|||
}
|
||||
|
||||
copy_server_config_to_build_dir() {
|
||||
cp "$APPIMAGE_DIR"/server_config.json.standard "$1"/monkey_island/cc/server_config.json
|
||||
cp "$APPIMAGE_DIR"/server_config.json.standard "$BUILD_DIR"/monkey_island/cc/server_config.json
|
||||
}
|
||||
|
||||
install_monkey_island_python_dependencies() {
|
||||
local appdir=$1
|
||||
local build_dir=$2
|
||||
log_message "Installing island requirements"
|
||||
|
||||
log_message "Installing pipenv"
|
||||
"$appdir"/AppRun -m pip install pipenv || handle_error
|
||||
"$APPDIR"/AppRun -m pip install pipenv || handle_error
|
||||
|
||||
requirements_island="$build_dir/monkey_island/requirements.txt"
|
||||
generate_requirements_from_pipenv_lock "$appdir" "$build_dir" "$requirements_island"
|
||||
requirements_island="$BUILD_DIR/monkey_island/requirements.txt"
|
||||
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
|
||||
"$APPDIR"/AppRun -m pip install -r "${requirements_island}" --ignore-installed || handle_error
|
||||
}
|
||||
|
||||
generate_requirements_from_pipenv_lock () {
|
||||
local appdir=$1
|
||||
local build_dir=$2
|
||||
local requirements_island=$3
|
||||
local requirements_island=$1
|
||||
|
||||
log_message "Generating a requirements.txt file with 'pipenv lock -r'"
|
||||
pushd "$build_dir/monkey_island"
|
||||
"$appdir"/AppRun -m pipenv --python "$appdir/AppRun" lock -r > "$requirements_island" || handle_error
|
||||
pushd "$BUILD_DIR/monkey_island"
|
||||
"$APPDIR"/AppRun -m pipenv --python "$APPDIR/AppRun" lock -r > "$requirements_island" || handle_error
|
||||
popd
|
||||
}
|
||||
|
||||
|
||||
install_mongodb() {
|
||||
local build_dir=$1
|
||||
local mongo_path="$build_dir/monkey_island/bin/mongodb"
|
||||
log_message "Installing MongoDB"
|
||||
|
||||
mkdir -p "$mongo_path"
|
||||
"$build_dir/monkey_island/linux/install_mongo.sh" "${mongo_path}" || handle_error
|
||||
mkdir -p "$MONGO_PATH"
|
||||
"$BUILD_DIR/monkey_island/linux/install_mongo.sh" "${MONGO_PATH}" || handle_error
|
||||
}
|
||||
|
||||
add_monkey_icon() {
|
||||
local appdir=$1
|
||||
local monkey_repo=$2
|
||||
|
||||
unlink "$appdir"/python.png
|
||||
mkdir -p "$appdir"/usr/share/icons
|
||||
cp "$monkey_repo"/monkey/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() {
|
||||
local appdir=$1
|
||||
|
||||
unlink "$appdir"/python*.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 "$1"
|
||||
remove_python_appdir_artifacts() {
|
||||
rm "$APPDIR"/python.png
|
||||
rm "$APPDIR"/python*.desktop
|
||||
rm "$APPDIR"/AppRun
|
||||
}
|
||||
|
||||
build_package() {
|
||||
local version=$1
|
||||
local dist_dir=$2
|
||||
|
||||
log_message "Building AppImage"
|
||||
pushd "$APPIMAGE_DIR"
|
||||
|
||||
ARCH="x86_64" appimagetool "$APPIMAGE_DIR/squashfs-root"
|
||||
apply_version_to_appimage "$version"
|
||||
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
|
||||
|
||||
apply_version_to_appimage "$version"
|
||||
move_package_to_dist_dir $dist_dir
|
||||
|
||||
popd
|
||||
|
|
|
@ -9,3 +9,4 @@ rm -rf "$HOME/git/monkey"
|
|||
rm -rf "$HOME/.monkey_island"
|
||||
rm -rf "$APPIMAGE_DIR/squashfs-root"
|
||||
rm "$APPIMAGE_DIR"/Infection_Monkey*x86_64.AppImage
|
||||
rm "$APPIMAGE_DIR/../dist/Infection_Monkey*x86_64.AppImage"
|
||||
|
|
|
@ -3,6 +3,6 @@ Type=Application
|
|||
Name=Infection Monkey
|
||||
Exec=bash
|
||||
Comment=An automated breach and attack simulation platform
|
||||
Icon=infection-monkey
|
||||
Icon=monkey-icon
|
||||
Categories=Development;
|
||||
Terminal=true
|
||||
|
|
|
@ -11,3 +11,4 @@ rm -rf "$DOCKER_DIR/monkey"
|
|||
rm -rf "$DOCKER_DIR/tgz"
|
||||
rm "$DOCKER_DIR"/dk.monkeyisland.*.tar
|
||||
rm "$DOCKER_DIR"/infection_monkey_docker*.tgz
|
||||
rm "$DOCKER_DIR"/../dist/infection_monkey_docker*.tgz
|
||||
|
|
Loading…
Reference in New Issue