Changed how arguments are passed to magellan.sh script

This commit is contained in:
David J. Allen 2023-10-24 14:33:32 -06:00
parent 091045ad1e
commit e039099263

View file

@ -11,6 +11,8 @@ THREADS="1"
TIMEOUT="30" TIMEOUT="30"
ARGS="" ARGS=""
FORCE_UPDATE=false FORCE_UPDATE=false
SCAN_PARAMS=""
COLLECT_PARAMS=""
function build(){ function build(){
@ -19,11 +21,11 @@ function build(){
function scan() { function scan() {
# ./magellan scan --subnet 172.16.0.0 --port 443 # ./magellan scan --subnet 172.16.0.0 --port 443
${EXE} scan \ ${EXE} scan ${SCAN_PARAMS}
--subnet ${SUBNETS} \ # --subnet ${SUBNETS} \
--port ${PORTS} \ # --port ${PORTS} \
--timeout ${TIMEOUT} \ # --timeout ${TIMEOUT} \
--threads ${THREADS} # --threads ${THREADS}
} }
function list(){ function list(){
@ -33,20 +35,30 @@ function list(){
function collect() { function collect() {
# ./magellan collect --user admin --pass password # ./magellan collect --user admin --pass password
${EXE} collect \ ${EXE} collect ${COLLECT_PARAMS}
--user ${USER} \ # --user ${USER} \
--pass ${PASS} \ # --pass ${PASS} \
--timeout ${TIMEOUT} \ # --timeout ${TIMEOUT} \
--threads ${THREADS} \ # --threads ${THREADS} \
--host ${SMD_HOST} \ # --host ${SMD_HOST} \
--port ${SMD_PORT} \ # --port ${SMD_PORT} \
--force-update ${FORCE_UPDATE} # --force-update ${FORCE_UPDATE}
} }
# parse incoming arguments to set variables # parse incoming arguments to set variables
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
--scan)
SCAN_PARAMS="$2"
shift
shift
;;
--collect)
COLLECT_PARAMS="$2"
shift
shift
;;
--subnet) --subnet)
SUBNETS="$2" SUBNETS="$2"
shift # past argument shift # past argument
@ -100,15 +112,6 @@ done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
echo "SMD host = ${SMD_HOST}"
echo "SMD port = ${SMD_PORT}"
echo "subnets = ${SUBNETS}"
echo "ports = ${PORTS}"
echo "user = ${USER}"
echo "threads = ${THREADS}"
echo "timeout = ${TIMEOUT}"
echo "pass = ..."
if [[ -n $1 ]]; then if [[ -n $1 ]]; then
echo "Last line of file specified as non-opt/last argument:" echo "Last line of file specified as non-opt/last argument:"
tail -1 "$1" tail -1 "$1"
@ -116,3 +119,8 @@ fi
scan scan
collect collect
# run with docker
# docker run magellan:latest magellan.sh \
# --scan "--subnet 127.16.0.0 --port 443" \
# --collect "--user admin --pass password --timeout 300 --threads 1 --smd-host host --smd-port port"