2020-04-23 09:56:33 -05:00
|
|
|
|
#!/usr/bin/env bash
|
2020-08-27 20:55:28 +01:00
|
|
|
|
set -eo pipefail
|
2020-04-23 09:56:33 -05:00
|
|
|
|
|
|
|
|
|
|
main() {
|
2020-08-27 20:55:28 +01:00
|
|
|
|
initialize_
|
|
|
|
|
|
parse_cmdline_ "$@"
|
|
|
|
|
|
|
|
|
|
|
|
# Don't pass any files tfsec will recurse directories anyway.
|
|
|
|
|
|
tfsec "$ARGS" .
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
initialize_() {
|
|
|
|
|
|
# get directory containing this script
|
|
|
|
|
|
local dir
|
|
|
|
|
|
local source
|
|
|
|
|
|
source="${BASH_SOURCE[0]}"
|
|
|
|
|
|
while [[ -L $source ]]; do # resolve $source until the file is no longer a symlink
|
|
|
|
|
|
dir="$(cd -P "$(dirname "$source")" > /dev/null && pwd)"
|
|
|
|
|
|
source="$(readlink "$source")"
|
|
|
|
|
|
# if $source was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
|
|
|
|
|
[[ $source != /* ]] && source="$dir/$source"
|
|
|
|
|
|
done
|
|
|
|
|
|
_SCRIPT_DIR="$(dirname "$source")"
|
|
|
|
|
|
|
|
|
|
|
|
# source getopt function
|
|
|
|
|
|
# shellcheck source=lib_getopt
|
|
|
|
|
|
. "$_SCRIPT_DIR/lib_getopt"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
parse_cmdline_() {
|
2020-04-23 09:56:33 -05:00
|
|
|
|
declare argv
|
|
|
|
|
|
argv=$(getopt -o a: --long args: -- "$@") || return
|
|
|
|
|
|
eval "set -- $argv"
|
|
|
|
|
|
|
|
|
|
|
|
for argv; do
|
|
|
|
|
|
case $argv in
|
|
|
|
|
|
-a | --args)
|
|
|
|
|
|
shift
|
2020-08-27 20:55:28 +01:00
|
|
|
|
ARGS+=("$1")
|
2020-04-23 09:56:33 -05:00
|
|
|
|
shift
|
|
|
|
|
|
;;
|
|
|
|
|
|
--)
|
|
|
|
|
|
shift
|
2020-08-27 20:55:28 +01:00
|
|
|
|
# ignore any parameters, as they're not used
|
2020-04-23 09:56:33 -05:00
|
|
|
|
break
|
|
|
|
|
|
;;
|
|
|
|
|
|
esac
|
|
|
|
|
|
done
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-27 20:55:28 +01:00
|
|
|
|
# global arrays
|
|
|
|
|
|
declare -a ARGS=()
|
2020-04-23 09:56:33 -05:00
|
|
|
|
|
2020-08-27 20:55:28 +01:00
|
|
|
|
[[ ${BASH_SOURCE[0]} != "$0" ]] || main "$@"
|