Build: Use $APPIMAGE instead of --path during service installation

This commit is contained in:
EliaOnceAgain 2022-05-02 22:09:41 +03:00 committed by Mike Salvatore
parent 02916a25f3
commit 0287f58d8d
1 changed files with 17 additions and 26 deletions

View File

@ -2,6 +2,7 @@
set -e set -e
SCRIPT_NAME="$(basename "${APPIMAGE}")"
SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
SYSTEMD_UNIT_FILENAME="infection-monkey.service" SYSTEMD_UNIT_FILENAME="infection-monkey.service"
SYSTEMD_DIR="/lib/systemd/system" SYSTEMD_DIR="/lib/systemd/system"
@ -12,18 +13,17 @@ echo_help() {
echo "Installs the Infection Monkey service to run on boot." echo "Installs the Infection Monkey service to run on boot."
echo "" echo ""
echo "Usage:" echo "Usage:"
echo " install-infection-monkey-service.sh --user <USERNAME> --appimage <PATH>" echo " ${SCRIPT_NAME} service --user <USERNAME>"
echo " install-infection-monkey-service.sh --uninstall" echo " ${SCRIPT_NAME} service --uninstall"
echo " install-infection-monkey-service.sh -h|--help" echo " ${SCRIPT_NAME} service -h|--help"
echo "" echo ""
echo "Options:" echo "Options:"
echo " --user User to run the service as" echo " --user Install Infection Monkey service and run as User"
echo " --appimage Path to AppImage" echo " --uninstall Uninstall Infection Monkey service"
echo " --uninstall Uninstall the Infection Monkey service"
} }
install_service() { install_service() {
move_appimage "$2" move_appimage
cat > "${SCRIPT_DIR}/${SYSTEMD_UNIT_FILENAME}" << EOF cat > "${SCRIPT_DIR}/${SYSTEMD_UNIT_FILENAME}" << EOF
[Unit] [Unit]
@ -65,9 +65,9 @@ uninstall_service() {
move_appimage() { move_appimage() {
sudo mkdir --mode=0755 -p "${MONKEY_BIN}" sudo mkdir --mode=0755 -p "${MONKEY_BIN}"
if [ "$1" != "${MONKEY_BIN}/${APPIMAGE_NAME}" ] ; then if [ "${APPIMAGE}" != "${MONKEY_BIN}/${APPIMAGE_NAME}" ] ; then
umask 022 umask 022
sudo cp "$appimage_path" "${MONKEY_BIN}/${APPIMAGE_NAME}" sudo cp "${APPIMAGE}" "${MONKEY_BIN}/${APPIMAGE_NAME}"
sudo chmod 755 "${MONKEY_BIN}/${APPIMAGE_NAME}" sudo chmod 755 "${MONKEY_BIN}/${APPIMAGE_NAME}"
fi fi
} }
@ -100,21 +100,16 @@ exit_if_missing_argument() {
do_uninstall=false do_uninstall=false
uname="" uname=""
appimage_path=""
while (( "$#" )); do while (( "$#" )); do
case "$1" in case "$1" in
--user) --user)
exit_if_missing_argument "$1" "$2" exit_if_missing_argument "$1" "$2"
uname=$2 uname=$2
shift 2 shift 2
;; ;;
--appimage) --install)
exit_if_missing_argument "$1" "$2" shift
appimage_path=$2
shift 2
;; ;;
--uninstall) --uninstall)
do_uninstall=true do_uninstall=true
@ -137,25 +132,21 @@ Run \`sudo -v\`, enter your password, and then re-run this script."
exit 1 exit 1
fi fi
if [ -z "${APPIMAGE}" ] ; then
echo "Error: Missing 'APPIMAGE' environment variable. Try installing the Infection Monkey service through the AppImage"
exit 1
fi
if $do_uninstall ; then if $do_uninstall ; then
uninstall_service uninstall_service
exit 0 exit 0
fi fi
assert_parameter_supplied "--user" "$uname" assert_parameter_supplied "--user" "$uname"
assert_parameter_supplied "--appimage" "$appimage_path"
if ! user_exists "$uname" ; then if ! user_exists "$uname" ; then
echo "Error: User '$uname' does not exist" echo "Error: User '$uname' does not exist"
exit 1 exit 1
fi fi
if [ ! -f "$appimage_path" ] ; then install_service "$uname"
if [ ! -f "${SCRIPT_DIR}/$appimage_path" ] ; then
echo "Error: AppImage '$appimage_path' does not exist"
exit 1
fi
appimage_path="${SCRIPT_DIR}/$appimage_path"
fi
install_service "$uname" "$appimage_path"