Alignment, restructuring, and quoting of -? option

This commit is contained in:
Michael Boelen 2016-05-11 15:12:37 +02:00
parent 50609242c2
commit 668a1fd0e5

View File

@ -23,6 +23,9 @@
################################################################################# #################################################################################
# #
echo $#
echo $@
# Check number of parameters submitted (at least one is needed) # Check number of parameters submitted (at least one is needed)
PARAMCOUNT=$# PARAMCOUNT=$#
while [ $# -ge 1 ]; do while [ $# -ge 1 ]; do
@ -114,213 +117,206 @@
fi fi
;; ;;
# Assign auditor to report # Assign auditor to report
--auditor) --auditor)
shift shift
AUDITORNAME=$1 AUDITORNAME=$1
;; ;;
# Perform tests (deprecated, use audit system) # Perform tests (deprecated, use audit system)
-c | --check-all | --checkall) --check-all | --checkall | -c)
# echo "Usage of option -c is deprecated. Please use: lynis audit system [options]" # echo "Usage of option -c is deprecated. Please use: lynis audit system [options]"
CHECK=1 CHECK=1
;; ;;
# Cronjob support # Cronjob support
--cronjob | --cron) --cronjob | --cron)
CRONJOB=1; CRONJOB=1
# Use some defaults (-c, -Q, no colors) CHECK=1; QUICKMODE=1; NEVERBREAK=1 # Use some defaults (-c, -Q, no colors)
CHECK=1; QUICKMODE=1; NEVERBREAK=1 NORMAL=""; WARNING=""; SECTION=""; NOTICE=""; OK=""; BAD=""; CYAN=""; MAGENTA=""; PURPLE=""; YELLOW=""; WHITE=""; GREEN=""; RED="" # Remove colors
# Get rid of the colors ;;
NORMAL=""; WARNING=""; SECTION=""; NOTICE=""; OK=""; BAD=""; CYAN=""; MAGENTA=""; PURPLE=""; YELLOW=""; WHITE=""; GREEN=""; RED=""
;;
# Perform tests with additional debugging information on screen # Perform tests with additional debugging information on screen
--debug) --debug)
DEBUG=1 DEBUG=1
;; ;;
# Developer mode (more details when creating tests) # Developer mode (more details when creating tests)
--developer) --developer)
DEVELOPER_MODE=1 DEVELOPER_MODE=1
;; ;;
# Display all available options with short alias # Display all available options with short alias
--dump-options | --dumpoptions) --dump-options | --dumpoptions)
OPTIONS="--auditor OPTIONS="--auditor
--check-all_(-c) --config --cronjob_(--cron) --check-all_(-c) --config --cronjob_(--cron)
--debug --debug
--help_(-h) --help_(-h)
--info --info
--license-key --log-file --license-key --log-file
--manpage_(--man) --manpage_(--man)
--no-colors --no-log --no-colors --no-log
--pentest --profile --plugins-dir --pentest --profile --plugins-dir
--quiet_(-q) --quick_(-Q) --quiet_(-q) --quick_(-Q)
--report-file --reverse-colors --report-file --reverse-colors
--tests --tests-category --tests --tests-category
--upload --upload
--version_(-V) --view-categories" --version_(-V) --view-categories"
for I in ${OPTIONS}; do for I in ${OPTIONS}; do
echo "${I}" | tr '_' ' ' echo "${I}" | tr '_' ' '
done done
ExitClean ExitClean
;; ;;
# View help
--help | -h | -?)
VIEWHELP=1
;;
# View program/database information # View help
--check-update | --check-updates | --info) --help | -h | "-?")
echo "This option is deprecated" VIEWHELP=1
echo "Use: lynis update info" ;;
ExitClean
;;
# License key for Lynis Enterprise # View program/database information
--license-key) --check-update | --check-updates | --info)
shift echo "This option is deprecated"
LICENSE_KEY=$1 echo "Use: lynis update info"
;; ExitClean
;;
# Adjust default logfile location # License key for Lynis Enterprise
--logfile | --log-file) --license-key)
shift shift
LOGFILE=$1 LICENSE_KEY=$1
;; ;;
# Don't use colors # Adjust default logfile location
--no-colors | --nocolors) --logfile | --log-file)
NORMAL=""; WARNING=""; SECTION=""; NOTICE=""; OK=""; BAD=""; CYAN=""; MAGENTA=""; PURPLE=""; YELLOW=""; WHITE=""; GREEN=""; RED="" shift
;; LOGFILE=$1
;;
# Disable logging # Don't use colors
--no-log | --nolog) --no-colors | --nocolors)
LOGFILE="/dev/null" NORMAL=""; WARNING=""; SECTION=""; NOTICE=""; OK=""; BAD=""; CYAN=""; MAGENTA=""; PURPLE=""; YELLOW=""; WHITE=""; GREEN=""; RED=""
;; ;;
--pentest | --pen-test) # Disable logging
PENTESTINGMODE=1 --no-log | --nolog)
;; LOGFILE="/dev/null"
;;
# Define a custom profile file --pen-test | --pentest)
--profile) PENTESTINGMODE=1
shift ;;
SEARCH_PROFILES=$1
;;
# Define a custom plugin directory # Define a custom profile file
--plugindir | --plugin-dir | --plugins-dir) --profile)
shift shift
PLUGINDIR=$1 SEARCH_PROFILES=$1
LASTCHAR=`echo $1 | awk '{ print substr($0, length($0))}'` ;;
if [ "${LASTCHAR}" = "/" ]; then
echo "${RED}Error:${WHITE} plugin directory path should not end with a slash${NORMAL}"
ExitCustom 65
fi
if [ ! -d ${PLUGINDIR} ]; then
echo "${RED}Error:${WHITE} invalid plugin directory ${PLUGINDIR}${NORMAL}"
ExitCustom 66
fi
;;
# Quiet mode # Define a custom plugin directory
-q | --quiet) --plugindir | --plugin-dir | --plugins-dir)
QUIET=1 shift
# Run non-interactive PLUGINDIR=$1
QUICKMODE=1 LASTCHAR=`echo $1 | awk '{ print substr($0, length($0))}'`
;; if [ "${LASTCHAR}" = "/" ]; then
echo "${RED}Error:${WHITE} plugin directory path should not end with a slash${NORMAL}"
ExitCustom 65
fi
if [ ! -d ${PLUGINDIR} ]; then
echo "${RED}Error:${WHITE} invalid plugin directory ${PLUGINDIR}${NORMAL}"
ExitCustom 66
fi
;;
# Non-interactive mode # Quiet mode
-Q | --quick) --quiet | -q)
QUICKMODE=1 QUIET=1
;; QUICKMODE=1 # Run non-interactive
;;
# Define alternative report file # Non-interactive mode
--report-file) --quick | -Q)
shift QUICKMODE=1
REPORTFILE=$1 ;;
;;
# Strip the colors which aren't clearly visible on light backgrounds # Define alternative report file
--reverse-colors) --report-file)
#NORMAL=""; shift
SECTION="${NORMAL}"; REPORTFILE=$1
NOTICE="${NORMAL}"; ;;
#OK="";
#BAD="";
CYAN="${NORMAL}";
GREEN="${NORMAL}";
YELLOW="${NORMAL}";
WHITE="${NORMAL}";
PURPLE="${NORMAL}";
#GREEN="";
#RED=""
;;
# Skip execution of plugins # Strip the colors which aren't clearly visible on light backgrounds
--skip-plugins | --no-plugins) --reverse-colors)
RUN_PLUGINS=0 SECTION="${NORMAL}";
;; NOTICE="${NORMAL}";
CYAN="${NORMAL}";
GREEN="${NORMAL}";
YELLOW="${NORMAL}";
WHITE="${NORMAL}";
PURPLE="${NORMAL}";
;;
# Only scan these tests # Skip execution of plugins
--tests) --skip-plugins | --no-plugins)
shift RUN_PLUGINS=0
TESTS_TO_PERFORM=$1 ;;
;;
# Scan one or more categories only # Only scan these tests
--tests-category) --tests)
shift shift
TESTS_CATEGORY_TO_PERFORM=$1 TESTS_TO_PERFORM=$1
;; ;;
# Lynis Enterprise: upload data to central node # Scan one or more categories only
--upload) --tests-category)
UPLOAD_DATA=1 shift
;; TESTS_CATEGORY_TO_PERFORM=$1
;;
--verbose) # Lynis Enterprise: upload data to central node
VERBOSE=1 --upload)
;; UPLOAD_DATA=1
;;
# Version number --verbose)
-V | --version) VERBOSE=1
echo "${PROGRAM_VERSION}" ;;
exit 0
;;
--view-categories | --list-categories | --show-categories) # Version number
ViewCategories --version | -V)
exit 0 echo "${PROGRAM_VERSION}"
;; exit 0
;;
# View man page --view-categories | --list-categories | --show-categories)
--view-manpage | --man | --manpage) ViewCategories
if [ -f lynis.8 ]; then exit 0
nroff -man lynis.8 ;;
exit 0
else
echo "Error: man page file not found (lynis.8)"
echo "If you are running an installed version of Lynis, use 'man lynis'"
exit 1
fi
;;
# Warnings # View man page
--warnings-only | --show-warnings-only) --view-manpage | --man | --manpage)
SHOW_WARNINGS_ONLY=1 if [ -f lynis.8 ]; then
QUICKMODE=1 nroff -man lynis.8
QUIET=1 exit 0
;; else
echo "Error: man page file not found (lynis.8)"
echo "If you are running an installed version of Lynis, use 'man lynis'"
exit 1
fi
;;
# Drop out when using wrong option(s) # Warnings
*) --warnings-only | --show-warnings-only)
# Wrong option used, we bail out later SHOW_WARNINGS_ONLY=1
WRONGOPTION=1 QUICKMODE=1
WRONGOPTION_value=$1 QUIET=1
;; ;;
# Drop out when using wrong option(s)
*)
# Wrong option used, we bail out later
WRONGOPTION=1
WRONGOPTION_value=$1
;;
esac esac
shift shift