diff --git a/seqs/backup.sh b/seqs/backup.sh index cdba14c..53609ae 100755 --- a/seqs/backup.sh +++ b/seqs/backup.sh @@ -1,42 +1,36 @@ #!/bin/bash -toolName=backup -toolBin=rsync +readonly toolName=backup +readonly toolBin=rsync -# Get script working directory -# (when called from a different directory) -WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )" -APTOPT= -CONFIG=0 -CONFIG_FILE_NAME="${toolName}.cfg" -CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example" +sq_aptOpt= +sq_config=0 seq_config() { - initSeqConfig -t "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" - if [ $? -eq 0 ] ; then - CONFIG=1 + if initSeqConfig -t "${seq_configName:?}" "${seq_configTemplate:?}" ; then + sq_config=1 else error -e "Check output for errors" # End if no configuration file exists - dry || return -1 + dry || return 1 fi - quiet && APTOPT="-y" + interactive || sq_aptOpt="-y" return 0 } step_1_info() { echo "Backup root" echoinfo "Essential excludes are provided in the configuration template." - echoinfo "($CONFIG_FILE_TEMPLATE)" + echoinfo "(${seq_configTemplate})" } step_1_options() { echo "[ADDITIONAL_EXCLUDES...]"; } step_1_alias() { echo "buroot"; } step_1() { local buTarget="/backup" - if [ $CONFIG -eq 0 ] ; then + if (( ! sq_config )) ; then error -e "Cannot backup root without properly configured excludes" - error -e " (expected config: $seq_configRoot/$CONFIG_FILE_NAME)" + error -e " (expected config: ${seq_configFile})" else buTarget="$BACKUP_TARGET" fi @@ -49,20 +43,19 @@ step_1() { step_3_info() { # Backup single directory recursively - local opt="[OPTION]" - local dir="" - local tar="" - local exc="[EXCLUDES...]" + local opt= + local dir= + local tar= + local exc= shift if [ "${1:-}" == "-t" ] ; then opt=" -t " - tar= shift fi if [ -n "${1:-}" ] ; then dir="$1" shift - if [ -n $tar ] && [ -n "$1" ] ; then + if [ -z $opt ] && [ -n "$1" ] ; then tar="$1" shift else @@ -75,12 +68,13 @@ step_3_info() { fi fi echo "Backup $opt $dir $tar $exc" - echoinfo " -t : Using configuration value as TARGET" - echoinfo " [EXCLUDES...]" + echoinfo " -t : Using configuration value as TARGET" + echoinfo " [EXCLUDES...]" echoinfo "EXCLUDES path notation starts within $dir" - echoinfo "e.g. to exclude $dir/a:" + echoinfo " e.g. to exclude $dir/a:" echoinfo " $0 budir $dir $tar /a" } +step_3_options() { echo "[OPTION] [TARGET] [EXCLUDES...]"; } step_3_alias() { echo "budir"; } step_3() { local configTarget=0 @@ -119,7 +113,7 @@ step_3() { buLog="backup_${buLog}" shift - if [ $configTarget -ne 0 ] && [ $CONFIG -ne 0 ] ; then + if [ $configTarget -ne 0 ] && (( sq_config )) ; then # Taking target from config buTarget=$(echo "$BACKUP_TARGET" | sed 's:/*$::') else @@ -176,7 +170,7 @@ step_100_info() { echo "Install $toolBin"; } step_100_alias() { echo "install"; } step_100() { exe apt update - exe apt install $toolBin $APTOPT + exe apt install $toolBin ${sq_aptOpt} } checkInstalled() { @@ -187,6 +181,7 @@ checkInstalled() { toolBin="$(command -v $toolBin)" } +# shellcheck disable=SC2034 # Appears unused readonly sqr_minVersion=16 +# shellcheck disable=SC1091 # Don't follow this source . /usr/local/bin/sequencer.sh - diff --git a/seqs/certbot.sh b/seqs/certbot.sh index 0f50238..646dd08 100755 --- a/seqs/certbot.sh +++ b/seqs/certbot.sh @@ -3,21 +3,20 @@ # Certbot installation and creation supporting Raspbian and Ubuntu. # Certificate can be created/updated as "certonly" only. -toolName=certbot +readonly toolName=certbot -# 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= seq_config() { - initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" - local confReturn=$? - if [ $confReturn -eq 0 ] ; then - CONFIG=1 + if ! initSeqConfig "${seq_configName:?}" "${seq_configTemplate:?}" ; then + # End if no configuration file exists + dry || return 1 fi + + ## Apt cmdline option to suppress user interaction + interactive || sq_aptOpt="-y" + + return 0 } step_1_info() { echo "Install $toolName for letsencrypt"; } @@ -41,24 +40,17 @@ step_1() { echo " [I] Detected OS: $osName $distName" - local aptOption= - if quiet ; then - aptOption="-y" - else - aptOption="" - fi - if [ "$osName" == "Ubuntu" ] ; then exe apt-get update - exe apt-get install software-properties-common $aptOption + exe apt-get install software-properties-common ${sq_aptOpt} saveReturn $? - exe add-apt-repository universe $aptOption + exe add-apt-repository universe ${sq_aptOpt} saveReturn $? - exe add-apt-repository ppa:certbot/certbot $aptOption + exe add-apt-repository ppa:certbot/certbot ${sq_aptOpt} saveReturn $? exe apt-get update - exe apt-get install $toolName $aptOption + exe apt-get install $toolName ${sq_aptOpt} saveReturn $? endReturn "$toolName installation for $osName failed" elif [ "$osName" == "Raspbian" ] ; then @@ -71,13 +63,15 @@ step_1() { step_2_info() { echo "Create or update letsencrypt certificate"; } step_2_alias() { echo "update"; } step_2() { - endCheckEmpty CERTBOT_DOMAINS "No domain list found. Check configuration" - endCheckEmpty CERTBOT_WEBROOT "Invalid web root. Check configuration" - endCheckEmpty CERTBOT_MAIL "Invalid mail address. Check configuration" + endIfEmpty CERTBOT_DOMAINS "No domain list found. Check configuration" + endIfEmpty CERTBOT_WEBROOT "Invalid web root. Check configuration" + endIfEmpty CERTBOT_MAIL "Invalid mail address. Check configuration" exe certbot certonly --webroot -w "$CERTBOT_WEBROOT" --rsa-key-size 4096 --expand --agree-tos \ -m "$CERTBOT_MAIL" ${CERTBOT_DOMAINS[@]/#/-d } } +# shellcheck disable=SC2034 # Appears unused readonly sqr_minVersion=16 +# shellcheck disable=SC1091 # Don't follow this source . /usr/local/bin/sequencer.sh diff --git a/seqs/debianrpi.sh b/seqs/debianrpi.sh index 55b7d40..f0dd543 100755 --- a/seqs/debianrpi.sh +++ b/seqs/debianrpi.sh @@ -1,11 +1,11 @@ #!/bin/bash #toolName=mytool -toolDownSite="https://raspi.debian.net/tested-images" +readonly toolDownSite="https://raspi.debian.net/tested-images" toolDownUrl= toolDownFile= -toolEssentialDeps="vim bash-completion man-db locales wget" +readonly toolEssentialDeps="vim bash-completion man-db locales wget" SDDEV= SDBOOT= @@ -14,25 +14,18 @@ SDROOT= SDROOTDEV= SDROOTPUUID= -# Get script working directory -# (when called from a different directory) -WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )" -APTOPT= -CONFIG=0 -SCRIPT_NAME=$(basename -- $0) -SCRIPT_NAME=${SCRIPT_NAME%%.*} -CONFIG_FILE_NAME="${SCRIPT_NAME}.cfg" -CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example" +sq_aptOpt= seq_config() { - quiet && APTOPT="-y" + interactive || sq_aptOpt="-y" return 0 } step_1_info() { - echo "Download latest xz-compressed image [IMAGE FILE URL] [SD CARD DEVICE]" + echo "Download latest xz-compressed image" echoinfo "$toolDownSite" } +step_1_options() { echo "[IMAGE FILE URL] [SD CARD DEVICE]"; } step_1_alias() { echo "install"; } step_1() { shift @@ -71,7 +64,8 @@ step_1() { endReturn -o $? "SHA256 checksum error" } -step_2_info() { echo "Write image to device [DEVICE]"; } +step_2_info() { echo "Write image to device"; } +step_2_options() { echo "[DEVICE]"; } step_2() { shift if [ -z "$SDDEV" ] ; then @@ -130,8 +124,8 @@ step_10() { fi exe apt update - exe apt full-upgrade $APTOPT - exe apt install $toolEssentialDeps $APTOPT + exe apt full-upgrade ${sq_aptOpt} + exe apt install $toolEssentialDeps ${sq_aptOpt} } step_11_info() { echo "Set timezone"; } @@ -156,12 +150,13 @@ step_12() { } localesConfigLoc="/etc/locale.gen" -step_14_info() { echo "Change hostname [HOSTNAME]"; } +step_14_info() { echo "Change hostname"; } +step_14_options() { echo "[HOSTNAME]"; } step_14_alias() { echo "hostname"; } step_14() { shift local localHostname=$1 - endCheckEmpty localHostname "No hostname provided" + endIfEmpty localHostname "No hostname provided" if [ $(grep -r "$localHostname" "$hostsLoc">>/dev/null; echo $?) -eq 0 ] ; then info "Hostname $localHostname already defined" return 0 @@ -175,7 +170,7 @@ hostsLoc="/etc/hosts" step_16_info() { echo "Install cifs mounting requirements"; } step_16_alias() { echo "cifs"; } step_16() { - exe apt install cifs-utils $APTOPT + exe apt install cifs-utils ${sq_aptOpt} } step_17_info() { echo "Cifs notes"; } @@ -296,5 +291,8 @@ read_sd_dev() { } SDBOOTPARTNO=1 SDROOTPARTNO=2 + +# shellcheck disable=SC2034 # Appears unused readonly sqr_minVersion=16 +# shellcheck disable=SC1091 # Don't follow this source . /usr/local/bin/sequencer.sh diff --git a/seqs/downloader.sh b/seqs/downloader.sh index f68f849..53e9905 100755 --- a/seqs/downloader.sh +++ b/seqs/downloader.sh @@ -1,26 +1,18 @@ #!/bin/bash -# Get script working directory -# (when called from a different directory) -WDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)" -APTOPT= -CONFIG=0 -SCRIPT_NAME=$(basename -- $0) -SCRIPT_NAME=${SCRIPT_NAME%%.*} -CONFIG_FILE_NAME="${SCRIPT_NAME}.cfg" -CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example" +sq_aptOpt= seq_config() { checkVpn - initSeqConfig -t "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" - if [ $? -eq 0 ] ; then - CONFIG=1 - else + if ! initSeqConfig -t "${seq_configName:?}" "${seq_configTemplate:?}" ; then # End if no configuration file exists - dry || return -1 + dry || return 1 fi - quiet && APTOPT="-y" + + ## Apt cmdline option to suppress user interaction + interactive || sq_aptOpt="-y" + return 0 } @@ -227,7 +219,7 @@ step_11() { exe curl -sL "$lidarrUrl" -o /tmp/Lidarr.tgz endReturn -o "Download failed" - exe apt install $lidarrDeps $APTOPT + exe apt install $lidarrDeps ${sq_aptOpt} exe tar xvzf /tmp/Lidarr.tgz -C "${DLD_DIR}/" exe mv "${DLD_DIR}/Lidarr" "${DLD_DIR}/lidarr" @@ -273,7 +265,7 @@ step_13() { local bazarrDeps="python3-pip python3-distutils python3-venv ffmpeg" #local bazarrDeps+=" libxml2-dev libxslt1-dev python3-libxml2 python3-lxml libatlas-base-dev" - exe apt install $bazarrDeps $APTOPT + exe apt install $bazarrDeps ${sq_aptOpt} } step_14_info() { echo "Install bazarr"; } @@ -352,8 +344,8 @@ step_16() { exe mkdir -p "$buildPath" exe cd "$buildPath" - exe apt build-dep unrar-nonfree $APTOPT - exe apt source -b unrar-nonfree $APTOPT + exe apt build-dep unrar-nonfree ${sq_aptOpt} + exe apt source -b unrar-nonfree ${sq_aptOpt} endReturn -o $? "unrar-nonfree build failed ($buildPath left untouched)" exe dpkg -i unrar*.deb endReturn -o $? "unrar-nonfree install failed ($buildPath left untouched)" @@ -370,7 +362,7 @@ step_17() { return 0 fi exe apt update - exe apt install dante-server $APTOPT + exe apt install dante-server ${sq_aptOpt} exe systemctl stop danted.service exe systemctl disable danted.service } @@ -606,5 +598,7 @@ checkVpn() { fi } +# shellcheck disable=SC2034 # Appears unused readonly sqr_minVersion=16 +# shellcheck disable=SC1091 # Don't follow this source . /usr/local/bin/sequencer.sh diff --git a/seqs/ebackup.sh b/seqs/ebackup.sh index b575253..ca9e935 100755 --- a/seqs/ebackup.sh +++ b/seqs/ebackup.sh @@ -27,16 +27,15 @@ seq_config() { step_1_info() { echo -n "Backup " if contextHelp ; then - echo -n "selected profile" + echo "selected profile" else - echo -n "profile: $seq_profileName" + echo "profile: $seq_profileName" fi - echo " [OPTIONS] [full|incremental]" echoinfo " [OPTIONS]" echoinfo " --no-purge, -n : Do not purge old backups after backup" echoinfo " --allow-source-mismatch, -a : see ${toolName:-} help" - } +step_1_options() { echo '[OPTIONS] [full|incremental]'; } step_1_alias() { echo "backup"; } step_1() { shift @@ -109,12 +108,13 @@ step_3() { } step_5_info() { - echo "Restore [OPTIONS] [TARGET]" + echo "Restore files from backup" echoinfo " [OPTIONS]" echoinfo " --file-to-restore, -f : Relative path within backup" echoinfo " (file or folder)" echoinfo " --time, -t