forked from p15670423/monkey
Build: Make error message formatting consistent
This commit is contained in:
parent
019bc56a73
commit
d5bb94f1a8
|
@ -9,6 +9,13 @@ SYSTEMD_DIR="/lib/systemd/system"
|
||||||
MONKEY_BIN="/opt/infection-monkey/bin"
|
MONKEY_BIN="/opt/infection-monkey/bin"
|
||||||
APPIMAGE_NAME="InfectionMonkey.AppImage"
|
APPIMAGE_NAME="InfectionMonkey.AppImage"
|
||||||
|
|
||||||
|
die() {
|
||||||
|
echo "$1" >&2
|
||||||
|
echo ""
|
||||||
|
echo_help
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
echo_help() {
|
echo_help() {
|
||||||
echo "Installs the Infection Monkey service to run on boot."
|
echo "Installs the Infection Monkey service to run on boot."
|
||||||
echo ""
|
echo ""
|
||||||
|
@ -82,8 +89,7 @@ user_exists() {
|
||||||
|
|
||||||
exit_if_user_doesnt_exist() {
|
exit_if_user_doesnt_exist() {
|
||||||
if ! user_exists "$1" ; then
|
if ! user_exists "$1" ; then
|
||||||
echo "Error: User '$1' does not exist"
|
die "Error: User '$1' does not exist."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,9 +101,7 @@ has_sudo() {
|
||||||
|
|
||||||
exit_if_missing_argument() {
|
exit_if_missing_argument() {
|
||||||
if [ -z "$2" ] || [ "${2:0:1}" == "-" ]; then
|
if [ -z "$2" ] || [ "${2:0:1}" == "-" ]; then
|
||||||
echo "Error: Argument for parameter '$1' is missing" >&2
|
die "Error: Argument for parameter '$1' is missing."
|
||||||
echo_help
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,26 +130,22 @@ while (( "$#" )); do
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Error: Unsupported parameter $1" >&2
|
die "Error: Unsupported parameter $1."
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if ! has_sudo; then
|
if ! has_sudo; then
|
||||||
echo "Error: You need root permissions for some of this script operations. \
|
die "Error: You need root permissions for some of this script operations. \
|
||||||
Run \`sudo -v\`, enter your password, and then re-run this script."
|
Run \`sudo -v\`, enter your password, and then re-run this script."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${APPIMAGE}" ] ; then
|
if [ -z "${APPIMAGE}" ] ; then
|
||||||
echo "Error: Missing 'APPIMAGE' environment variable. Try installing the Infection Monkey service through the AppImage"
|
die "Error: Missing 'APPIMAGE' environment variable. Try installing the Infection Monkey service through the AppImage"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $do_install && $do_uninstall ; then
|
if $do_install && $do_uninstall ; then
|
||||||
echo "The --install and --uninstall flags are mutually exclusive."
|
die "Error: The --install and --uninstall flags are mutually exclusive."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $do_uninstall ; then
|
if $do_uninstall ; then
|
||||||
|
@ -155,15 +155,11 @@ fi
|
||||||
|
|
||||||
if $do_install ; then
|
if $do_install ; then
|
||||||
if [ -z "$username" ] ; then
|
if [ -z "$username" ] ; then
|
||||||
echo "You must supply a username."
|
die "Error: You must supply a username."
|
||||||
echo ""
|
|
||||||
echo_help
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
install_service "$username"
|
install_service "$username"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "You must specify either the --install or --uninstall flag"
|
die "Error:You must specify either the --install or --uninstall flag."
|
||||||
exit 1
|
|
||||||
|
|
Loading…
Reference in New Issue