Improve help output and error messages

This commit is contained in:
Michael Boelen 2016-05-14 17:42:33 +02:00
parent be5e9f6e54
commit b72b510301
1 changed files with 77 additions and 44 deletions

View File

@ -47,19 +47,48 @@ lynis show ${BROWN}version${NORMAL} (${PROGRAM_NAME} version)"
AUDIT_ARGS="( dockerfile | system )"
AUDIT_HELP="
audit ${CYAN}dockerfile${NORMAL}
${WHITE}lynis audit <target>${NORMAL}
Perform audit on a Docker build file
${GRAY}Usage:${NORMAL} lynis audit dockerfile ${BROWN}<file>${NORMAL}
${CYAN}audit dockerfile ${BROWN}<file>${NORMAL}
Perform security audit on a Docker build file
${GRAY}Example:${NORMAL}
lynis audit dockerfile Dockerfile
audit ${CYAN}system${NORMAL}
${CYAN}audit system ${GRAY}[options]${NORMAL}
Perform security system audit
${GRAY}Examples:${NORMAL}
lynis audit system
lynis audit system --cronjob
lynis audit system --profile developer.prf
lynis audit system --quick
${CYAN}audit system remote ${BROWN}<target> ${GRAY}[options]${NORMAL}
Perform security system audit on a remote target
${GRAY}Examples:${NORMAL}
lynis audit system remote 192.168.1.100
lynis audit system remote 192.168.1.100 --no-colors
Perform system audit
${DARKGRAY}Usage:${NORMAL} lynis audit system
"
UPDATE_ARGS="info release"
UPDATE_HELP="
${CYAN}update info${NORMAL}
Check version information
${CYAN}update release${NORMAL}
Perform update of release
"
SHOW_TESTS_ARGS="skipped"
@ -70,30 +99,30 @@ if [ $# -gt 0 ]; then
case $1 in
"commands")
if [ $# -eq 1 ]; then
echo "\n${WHITE}Commands:${NORMAL}"
${ECHOCMD} "\n${WHITE}Commands:${NORMAL}"
for I in ${COMMANDS}; do
echo "lynis ${CYAN}${I}${NORMAL}"
${ECHOCMD} "lynis ${CYAN}${I}${NORMAL}"
done
echo ""
${ECHOCMD} ""
else
shift
if [ $# -eq 1 ]; then
case $1 in
"audit") echo "${AUDIT_HELP}" ;;
"show") echo "${SHOW_HELP}" ;;
*) echo "Unknown argument for 'commands'"
"audit") ${ECHOCMD} "${AUDIT_HELP}" ;;
"show") ${ECHOCMD} "${SHOW_HELP}" ;;
*) ${ECHOCMD} "Unknown argument for 'commands'"
esac
else
shift
case $1 in
"dockerfile")
echo "Usage: lynis audit dockerfile <file>"
${ECHOCMD} "Usage: lynis audit dockerfile <file>"
;;
"system")
echo "${COMMANDS_AUDIT_SYSTEM_USAGE}\n${COMMANDS_AUDIT_SYSTEM_FUNCTION}\n"
${ECHOCMD} "${COMMANDS_AUDIT_SYSTEM_USAGE}\n${COMMANDS_AUDIT_SYSTEM_FUNCTION}\n"
;;
*)
echo "Unknown argument for 'commands'"
${ECHOCMD} "Unknown argument for 'commands'"
;;
esac
fi
@ -101,57 +130,61 @@ if [ $# -gt 0 ]; then
;;
"help")
if [ $# -eq 1 ]; then
echo "${WHITE}Commands${NORMAL}:"
${ECHOCMD} "${PROGRAM_NAME} ${PROGRAM_VERSION} - Help"
${ECHOCMD} "=========================="
${ECHOCMD} ""
${ECHOCMD} "${WHITE}Commands${NORMAL}:"
for I in ${COMMANDS}; do
echo "lynis ${CYAN}${I}${NORMAL}"
${ECHOCMD} "${CYAN}${I}${NORMAL}"
done
echo ""
echo "${WHITE}Options${NORMAL}:\n${BLUE}${OPTIONS}${NORMAL}"
${ECHOCMD} ""
${ECHOCMD} "Use 'lynis show help <command>' to see details"
${ECHOCMD} ""; ${ECHOCMD} ""
${ECHOCMD} "${WHITE}Options${NORMAL}:\n${GRAY}${OPTIONS}${NORMAL}"
else
shift
case $1 in
"audit") echo "${AUDIT_HELP}" ;;
"show") echo "${SHOW_ARGS}" ;;
"update") echo "${UPDATE_ARGS}" ;;
"?") echo "${SHOW_ARGS}" ;;
*) echo "Invalid argument provided for lynis show help" ;;
"audit") ${ECHOCMD} "${AUDIT_HELP}" ;;
"show") ${ECHOCMD} "${SHOW_HELP}" ;;
"update") ${ECHOCMD} "${UPDATE_HELP}" ;;
"?") ${ECHOCMD} "${SHOW_ARGS}" ;;
*) ${ECHOCMD} "Invalid argument provided for lynis show help" ;;
esac
fi
;;
"license") echo "${PROGRAM_LICENSE}" ;;
"man") echo "Use ./lynis --man or man lynis" ;;
"options") echo "${OPTIONS}" ;;
"pidfile") echo "${PIDFILE}" ;;
"profile" | "profiles") for I in ${PROFILES}; do echo ${I}; done ;;
"plugindir") echo "${PLUGINDIR}" ;;
"release" | "version") echo "${PROGRAM_VERSION}" ;;
"releasedate") echo "${PROGRAM_RELEASE_DATE}" ;;
"license") ${ECHOCMD} "${PROGRAM_LICENSE}" ;;
"man") ${ECHOCMD} "Use ./lynis --man or man lynis" ;;
"options") ${ECHOCMD} "${OPTIONS}" ;;
"pidfile") ${ECHOCMD} "${PIDFILE}" ;;
"profile" | "profiles") for I in ${PROFILES}; do ${ECHOCMD} ${I}; done ;;
"plugindir") ${ECHOCMD} "${PLUGINDIR}" ;;
"release" | "version") ${ECHOCMD} "${PROGRAM_VERSION}" ;;
"releasedate") ${ECHOCMD} "${PROGRAM_RELEASE_DATE}" ;;
"tests")
if [ $# -gt 0 ]; then
shift
case $1 in
"skipped") echo "${SKIP_TESTS}" ;;
*) echo "Invalid argument provided to lynis show tests\n\n"
echo "Suggestions:\n"
for I in ${SHOW_TESTS_ARGS}; do
echo "lynis show tests ${I}"
done
"skipped") ${ECHOCMD} "${SKIP_TESTS}" ;;
*)
${ECHOCMD} "Invalid argument provided to lynis show tests\n\n"
${ECHOCMD} "Suggestions:\n"
for I in ${SHOW_TESTS_ARGS}; do ${ECHOCMD} "lynis show tests ${I}"; done
;;
esac
else
echo "Need more arguments"
${ECHOCMD} "Need more arguments"
fi
;;
"?") echo "${SHOW_ARGS}" ;;
*) echo "Unknown option" ;;
"?") ${ECHOCMD} "${SHOW_ARGS}" ;;
*) ${ECHOCMD} "Unknown argument '$1'" ;;
esac
else
echo "\n ${WHITE}Provide an additional argument${NORMAL}\n\n"
${ECHOCMD} "\n ${WHITE}Provide an additional argument${NORMAL}\n\n"
for I in ${SHOW_ARGS}; do
echo " lynis show ${BROWN}${I}${NORMAL}"
${ECHOCMD} " lynis show ${BROWN}${I}${NORMAL}"
done
echo "\n"
${ECHOCMD} "\n"
fi