Skip to content

Commit

Permalink
fixed syntax based on shellcheck
Browse files Browse the repository at this point in the history
Fixed issues reported by shellcheck
(https://github.com/koalaman/shellcheck/wiki) to improve security and
POSIX shell interoperability.

(part of #27)

Signed-off-by: Andreas Ulm <[email protected]>
  • Loading branch information
root360-AndreasUlm committed Mar 12, 2020
1 parent 2220856 commit aaf0e38
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/sh
#!/bin/bash

current_time=$(date "+%Y.%m.%d-%H.%M")
if [[ -z $upload ]]
upload="${upload:-}"
current_time="$(date "+%Y.%m.%d-%H.%M")"
if [ -z "$upload" ]
then
root_dir=/shared/
else
Expand All @@ -10,48 +11,47 @@ else
mkdir /reports
fi

report_extension="tex"
report_extension="${format:-tex}"

if [[ ! -z $format ]]
then
report_extension=$format
fi
xml_dir="xml_files/$current_time"
report_file="reports/report_$current_time.$report_extension"
report_file_path="${root_dir}${report_file}"

xml_dir=xml_files/$current_time
report_file=reports/report_$current_time.$report_extension

function upload {
if [[ -z $upload ]]
upload() {
if [ -z "$upload" ]
then
return
elif [ $upload = "aws" ]
fi
if [ "$upload" = "aws" ]
then
python /aws_push.py $1
elif [ $upload = "gcp" ]
python /aws_push.py "$1"
elif [ "$upload" = "gcp" ]
then
python /gcp_push.py $1
python /gcp_push.py "$1"
fi
}

function get_filename(){
echo $1 | tr / -
get_filename() {
echo "$1" | tr / -
}

mkdir $root_dir$xml_dir
mkdir -p "$root_dir$xml_dir"
while IFS= read -r line
do
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
filename=$(get_filename $line)".xml"
nmap -sV -oX $root_dir$xml_dir/$filename -oN - -v1 $@ --script=vulners/vulners.nse $line
upload $xml_dir/$filename
current_time="$(date "+%Y.%m.%d-%H.%M.%S")"
filename="$(get_filename "$line").xml"
# $@ without quotes required to expand additional options
# shellcheck disable=SC2068
nmap -sV -oX "$root_dir$xml_dir/$filename" -oN - -v1 $@ --script=vulners/vulners.nse "$line"
upload "$xml_dir/$filename"
done < /shared/ips.txt

python /output_report.py $root_dir$xml_dir $root_dir$report_file /shared/ips.txt
if [[ $report_extension = "tex" ]]
python /output_report.py "$root_dir$xml_dir" "$report_file_path" /shared/ips.txt
if [[ "$report_extension" = "tex" ]]
then
sed -i 's/_/\\_/g' $root_dir$report_file
sed -i 's/\$/\\\$/g' $root_dir$report_file
sed -i 's/#/\\#/g' $root_dir$report_file
sed -i 's/%/\\%/g' $root_dir$report_file
sed -i 's/_/\\_/g' "$report_file_path"
sed -i 's/\$/\\\$/g' "$report_file_path"
sed -i 's/#/\\#/g' "$report_file_path"
sed -i 's/%/\\%/g' "$report_file_path"
fi
upload $report_file
upload "$report_file_path"

0 comments on commit aaf0e38

Please sign in to comment.