Skip to content

Commit

Permalink
Satisfied all remaining shellcheck warnings:
Browse files Browse the repository at this point in the history
* Replaced all remaining $.. with "$..".

* Replaced raw $? checks with better  ||, && and "if" checks.

* Packed chains of 'echo ".." >> $x; echo ".." >> $x' with better
  '{ echo ".."; echo ".." } >> $x'.

* exported locally unused variables (that are probably needed by other
  scripts).
  • Loading branch information
Carlos A. Parra F committed Mar 29, 2021
1 parent 040d7ba commit c5310db
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 105 deletions.
12 changes: 6 additions & 6 deletions src/alert_methods/SCP/alert
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ PASSWORD_FILE=$6
REPORT_FILE=$7

KNOWN_HOSTS_FILE=$(mktemp) || exit 1
echo $KNOWN_HOSTS > $KNOWN_HOSTS_FILE
echo "$KNOWN_HOSTS" > "$KNOWN_HOSTS_FILE"

ERROR_FILE=$(mktemp) || exit 1

Expand Down Expand Up @@ -55,9 +55,9 @@ DEST_ESC=$(shell_esc "$DEST")

if [ -z "$PRIVATE_KEY_FILE" ]
then
timeout $TIMEOUT sshpass -f ${PASSWORD_FILE} scp -o HashKnownHosts=no -o UserKnownHostsFile="${KNOWN_HOSTS_FILE} ~/.ssh/known_hosts ~/.ssh/known_hosts2 /etc/ssh/ssh_known_hosts" "${REPORT_FILE}" "${USERNAME}@${HOST}:${DEST_ESC}" 2>$ERROR_FILE
timeout "$TIMEOUT" sshpass -f "${PASSWORD_FILE}" scp -o HashKnownHosts=no -o UserKnownHostsFile="${KNOWN_HOSTS_FILE} ~/.ssh/known_hosts ~/.ssh/known_hosts2 /etc/ssh/ssh_known_hosts" "${REPORT_FILE}" "${USERNAME}@${HOST}:${DEST_ESC}" 2>"$ERROR_FILE"
else
timeout $TIMEOUT sshpass -f ${PASSWORD_FILE} -P "passphrase" scp -i "$PRIVATE_KEY_FILE" -o PasswordAuthentication=no -o HashKnownHosts=no -o UserKnownHostsFile="${KNOWN_HOSTS_FILE} ~/.ssh/known_hosts ~/.ssh/known_hosts2 /etc/ssh/ssh_known_hosts" "${REPORT_FILE}" "${USERNAME}@${HOST}:${DEST_ESC}" 2>"$ERROR_FILE"
timeout "$TIMEOUT" sshpass -f "${PASSWORD_FILE}" -P "passphrase" scp -i "$PRIVATE_KEY_FILE" -o PasswordAuthentication=no -o HashKnownHosts=no -o UserKnownHostsFile="${KNOWN_HOSTS_FILE} ~/.ssh/known_hosts ~/.ssh/known_hosts2 /etc/ssh/ssh_known_hosts" "${REPORT_FILE}" "${USERNAME}@${HOST}:${DEST_ESC}" 2>"$ERROR_FILE"
fi

EXIT_CODE=$?
Expand Down Expand Up @@ -93,8 +93,8 @@ then
log_error "sshpass failed with exit code ${EXIT_CODE}: $ERROR_SHORT"
fi

rm $KNOWN_HOSTS_FILE
rm $PASSWORD_FILE
rm $ERROR_FILE
rm "$KNOWN_HOSTS_FILE"
rm "$PASSWORD_FILE"
rm "$ERROR_FILE"

exit $EXIT_CODE
4 changes: 2 additions & 2 deletions src/alert_methods/SNMP/alert
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ COMMUNITY=$1
AGENT=$2 # Host.
MESSAGE=$3

OUTPUT=$(snmptrap -v 2c -c $COMMUNITY $AGENT '' .1.3.6.1.6.3 0 s "$MESSAGE" 2>&1)
OUTPUT=$(snmptrap -v 2c -c "$COMMUNITY" "$AGENT" '' .1.3.6.1.6.3 0 s "$MESSAGE" 2>&1)

EXIT_CODE=$?

if [ "0" -ne "$EXIT_CODE" ]
then
echo "snmptrap failed with code $EXIT_CODE:\n$OUTPUT" >&2
printf 'snmptrap failed with code %s:\n%s\n' "$EXIT_CODE" "$OUTPUT">&2
exit $EXIT_CODE
fi
2 changes: 1 addition & 1 deletion src/alert_methods/Send/alert
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

# Escalator method script: Send.

cat $3 | socat -t 0 - TCP:$1:$2
socat -t 0 - TCP:"$1":"$2" < "$3"
EXIT_CODE=$?
exit $EXIT_CODE
2 changes: 1 addition & 1 deletion src/alert_methods/Sourcefire/alert
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

# Escalator method script: Sourcefire connector.

greenbone_sourcefire_connector -server=$1 -port=$2 -pkcs12=$3 -password="$5" $4
greenbone_sourcefire_connector -server="$1" -port="$2" -pkcs12="$3" -password="$5" "$4"
EXIT_CODE=$?
exit $EXIT_CODE
2 changes: 1 addition & 1 deletion src/alert_methods/verinice/alert
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

# Escalator method script: verinice connector.

greenbone_verinice_connector $1 $2 $3 $4
greenbone_verinice_connector "$1" "$2" "$3" "$4"
EXIT_CODE=$?
exit $EXIT_CODE
2 changes: 1 addition & 1 deletion src/schema_formats/HTML/generate
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
# This schema generator creates a single HTML file from the XML schema using
# an XSL transformation via the tool xsltproc.

xsltproc ./HTML.xsl $1
xsltproc ./HTML.xsl "$1"
2 changes: 1 addition & 1 deletion src/schema_formats/RNC/generate
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
# This schema generator creates a single RNC file from the XML schema using
# an XSL transformation via the tool xsltproc.

xsltproc ./RNC.xsl $1
xsltproc ./RNC.xsl "$1"
2 changes: 1 addition & 1 deletion src/schema_formats/XML-brief/generate
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
# This schema generator creates a brief XML description of the protocol.
# Basically just the command list.

xsltproc ./GMP.xsl $1
xsltproc ./GMP.xsl "$1"
2 changes: 1 addition & 1 deletion src/schema_formats/XML/generate
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
# This schema generator is the most trivial one as it simply passes on the
# GMP XML schema as is.

cat $1
cat "$1"
exit 0
Loading

0 comments on commit c5310db

Please sign in to comment.