From ec3c35483f0f47744f65372b63ecebabcea1de23 Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Tue, 16 Aug 2022 17:15:30 +0200 Subject: [PATCH] ufw - Adapt to new sequencer --- seqs/ufw.sh | 55 +++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/seqs/ufw.sh b/seqs/ufw.sh index 6775b78..3d9cca5 100755 --- a/seqs/ufw.sh +++ b/seqs/ufw.sh @@ -3,28 +3,31 @@ toolName=ufw toolDeps=$toolName -# Get script working directory -# (when called from a different directory) -WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )" -CONFIG=0 -CONFIG_FILE_NAME="${toolName}.cfg" -CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example" +sq_aptOpt= +#sq_config=0 -#step_config() { -# initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" -# if [ $? -eq 0 ] ; then -# CONFIG=1 -# fi -#} +step_config() { + #if initSeqConfig "${seq_configName:?}" "${seq_configTemplate:?} ; then + # sq_config=1 + #else + # # End if no configuration file exists + # dry || return 1 + #fi + ## Apt cmdline option to suppress user interaction + interactive || sq_aptOpt="-y" + + ## Disable error checks if external scripts are used + ## e.g. error on unbound variables + #disableErrorCheck + + ## Return of non zero value will abort the sequence + return 0 +} step_1_info() { echo "Install $toolName and allow ssh access"; } step_1_alias() { echo "install"; } step_1() { - local aptOpt= - if quiet;then - aptOpt="-y" - fi - exe apt install $toolDeps $aptOpt + exe apt install $toolDeps ${sq_aptOpt} exe ufw allow ssh } @@ -48,13 +51,13 @@ step_22_info() { echoinfoArgs "[IP]"; echo "Deny multicast from gateway"; } step_22_alias() { echo "multicast"; } step_22() { shift - if [ -z $1 ] ; then + if [ -z "${1:-}" ] ; then error -e "No [IP} specified" return 1 fi - exe ufw deny in from $1 to 224.0.0.0/4 comment 'Broadcast Fritzbox' - exe ufw deny in from $1 to 239.0.0.0/8 comment 'Broadcast Fritzbox' + exe ufw deny in from "${1}" to 224.0.0.0/4 comment 'Broadcast Fritzbox' + exe ufw deny in from "${1}" to 239.0.0.0/8 comment 'Broadcast Fritzbox' } step_24_info() { @@ -67,24 +70,24 @@ step_24_info() { step_24_alias() { echo "cifs"; } step_24() { shift - local destIp=$1 + local destIp=${1:-} local ipregex='^[0-2]*[0-9]{1,2}\.[0-2]*[0-9]{1,2}\.[0-2]*[0-9]{1,2}\.[0-2]*[0-9]{1,2}\/*[0-9]*$' endCheckEmpty destIp "No IP provided" - if [[ ! $1 =~ $ipregex ]]; then + if [[ ! ${1:-} =~ $ipregex ]]; then error "No valid IP provided" return 1 fi local destPort=445 - case "$2" in + case "${2:-}" in 139|445) - destPort=$2;; + destPort="${2}";; "");; # Set default *) error -e "Invalid port." return 1;; esac - exe ufw allow out on eth0 to $destIp port $destPort proto tcp comment "samba/cifs" + exe ufw allow out on eth0 to "${destIp}" port "${destPort}" proto tcp comment "samba/cifs" } step_26_info() { echo "Basic secure VPN setup"; } @@ -107,5 +110,7 @@ step_26() { exe ufw status verbose } +# shellcheck disable=SC2034 # Appears unused readonly sqr_minVersion=16 +# shellcheck disable=SC1091 # Don't follow this source . /usr/local/bin/sequencer.sh