Fix unbound variable errors

This commit is contained in:
2022-06-02 16:08:07 +02:00
parent a6eeccb417
commit 4f8c1b5388
15 changed files with 85 additions and 86 deletions

View File

@@ -54,21 +54,21 @@ step_3_info() {
local tar="<TARGET>"
local exc="[EXCLUDES...]"
shift
if [ "$1" == "-t" ] ; then
if [ "${1:-}" == "-t" ] ; then
opt=" -t "
tar=
shift
fi
if [ ! -z "$1" ] ; then
if [ -n "${1:-}" ] ; then
dir="$1"
shift
if [ ! -z $tar ] && [ ! -z "$1" ] ; then
if [ -n $tar ] && [ -n "$1" ] ; then
tar="$1"
shift
else
tar="$BACKUP_TARGET"
fi
if [ ! -z "$1" ] ; then
if [ -n "${1:-}" ] ; then
exc="$@"
else
exc="[NO EXCLUDES]"
@@ -83,7 +83,6 @@ step_3_info() {
}
step_3_alias() { echo "budir"; }
step_3() {
local arg
local configTarget=0
local noRemount=0
local buSource=
@@ -93,7 +92,7 @@ step_3() {
# don't use step number
shift
for arg in "$@"; do
for _ in "$@"; do
case "$1" in
-t)
configTarget=1

View File

@@ -39,7 +39,7 @@ step_1() {
SDDEV="$2"
if [ -z "$1" ] && interactive ; then
read -p "Provide image download url from $toolDownSite: " toolDownUrl
elif [ ! -z "$1" ] ; then
elif [ -n "${1:-}" ] ; then
toolDownUrl="$1"
else
error -e "No image file provided for download"
@@ -246,7 +246,7 @@ HDBOOT_EOF
read_sd_dev() {
local partExt=""
if [ ! -z "$1" ] ; then
if [ -n "${1:-}" ] ; then
SDBOOT=
SDROOT=
SDROOTDEV=

View File

@@ -601,8 +601,9 @@ step_50() {
}
checkVpn() {
ip -br a | grep tun >>/dev/null 2>&1
[ $? -eq 0 ] && warning "A VPN connection is possibly active. Consider deactivating it befor any apt operation."
if ip -br a | grep tun >>/dev/null 2>&1 ; then
[ $? -eq 0 ] && warning "A VPN connection is possibly active. Consider deactivating it befor any apt operation."
fi
}
readonly sqr_minVersion=16

View File

@@ -59,9 +59,9 @@ step_1() {
return 1
fi
if [ ! -z "$1" ] && ( [ "$1" == "full" ] || [ "$1" == "incremental" ] ) ; then
if [ -n "${1:-}" ] && ( [ "$1" == "full" ] || [ "$1" == "incremental" ] ) ; then
dupArgs+=("$1")
elif [ ! -z "$1" ] ; then
elif [ -n "${1:-}" ] ; then
echo " [W] $toolName command \"$1\" not recognized"
return 1
fi
@@ -155,7 +155,7 @@ step_7() {
shift
local ebuTarget="$EBU_TARGET"
local dupCommand=
if [ ! -z "$1" ] ; then
if [ -n "${1:-}" ] ; then
ebuTarget="$1"
fi
@@ -182,7 +182,7 @@ step_20_info() {
[ ! -z "${1:-}" ] && ebuTarget="$1"
if contextHelp; then
echo "Status of (profile) [TARGET]"
elif [ ! -z "$1" ]; then
elif [ -n "${1:-}" ]; then
echo "Status of target: $ebuTarget"
else
echo "Status of profile \"$seq_profileName\" target: $ebuTarget"
@@ -192,7 +192,7 @@ step_20_alias() { echo 'status'; }
step_20() {
shift
local ebuTarget="$EBU_TARGET"
if [ ! -z "$1" ] ; then
if [ -n "${1:-}" ] ; then
ebuTarget="$1"
fi
@@ -205,7 +205,7 @@ step_22_alias() { echo 'list'; }
step_22() {
shift
local ebuTarget="$EBU_TARGET"
if [ ! -z "$1" ] ; then
if [ -n "${1:-}" ] ; then
ebuTarget="$1"
fi

View File

@@ -60,7 +60,7 @@ step_20() {
if [ ! -z $ELEMENT_WEB_BACKUP ] ; then
exe mkdir -p "$ELEMENT_WEB_BACKUP"
fi
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
tempRoot="$1"
else
tempRoot="$ELEMENT_WEB_LOC"

View File

@@ -35,10 +35,10 @@ step_20() {
error -e "No configuration file found"
return 1
fi
if [ ! -z $FR_BACKUP ] ; then
if [ -n "$FR_BACKUP" ] ; then
exe mkdir -p "$FR_BACKUP"
fi
if [ ! -z "$1" ] ; then
if [ -n "${1:-}" ] ; then
tempRoot="$1"
else
tempRoot="$FR_LOC"
@@ -61,7 +61,7 @@ step_20() {
step_22_info() {
shift
if [ -z $1 ] ; then
if [ -z "${1:-}" ] ; then
echo -n "Get latest version from github"
if ! contextHelp ; then
echo ": $(curl --silent "$latestUrl" | grep -Po '"tag_name": "\K.*?(?=")')"
@@ -76,7 +76,7 @@ step_22_alias() { echo "upgrade"; }
step_22() {
shift # don't need step number
local latestVersion=
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
latestVersion="$1"
else
latestVersion=$(curl --silent "$latestUrl" | grep -Po '"tag_name": "\K.*?(?=")')

View File

@@ -218,7 +218,7 @@ step_103_info() { echo "(re)Set passwort for <USER>"; }
step_103_alias() { echo "passwd"; }
step_103() {
shift
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
echo " [I] Password operation for $1"
userId="$1"
elif [ ! -z $userId ] ; then
@@ -234,7 +234,7 @@ step_105_info() { echo "Adding <USER ID> to existing group <GROUP NAME>"; }
step_105_alias() { echo "user2group"; }
step_105() {
shift
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
userId="$1"
echo " [I] User operation for $userId"
elif [ ! -z $userId ] ; then
@@ -269,7 +269,7 @@ step_107_info() { echo "Removing <USER ID> from existing group <GROUP NAME>"; }
step_107_alias() { echo "rmusergroup"; }
step_107() {
shift
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
userId="$1"
echo " [I] User operation for $userId"
elif [ ! -z $userId ] ; then

View File

@@ -31,7 +31,7 @@ seq_config() {
initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
if [ $? -eq 0 ] ; then
CONFIG=1
info " Domain: $MAS_DOMAIN"
info " Domain: ${MAS_DOMAIN:-}"
elif [ $? -eq 1 ] ; then
# Config $CONFIG_FILE_NAME created. Needs modification first
dry || return -1
@@ -415,20 +415,19 @@ step_100_info() {
step_100_alias() { echo "test"; }
step_100() {
shift
local arg
local fromAdr
local toAdr="postmaster@$MAS_DOMAIN"
local asUser=
for arg in "$@" ; do
for _ in "$@" ; do
case "$1" in
-f)
shift
fromAdr="-f $1 "
fromAdr="-f ${1:-} "
shift
;;
-u)
shift
asUser="sudo -u $1 "
asUser="sudo -u ${1:-} "
shift
;;
*)
@@ -436,7 +435,7 @@ step_100() {
;;
esac
done
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
toAdr="$1"
fi
exe ${asUser}sh -c "echo \"Subject: Test from Postfix\nIt is \$(date)\n\nGreetings \$(whoami)\" | sendmail ${fromAdr}$toAdr"
@@ -456,7 +455,7 @@ step_104_alias() { echo "delqueue"; }
step_104() {
shift
local msgId="ALL"
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
msgId="$1"
fi
exe postsuper -d "$msgId"

View File

@@ -25,9 +25,9 @@ seq_config() {
initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
if [ $? -eq 0 ] ; then
CONFIG=1
postgresDb="$MAYAN_DB"
postgresUser="$MAYAN_DBUSER"
postgresPass="$MAYAN_DBPASS"
postgresDb="${MAYAN_DB:-}"
postgresUser="${MAYAN_DBUSER:-}"
postgresPass="${MAYAN_DBPASS:-}"
else
# End if no configuration file exists
dry || return -1
@@ -223,7 +223,7 @@ readDatabaseInfos() {
# Needs readDatabaseInfos() to execute some commands
toolScript() {
if [ ! -z "$1" ] ; then
if [ -n "${1:-}" ] ; then
readDatabaseInfos
fi

View File

@@ -1,7 +1,7 @@
#!/bin/bash
toolName=postfixadmin
toolPhpDeps='php${PFA_PHP_VERSION}-fpm php${PFA_PHP_VERSION}-imap php${PFA_PHP_VERSION}-mbstring php${PFA_PHP_VERSION}-mysql php${PFA_PHP_VERSION}-json php${PFA_PHP_VERSION}-curl php${PFA_PHP_VERSION}-zip php${PFA_PHP_VERSION}-xml php${PFA_PHP_VERSION}-bz2 php${PFA_PHP_VERSION}-intl php${PFA_PHP_VERSION}-gmp'
toolPhpDeps='php${PFA_PHP_VERSION:-}-fpm php${PFA_PHP_VERSION:-}-imap php${PFA_PHP_VERSION:-}-mbstring php${PFA_PHP_VERSION:-}-mysql php${PFA_PHP_VERSION:-}-json php${PFA_PHP_VERSION:-}-curl php${PFA_PHP_VERSION:-}-zip php${PFA_PHP_VERSION:-}-xml php${PFA_PHP_VERSION:-}-bz2 php${PFA_PHP_VERSION:-}-intl php${PFA_PHP_VERSION:-}-gmp'
toolConfName="config.local.php"
toolTemplates="templates_c"
toolTemplatesLoc="$PFA_SRV_LOC/$toolTemplates"
@@ -18,12 +18,13 @@ CONFIG_FILE_NAME="${toolName}.cfg"
CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example"
seq_config() {
initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
if [ $? -eq 0 ] ; then
echo " ${toolName} path: ${PFA_WEB_LOC}"
echo " ${toolName} backup: ${PFA_BACKUP}"
echo " php Version: ${PFA_PHP_VERSION}"
if initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" ; then
info "${toolName} path: ${PFA_WEB_LOC:-}"
info -a "${toolName} backup: ${PFA_BACKUP:-}"
info -a " php Version: ${PFA_PHP_VERSION:-}"
CONFIG=1
else
dry || return 1
fi
}
@@ -45,7 +46,7 @@ step_1() {
exe apt install $localDeps $aptOpt
}
step_2_info() { echo "Install $toolName to $PFA_SRV_LOC"; }
step_2_info() { echo "Install $toolName to ${PFA_SRV_LOC:-}"; }
step_2() {
step upgrade
}
@@ -149,7 +150,7 @@ step_18() {
shift
local isInstalled=
local latestVersion=
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
latestVersion="$1"
else
latestVersion=$(curl --silent "$latestUrl" | grep -Po '"tag_name": "postfixadmin-\K.*?(?=")')
@@ -186,7 +187,7 @@ step_20() {
if [ ! -z $PFA_BACKUP ] ; then
exe mkdir -p "$PFA_BACKUP"
fi
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
tempRoot="$1"
else
tempRoot="$PFA_SRV_LOC"
@@ -219,7 +220,7 @@ step_22_alias() { echo "upgrade"; }
step_22() {
shift # don't need step number
local latestVersion=
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
latestVersion="$1"
else
latestVersion=$(curl --silent "$latestUrl" | grep -Po '"tag_name": "postfixadmin-\K.*?(?=")')

View File

@@ -55,10 +55,10 @@ HDSWAPPUUID=
evalArgs() {
local argCount=0
for arg in "$@"; do
for _ in "$@"; do
case "$1" in
-a|--arch)
if [ ! -z "$2" ]; then
if [ -n "${2:-}" ]; then
PIARCH="$2"
((argCount+=2))
else
@@ -115,7 +115,7 @@ step_2_info() {
echoinfoArgs "[OPTIONS] [SD CARD DEVICE]"
echo "Write Raspberry Pi OS image to SD card"
echoinfo "This operation will delete all data previously on the SD card!"
contextExe && [ ! -z $1 ] && echoinfo " [SD CARD DEVICE]: $1"
contextExe && [ -n "${1:-}" ] && echoinfo " [SD CARD DEVICE]: $1"
}
step_2_alias() { echo "writesd"; }
step_2() {
@@ -134,7 +134,7 @@ step_2() {
endReturn -o 1 "No root"
fi
read_sd_dev "$1"
read_sd_dev "${1:-}"
# check if device was confirmed
if [ $? -ne 0 ] ; then
endReturn -o 1 "SD card device not found"
@@ -162,14 +162,14 @@ step_3_info() {
echoinfoArgs "[SD CARD DEVICE]"
echo "Prepare SD for first run"
if contextExe; then
[ ! -z $1 ] && echoinfo " [SD CARD DEVICE]: $1"
[ -n "${1:-}" ] && echoinfo " [SD CARD DEVICE]: $1"
fi
}
step_3() {
# Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
if [ -z $1 ] && [ ! -z $SDDEV ] ; then
if [ -z "${1:-}" ] && [ -n "${SDDEV:-}" ] ; then
if quiet ; then
answer="n"
else
@@ -188,7 +188,7 @@ step_3() {
esac
fi
read_sd_dev "$1"
read_sd_dev "${1:-}"
endReturn -o $? "SD card device not found"
if [ ! -w "$SDBOOT" ] ; then
@@ -213,8 +213,8 @@ step_4_info() {
echoinfoArgs "[SD CARD DEVICE] [HD DEVICE]"
echo "Prepare SD card to boot from hard disk"
if contextExe; then
[ ! -z $1 ] && echoinfo " [SD CARD DEVICE]: $1"
[ ! -z $2 ] && echoinfo " [HD DEVICE]: $2"
[ -n "${1:-}" ] && echoinfo " [SD CARD DEVICE]: $1"
[ -n "${2:-}" ] && echoinfo " [HD DEVICE]: $2"
fi
}
step_4_alias() { echo "hdboot"; }
@@ -222,9 +222,9 @@ step_4() {
# Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
read_sd_dev "$1"
read_sd_dev "${1:-}"
endReturn -o $? "SD detection error $?"
read_hd_dev "$2"
read_hd_dev "${2:-}"
endReturn -o $? "HD detection error"
echo " [I] SD: $SDDEV"
echo " $SDBOOT [$SDBOOTPUUID]"
@@ -285,8 +285,8 @@ step_5_info() {
echo "Prepare HD for boot (TODO)"
if contextExe; then
[ ! -z $1 ] && echoinfo " [SD CARD DEVICE]: $1"
[ ! -z $2 ] && echoinfo " [HD DEVICE]: $2"
[ -n "${1:-}" ] && echoinfo " [SD CARD DEVICE]: $1"
[ -n "${2:-}" ] && echoinfo " [HD DEVICE]: $2"
fi
}
step_5() {
@@ -296,10 +296,10 @@ step_5() {
#TODO
error -e "Not ready yet...TODO"
#return 1
read_sd_dev "$1"
read_sd_dev "${1:-}"
endReturn -o $? "SD detection error $?"
read_hd_dev "$2"
read_hd_dev "${2:-}"
endReturn -o $? "HD detection error"
echo " [I] SD: $SDDEV"
echo " $SDBOOT [$SDBOOTPUUID]"
@@ -333,14 +333,14 @@ step_5() {
read_sd_dev() {
local partExt=""
if [ ! -z "$1" ] ; then
if [ -n "${1:-}" ] ; then
SDBOOT=
SDROOT=
SDROOTDEV=
SDROOTPUUID=
SDBOOTPUUID=
SDDEV="$1"
elif [ -z $SDDEV ] || [ ! -b "$SDDEV" ] ; then
elif [ -z "${SDDEV:-}" ] || [ ! -b "$SDDEV" ] ; then
SDDEV=
SDBOOT=
SDROOT=
@@ -385,7 +385,7 @@ SDBOOTPARTNO=1
SDROOTPARTNO=2
read_hd_dev() {
if [ ! -z "$1" ] ; then
if [ -n "${1:-}" ] ; then
HDROOT=
HDROOTPUUID=
HDSWAPPUUID=
@@ -447,7 +447,7 @@ step_22_info() { echoinfoArgs "[SD CARD DEVICE]"; echo "Resize second SD card pa
step_22_alias() { echo "resizesd"; }
step_22() {
shift
read_sd_dev "$1"
read_sd_dev "${1:-}"
if [ -z $SDDEV ] || [ "$SDDEV" = "" ] || [ "$SDROOT" == "/" ] ; then
error -e "No SD found"
return 1
@@ -570,7 +570,7 @@ tvserviceOffCmd="${tvserviceBin} -o'"
# checkBootConfig <CONFIGNAME> [VALUE]
checkBootConfig() {
[ -z "$1" ] && return 1
[ -z "${1:-}" ] && return 1
local re_check="^[[:blank:]]*[^#]*${1}[[:blank:]]*=[[:blank:]]*$2"
grep -rqE "$re_check" "$RPI_BOOT_CONFIG"

View File

@@ -173,7 +173,7 @@ step_22() {
shift # don't need step number
local currentVersion=
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
latestVersion="$1"
else
fetchLatestVersion

View File

@@ -73,7 +73,7 @@ step_2() {
addConf -a "$v3AuthEntry" "$v3AuthLoc"
shift
if [ ! -z $1 ] && [ "$1" == "-s" ] ; then
if [ -n "${1:-}" ] && [ "$1" == "-s" ] ; then
info "Stop after creating authentication config"
exe service snmpd start
return 0
@@ -109,7 +109,7 @@ step_5_alias() { echo "ufw"; }
step_5() {
shift
local lInterface="eth0"
[ ! -z "$1" ] && lInterface="$1"
[ -n "${1:-}" ] && lInterface="$1"
# Check if interface exists
ip -br a | grep -E "^$lInterface" >>/dev/null 2>&1
endReturn -o $? "Interface $lInterface does not exist"

View File

@@ -119,7 +119,7 @@ parseList() {
else
error -e "Command list not found: $1"
fi
if [ ! -z "$1" ] && dry || interactive ; then
if [ -n "${1:-}" ] && dry || interactive ; then
read -p " Create template there y/[n]? " answer
case "$answer" in
y|Y)

View File

@@ -19,36 +19,35 @@ CONFIG_FILE_NAME="${toolName}.cfg"
CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example"
seq_config() {
initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
if [ $? -eq 0 ] ; then
if initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" ; then
CONFIG=1
else
dry || return 1
fi
toolConfigLoc=`eval echo "$TWXA_CONFIG_LOC"`
toolConfigLoc=`eval echo "${TWXA_CONFIG_LOC:-}"`
toolConfig="$toolConfigLoc/config_cache/$toolConfigName"
toolHtmlLoc=`eval echo "$TWXA_HTML_LOC"`
toolBackupLoc=`eval echo "$TWXA_BACKUP_LOC"`
toolGitLoc=`eval echo "$TWXA_GIT_LOC"`
gitLibLoc=`eval echo "$TWXA_GIT_LOC/var/lib/torrentwatch-xa"`
gitHtmlLoc=`eval echo "$TWXA_GIT_LOC/var/www/html/torrentwatch-xa"`
echo " git: $toolGitLoc"
echo " config: $toolConfig"
echo " html: $toolHtmlLoc"
echo " backup: $toolBackupLoc"
toolHtmlLoc=`eval echo "${TWXA_HTML_LOC:-}"`
toolBackupLoc=`eval echo "${TWXA_BACKUP_LOC:-}"`
toolGitLoc=`eval echo "${TWXA_GIT_LOC:-}"`
gitLibLoc=`eval echo "${TWXA_GIT_LOC:-}/var/lib/torrentwatch-xa"`
gitHtmlLoc=`eval echo "${TWXA_GIT_LOC:-}/var/www/html/torrentwatch-xa"`
info " git: $toolGitLoc"
info -a "config: $toolConfig"
info -a " html: $toolHtmlLoc"
info -a "backup: $toolBackupLoc"
}
step_1_info() { echo "Install $toolName [VERSION]"; }
step_1_alias() { echo "install"; }
step_1() {
shift
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
toolVersion="$1"
fi
echo $toolConfig
}
step_2_info() { echo "Setup git repository at $toolGitLoc [VERSION e.g. 1.4.1]"; }
step_2_info() { echo "Setup git repository at ${toolGitLoc:-} [VERSION e.g. 1.4.1]"; }
step_2_alias() { echo "git"; }
step_2() {
shift
@@ -60,7 +59,7 @@ step_2() {
exe cd "$toolGitLoc"
exe git pull
fi
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
toolVersion="$1"
fi
exe git checkout $toolVersion
@@ -76,7 +75,7 @@ step_20() {
fi
local buType="all"
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
buType="$1"
fi
local buDate=`date +%Y%m%d-%H%M%S`
@@ -118,7 +117,7 @@ step_30_info() { echo "Upgrade $toolName [VERSION]"; }
step_30_alias() { echo "upgrade"; }
step_30() {
shift
if [ ! -z $1 ] ; then
if [ -n "${1:-}" ] ; then
toolVersion="$1"
fi