diff --git a/bin/backup b/bin/backup index 5c4b401..46a61cc 100755 --- a/bin/backup +++ b/bin/backup @@ -20,7 +20,7 @@ ########## _version() { cat <&2 _usage exit 1 ;; @@ -141,7 +141,7 @@ while :; do 24H) date_format=%T ;; FULL) date_format=%F_%T ;; *) - echo "Not supported format: ${1}" + echo Not supported format: "${1}" >&2 _usage exit 1 ;; @@ -163,7 +163,7 @@ while :; do ;; "") break ;; *) - echo "Not supported option: ${1}" + echo Not supported option: "${1}" >&2 _usage exit 1 ;; @@ -174,28 +174,32 @@ done check-root # Check required options -: "${file_system:?"Filesystem missing"}" -: "${mount_point:?"Mounting point missing"}" -: "${source_dir:?"Source missing"}" -: "${dest_dir:?"Destination missing"}" +: "${file_system:?Filesystem missing}" +: "${mount_point:?Mounting point missing}" +: "${source_dir:?Source missing}" +: "${dest_dir:?Destination missing}" +print-status Mount "${file_system}" to "${mount_point}"... if ! findmnt "${mount_point}" >/dev/null; then - print-status "Mount backup filesystem..." mount "${file_system}" "${mount_point}" print-finish +else + print-finish Already mounted, skip. fi now=$(date "+${date_format}") destination="${mount_point}/${dest_dir}" +print-status Create destination dir "${destination}..." if [[ ! -e "${destination}" ]]; then - print-status "Create destination dir..." mkdir -p "${destination}" print-finish +else + print-finish Already created, skip. fi # Set rsync targets, options -if [[ "${backup_mode}" == "archive" || "${backup_mode}" == "quick" ]]; then +if [[ "${backup_mode}" == archive || "${backup_mode}" == quick ]]; then target="${destination}/actual" opt=(--delete --inplace) else @@ -204,13 +208,13 @@ else opt=("--link-dest=${last}") fi -print-header "Backup files..." +print-header Backup files... rsync -aAXHEh --info=stats1 --info=progress2 "${opt[@]}" "${exclusion[@]}" "${quiet[@]}" "${source_dir}" "${target}" # Post backup steps case "${backup_mode}" in snapshot) - print-status "Manage links for snapshots..." + print-status Manage links for snapshots... # Remove symlink to previous snapshot rm -f "${last}" # Create new symlink to latest snapshot for the next backup to hardlink @@ -218,24 +222,26 @@ case "${backup_mode}" in print-finish if [[ -n "${expire_date}" ]]; then - print-status "Delete expired snapshots..." + print-status Delete expired snapshots... find "${destination}" -mindepth 1 -maxdepth 1 -mtime "+${expire_date}" -exec rm -rf {} \; print-finish fi ;; archive) + print-status Create archive dir "${destination}/${archive_dir}..." if [[ ! -e "${destination}/${archive_dir}" ]]; then - print-status "Create archive dir..." mkdir -p "${destination}/${archive_dir}" print-finish + else + print-finish Already created, skip. fi - print-status "Compress files..." + print-status Compress files... tar -C "${destination}" -I "pigz --fast" --sort=name -cf "${destination}/${archive_dir}/${archive_prefix}${now}.tar.gz" actual/ print-finish if [[ -n "${expire_date}" ]]; then - print-status "Delete expired archives..." + print-status Delete expired archives... find "${destination}/${archive_dir}" -mindepth 1 -maxdepth 1 -mtime "+${expire_date}" -exec rm -rf {} \; print-finish fi @@ -243,13 +249,14 @@ case "${backup_mode}" in *) ;; esac -# Unmount filesystem +print-status Unmounting "${mount_point}..." if findmnt "${mount_point}" >/dev/null; then - print-status "Unmounting backup filesystem..." umount "${mount_point}" || true print-finish +else + print-finish Already unmounted, skip. fi -print-finish "Backup finished" +print-finish Backup finished exit 0 diff --git a/bin/benchmark b/bin/benchmark index 5929b2f..90fc31e 100755 --- a/bin/benchmark +++ b/bin/benchmark @@ -18,7 +18,7 @@ ############ # Version -version=1.2.3 +version=1.2.4 # Individual benchmark time limit (seconds) # Quick benchmark test_run_time_quick=6 @@ -155,9 +155,9 @@ _cpu-app-test() { # shellcheck disable=SC2312 time_aes=$({ TIME="%e seconds" time openssl enc -e -aes-256-cbc -pass pass:12345678 -pbkdf2 >/dev/null &1) - printf "%-20s %s\n" "SHA256-hashing:" "${time_sha}" - printf "%-20s %s\n" "bzip2-compressing:" "${time_bzip}" - printf "%-20s %s\n" "AES-encrypting:" "${time_aes}" + printf "%-20s %s\n" SHA256-hashing: "${time_sha}" + printf "%-20s %s\n" bzip2-compressing: "${time_bzip}" + printf "%-20s %s\n" AES-encrypting: "${time_aes}" rm -f test_file.cpu } @@ -168,7 +168,7 @@ _cpu-app-test() { ## @param $@ Params for benchmark ##################################### _run-benchmark() { - local type="${1?:"Benchmark type missing"}" + local type="${1?:Benchmark type missing}" local params=("--time=${test_run_time}") # Compile params @@ -181,15 +181,15 @@ _run-benchmark() { return 0 ;; *) - echo "Not supported type" >&2 + echo Not supported type >&2 return 1 ;; esac # Run benchmark - [[ "${type}" == "disk" ]] && sysbench "${params[@]}" prepare + [[ "${type}" == disk ]] && sysbench "${params[@]}" prepare sysbench "${params[@]}" run - [[ "${type}" == "disk" ]] && sysbench "${params[@]}" cleanup + [[ "${type}" == disk ]] && sysbench "${params[@]}" cleanup return 0 } @@ -200,8 +200,8 @@ _run-benchmark() { ## @param $2 Raw results ####################################### _filter-results() { - local type="${1?:"Benchmark type missing"}" - local raw="${2?:"Raw results missing"}" + local type="${1?:Benchmark type missing}" + local raw="${2?:Raw results missing}" local filter case "${type}" in @@ -214,7 +214,7 @@ _filter-results() { return 0 ;; *) - echo "Not supported type" >&2 + echo Not supported type >&2 return 1 ;; esac @@ -327,7 +327,7 @@ _print-summary() { printf "%-15s [%-10s] : " "${params[1]}" "${params[0]}" ;; *) - echo "Not supported testname: ${testname}" >&2 + echo Not supported testname: "${testname}" >&2 exit 1 ;; esac @@ -338,7 +338,7 @@ _print-summary() { done # Print CPU application test results - if [[ "${testname}" == "cpu" ]]; then + if [[ "${testname}" == cpu ]]; then printf "\nApplication test\n----------------\n\n%s\n" "${summary[cpu_app]}" fi } @@ -392,7 +392,7 @@ while :; do ;; "") break ;; *) - echo "Not supported option: ${1}" >&2 + echo Not supported option: "${1}" >&2 _usage exit 1 ;; @@ -429,7 +429,7 @@ case "${benchmark_depth}" in ;; *) if [[ -z "${sys_check}" ]]; then - echo "Not supported depth: ${benchmark_depth}" >&2 + echo Not supported depth: "${benchmark_depth}" >&2 _usage exit 1 fi @@ -444,7 +444,7 @@ if [[ -z "${sys_check}" ]]; then required_commands=(dd sha256sum bzip2 openssl lsblk sysbench curl) for cmd in "${required_commands[@]}"; do if ! command -v "${cmd}" >/dev/null 2>&1; then - echo "Missing dependency: ${cmd}" >&2 + echo Missing dependency: "${cmd}" >&2 exit 1 fi done @@ -492,10 +492,10 @@ _print-sysinfo | tee "${output_file}" trap _clean-up EXIT INT TERM # Run Benchmarks -echo "Start Benchmarking..." +echo Start Benchmarking... for type in "${tests[@]}"; do - if [[ "${type}" == "cpu" ]]; then - echo "Running CPU application test..." + if [[ "${type}" == cpu ]]; then + echo Running CPU application test... results=$(_cpu-app-test) summary[cpu_app]=$(_filter-results cpu_app "${results}") fi @@ -506,7 +506,7 @@ for type in "${tests[@]}"; do selector="${type}_${i}" IFS=";" read -r -a params <<<"${run_param}" - echo "Running ${type^^} benchmark #$((i + 1))..." + echo Running "${type^^}" benchmark "#$((i + 1))..." results=$(_run-benchmark "${type}" "${params[@]}") summary[${selector}]=$(_filter-results "${type}" "${results}") @@ -514,7 +514,7 @@ for type in "${tests[@]}"; do done done -echo "Benchmarking finished." +echo Benchmarking finished. echo ## Summary diff --git a/bin/clean b/bin/clean index ab7b904..8f45133 100755 --- a/bin/clean +++ b/bin/clean @@ -16,7 +16,7 @@ ########## _version() { cat <&2 _usage exit 1 ;; @@ -125,11 +125,11 @@ print Done. # User caches for user in "${users[@]}"; do if ! homedir=$(getent passwd "${user}" | cut -d: -f6); then - echo "User not exits: ${user}" 1>&2 + echo User not exits: "${user}" >&2 exit 1 fi - print "Clean-up for ${user}..." + print Clean-up for "${user}..." print -n Empty trash bin... sudo test -d "${homedir}/.local/share/Trash" && sudo find "${homedir}/.local/share/Trash" -mindepth 1 -delete @@ -151,7 +151,7 @@ for user in "${users[@]}"; do sudo test -d "${homedir}/snap/spotify/common/.cache" && sudo find "${homedir}/snap/spotify/common/.cache" -mindepth 1 -delete print Done. - print "Cleanup finished for ${user}." + print Cleanup finished for "${user}." done exit 0 diff --git a/bin/generate-moduli b/bin/generate-moduli index 065877d..177f8bf 100755 --- a/bin/generate-moduli +++ b/bin/generate-moduli @@ -16,8 +16,8 @@ ## @param $2 Output file path ######################################### _generate-DH-primes() { - local bit="${1?:"Bit missing"}" - local output_file="${2?:"Output file name missing"}" + local bit="${1?:Bit missing}" + local output_file="${2?:Output file name missing}" local candidates candidates=$(mktemp --tmpdir DH_candidates.XXXXXXXX) @@ -37,13 +37,13 @@ IFS=$'\n\t' source "${ES_SHELL_LOADER}" # Parse options -IFS=$',' read -r -a bits <<<"${1:-4096,6144,7680,8192}" +IFS=, read -r -a bits <<<"${1:-4096,6144,7680,8192}" results_file="${2:-DH_moduli}" # Validate bits for bit in "${bits[@]}"; do if [[ ! "${bit}" =~ ^[0-9]+$ ]]; then - echo "Only integers as BIT_SIZE." + echo Only integers as BIT_SIZE. exit 1 fi done @@ -66,7 +66,7 @@ done print-finish found=$(wc -l < "${results_file}") -echo "Primes found: $((found - 1))" +echo Primes found: $((found - 1)) print-run-time diff --git a/bin/pass-man b/bin/pass-man index f019644..8c4c1d4 100755 --- a/bin/pass-man +++ b/bin/pass-man @@ -21,7 +21,7 @@ timer=6h _usage() { cat </dev/null | cut -f1) + total=$(sudo du --summarize --block-size=1 "${dir}" 2>/dev/null | cut -f1) while IFS= read -r -d '' line; do read -r size dir <<<"${line}" printf "%3d%% %8s %s\n" "$((size * 100 / total))" "$(numfmt --to=iec "${size}")" "${dir}" - done < <(du --null --block-size=1 -d1 "${dir}" 2>/dev/null | sort -nz) + done < <(sudo du --null --block-size=1 -d1 "${dir}" 2>/dev/null | sort -nz) } diff --git a/lib/certificate.sh b/lib/certificate.sh index 6534177..99b92b9 100644 --- a/lib/certificate.sh +++ b/lib/certificate.sh @@ -13,9 +13,9 @@ ## @param $3 CSR subject ########################################### csr-create() { - local priv_key="${1?:"Private key path missing"}" - local csr="${2?:"CSR path missing"}" - local subject="${3?:"CSR subject missing"}" + local priv_key="${1?:Private key path missing}" + local csr="${2?:CSR path missing}" + local subject="${3?:CSR subject missing}" shift 3 openssl req \ -new \ @@ -36,11 +36,11 @@ csr-create() { ## @param $5 Validity in days ########################################### csr-sign() { - local ca_priv_key="${1?:"CA private key path missing"}" - local ca_cert="${2?:"CA cert path missing"}" - local csr="${3?:"CSR path missing"}" - local cert="${4?:"Certificate path missing"}" - local validity="${5?:"Valid days missing"}" + local ca_priv_key="${1?:CA private key path missing}" + local ca_cert="${2?:CA cert path missing}" + local csr="${3?:CSR path missing}" + local cert="${4?:Certificate path missing}" + local validity="${5?:Valid days missing}" local subject site tmp_config shift 5 @@ -74,7 +74,7 @@ EOF ## @param $1 CSR path ######################### csr-view() { - local csr="${1?:"CSR path missing"}" + local csr="${1?:CSR path missing}" shift openssl req \ -noout \ @@ -87,7 +87,7 @@ csr-view() { ## @param $1 Key path ######################### cert-key() { - local key="${1?:"Key path missing"}" + local key="${1?:Key path missing}" shift openssl genpkey \ -aes-256-cbc \ @@ -104,17 +104,17 @@ cert-key() { ## @param $4 Certificate subject #################################### cert-selfsigned() { - local priv_key="${1?:"Private key path missing"}" - local cert="${2?:"Certificate path missing"}" - local validity="${3?:"Valid days missing"}" - local subject="${4?:"Certificate subject missing"}" + local priv_key="${1?:Private key path missing}" + local cert="${2?:Certificate path missing}" + local validity="${3?:Valid days missing}" + local subject="${4?:Certificate subject missing}" shift 4 openssl req \ -new \ -x509 \ -sha512 \ -extensions v3_ca \ - -addext "keyUsage=critical,keyCertSign,cRLSign" \ + -addext keyUsage=critical,keyCertSign,cRLSign \ -key "${priv_key}" \ -out "${cert}" \ -days "${validity}" \ @@ -131,12 +131,12 @@ cert-selfsigned() { ## @param $6 Validity in days #################################### cert-create() { - local priv_key="${1?:"Private key path missing"}" - local subject="${2?:"CSR subject missing"}" - local ca_priv_key="${3?:"CA private key path missing"}" - local ca_cert="${4?:"CA cert path missing"}" - local cert="${5?:"Certificate path missing"}" - local validity="${6?:"Valid days missing"}" + local priv_key="${1?:Private key path missing}" + local subject="${2?:CSR subject missing}" + local ca_priv_key="${3?:CA private key path missing}" + local ca_cert="${4?:CA cert path missing}" + local cert="${5?:Certificate path missing}" + local validity="${6?:Valid days missing}" local csr csr=$(mktemp) @@ -149,7 +149,7 @@ cert-create() { ## @param $1 Cert path ########################## cert-view() { - local cert="${1?:"Certificate path missing"}" + local cert="${1?:Certificate path missing}" shift openssl x509 \ -noout \ diff --git a/lib/db.sh b/lib/db.sh index f2009b7..399c1bd 100644 --- a/lib/db.sh +++ b/lib/db.sh @@ -26,7 +26,7 @@ db-dump-wrapper() { ## @param $* Extra args to mysqldump ######################################## db-dump-full-db() { - local db="${1:?"DB name missing"}" + local db="${1:?DB name missing}" shift db-dump-wrapper --routines "${@}" "${db}" } @@ -38,7 +38,7 @@ db-dump-full-db() { ## @param $* Tables ######################## db-dump-full-tables() { - local db="${1:?"DB name missing"}" + local db="${1:?DB name missing}" shift db-dump-wrapper "${db}" "${@}" } @@ -50,7 +50,7 @@ db-dump-full-tables() { ## @param $* Extra args to mysqldump ######################################## db-dump-structure-db() { - local db="${1:?"DB name missing"}" + local db="${1:?DB name missing}" shift db-dump-wrapper --no-data --routines "${@}" "${db}" } @@ -62,7 +62,7 @@ db-dump-structure-db() { ## @param $* Tables ######################## db-dump-structure-tables() { - local db="${1:?"DB name missing"}" + local db="${1:?DB name missing}" shift db-dump-wrapper --no-data "${db}" "${@}" } @@ -74,7 +74,7 @@ db-dump-structure-tables() { ## @param $* Extra args to mysqldump ######################################## db-dump-data-db() { - local db="${1:?"DB name missing"}" + local db="${1:?DB name missing}" shift db-dump-wrapper --no-create-info --skip-extended-insert --skip-triggers "${@}" "${db}" } @@ -86,7 +86,7 @@ db-dump-data-db() { ## @param $* Tables ######################## db-dump-data-tables() { - local db="${1:?"DB name missing"}" + local db="${1:?DB name missing}" shift db-dump-wrapper --no-create-info --skip-extended-insert --skip-triggers "${db}" "${@}" } @@ -97,8 +97,8 @@ db-dump-data-tables() { ## @param $2 Pattern ######################## db-list-tables() { - local db="${1:?"DB name missing"}" - local pattern="${2:?"Pattern missing"}" + local db="${1:?DB name missing}" + local pattern="${2:?Pattern missing}" # shellcheck disable=SC2312 db-query "${db}" "SHOW TABLES LIKE '${pattern}'" -B | sed '1d' } @@ -110,8 +110,8 @@ db-list-tables() { ## @param $* Extra args to mysql #################################### db-query() { - local db="${1:?"DB name missing"}" - local query="${2:?"Query missing"}" + local db="${1:?DB name missing}" + local query="${2:?Query missing}" shift 2 sudo mysql -D "${db}" -e "${query}" "${@}" } @@ -125,10 +125,10 @@ db-query() { ## @param $5 Delimiter ################################ db-replace() { - local db="${1:?"DB name missing"}" - local table="${2:?"Table missing"}" - local search="${3:?"Search string missing"}" - local replace="${4:?"Replace string missing"}" + local db="${1:?DB name missing}" + local table="${2:?Table missing}" + local search="${3:?Search string missing}" + local replace="${4:?Replace string missing}" local delim="${5:-@}" local tmp diff --git a/lib/dev.sh b/lib/dev.sh index 94c47fa..76b5805 100644 --- a/lib/dev.sh +++ b/lib/dev.sh @@ -10,7 +10,7 @@ ## @param $1 Remote host ################################### debug-tunnel-open() { - local remote="${1?:"Remote missing"}" + local remote="${1?:Remote missing}" ssh-tunnel-open -fqN -R 9003:localhost:9003 "${remote}" } @@ -19,7 +19,7 @@ debug-tunnel-open() { ## @param $1 Remote host #################################### debug-tunnel-close() { - local remote="${1?:"Remote missing"}" + local remote="${1?:Remote missing}" ssh-tunnel-close -fqN -R 9003:localhost:9003 "${remote}" } @@ -30,8 +30,8 @@ debug-tunnel-close() { ## @param $@ Extra args to mkdocs build ########################################### build-mkdocs() { - local config_file="${1?:"mkdocs config file missing"}" - local destination="${2?:"Build destination missing"}" + local config_file="${1?:mkdocs config file missing}" + local destination="${2?:Build destination missing}" shift 2 mkdocs build -f "${config_file}" -d "${destination}" "${@}" @@ -75,21 +75,21 @@ ppretty-json() { ## @param $2 Which part to bump (major, minor, patch) ######################################################## bump-version() { - local version="${1?:"Version missing"}" - local part="${2?:"Version part missing"}" + local version="${1?:Version missing}" + local part="${2?:Version part missing}" local major minor patch IFS=$'.' read -r major minor patch <<< "${version}" if [[ ! "${major}" =~ ^[0-9]+$ ]]; then - print-error "Invalid version" + print-error Invalid version return 1 fi if [[ ! "${minor}" =~ ^[0-9]+$ ]]; then - print-error "Invalid version" + print-error Invalid version return 1 fi if [[ ! "${patch}" =~ ^[0-9]+$ ]]; then - print-error "Invalid version" + print-error Invalid version return 1 fi @@ -107,7 +107,7 @@ bump-version() { patch=$((patch + 1)) ;; *) - print-error "Invalid part" + print-error Invalid part return 1 ;; esac diff --git a/lib/error.sh b/lib/error.sh index deee374..248ef1f 100644 --- a/lib/error.sh +++ b/lib/error.sh @@ -29,7 +29,7 @@ export _E_NO_CHANGE=32 ## @default 1 ############################### error-exit() { - print-error "${1:-"fatal error"}" + print-error "${1:-fatal error}" exit "${2:-1}" } diff --git a/lib/files.sh b/lib/files.sh index b1f059c..99149d3 100644 --- a/lib/files.sh +++ b/lib/files.sh @@ -11,10 +11,10 @@ ## @param $1 File ########################## dir-file() { - local file="${1:?"File missing"}" + local file="${1:?File missing}" if [[ ! -f "${file}" ]]; then - print-error "Not a file" + print-error Not a file return 1 fi @@ -42,7 +42,7 @@ dir-parents() { dir=$(realpath "${dir}") if [[ ! -d "${dir}" ]]; then - print-error "Not a directory" + print-error Not a directory return 1 fi @@ -62,8 +62,8 @@ dir-parents() { ## @param $2 Directory ############################################# give() { - local user="${1:?"User missing"}" - local dir="${2:?"Directory missing"}" + local user="${1:?User missing}" + local dir="${2:?Directory missing}" shift 2 sudo chgrp -R "${user}" "${dir}" "${@}" sudo chmod -R o-rwx "${dir}" "${@}" diff --git a/lib/git.sh b/lib/git.sh index 4bef73c..e5cec9a 100644 --- a/lib/git.sh +++ b/lib/git.sh @@ -15,20 +15,20 @@ ## @default origin ############################################### ggit-merge() { - local branch="${1?:"Source branch missing"}" + local branch="${1?:Source branch missing}" local into="${2:-main}" local remote="${3:-origin}" - print-header "Pull remote changes for ${branch} from ${remote}" + print-header Pull remote changes for "${branch}" from "${remote}" git checkout "${branch}" || return 1 git pull --stat "${remote}" "${branch}" || return 1 - print-header "Pull remote changes for ${into} from ${remote}" + print-header Pull remote changes for "${into}" from "${remote}" git checkout "${into}" || return 1 git pull --stat "${remote}" "${into}" || return 1 - print-header "Merge and push" + print-header Merge and push git merge --stat --no-ff "${branch}" -m "Merge branch '${branch}' into ${into}" || return 1 git push "${remote}" "${into}" || return 1 - print-header "Delete branches" + print-header Delete branches git branch -d "${branch}" git branch -d -r "${remote}/${branch}" } @@ -36,7 +36,7 @@ ggit-merge() { ## Check git repo status ######################## ggit-report() { - print-header "Git status" + print-header Git status git status || return 1 print-header Branches git --no-pager branch -a -l -vv @@ -49,7 +49,7 @@ ggit-report() { ## @param $1 How many commits from HEAD ########################################### ggit-fix() { - local commits="${1?:"Commits missing"}" + local commits="${1?:Commits missing}" git rebase -i "HEAD~${commits}" } @@ -64,9 +64,9 @@ ggit-pull() { local branch="${1:-main}" local remote="${2:-origin}" - print-header "Switch to ${branch}" + print-header Switch to "${branch}" git checkout "${branch}" || return 1 - print-header "Pull remote changes for ${branch} from ${remote}" + print-header Pull remote changes for "${branch}" from "${remote}" git pull "${remote}" "${branch}" || return 1 git submodule update --init } @@ -78,15 +78,15 @@ ggit-pull() { ## @default origin ################################## ggit-update() { - local branch="${1?:"Branch missing"}" + local branch="${1?:Branch missing}" local remote="${2:-origin}" - print-header "Fetch ${remote}" + print-header Fetch "${remote}" git fetch --prune "${remote}" || return 1 - print-header "Delete old ${branch}" + print-header Delete old "${branch}" git checkout -b "${branch}-temp" "${branch}" || return 1 git branch -D "${branch}" || return 1 - print-header "Checkout new ${branch} from ${remote}" + print-header Checkout new "${branch}" from "${remote}" git checkout -b "${branch}" --recurse-submodules --track "${remote}/${branch}" || return 1 git branch -D "${branch}-temp" } @@ -97,8 +97,8 @@ ggit-update() { ## @param $2 Branch B ######################### ggit-diff() { - local branch_a="${1?:"Branch A missing"}" - local branch_b="${2?:"Branch B missing"}" + local branch_a="${1?:Branch A missing}" + local branch_b="${2?:Branch B missing}" git diff --stat "${branch_a}" "${branch_b}" } @@ -111,17 +111,17 @@ ggit-diff() { ## @default origin ######################################## ggit-base() { - local branch_src="${1?:"Branch to rebase missing"}" + local branch_src="${1?:Branch to rebase missing}" local branch_onto="${2:-main}" local remote="${3:-origin}" - print-header "Switch to ${branch_src}" + print-header Switch to "${branch_src}" git switch "${branch_src}" || return 1 - print-header "Rebase ${branch_src} onto ${branch_onto}" + print-header Rebase "${branch_src}" onto "${branch_onto}" git rebase "${branch_onto}" || return 1 - print-header "Push ${branch_src}" + print-header Push "${branch_src}" git push "${remote}" "+${branch_src}" || return 1 - print-header "Switch to ${branch_onto}" + print-header Switch to "${branch_onto}" git switch "${branch_onto}" || return 1 } @@ -136,7 +136,7 @@ ggit-base() { ## @default origin ################################# ggit-tag() { - local name="${1?:"Tag name missing"}" + local name="${1?:Tag name missing}" local commit="${2:-HEAD}" local message="${3:-${name}}" local remote="${4:-origin}" @@ -154,7 +154,7 @@ ggit-tag() { ## @default origin ######################################################### ggit-version() { - local part="${1?:"Version part missing"}" + local part="${1?:Version part missing}" local commit="${2:-HEAD}" local remote="${3:-origin}" local version @@ -208,7 +208,7 @@ ggit-stat-daily() { git --no-pager log \ --author="${user}" \ --format=%ad \ - --date="format:%H" "${date_filter[@]}" \ + --date=format:%H "${date_filter[@]}" \ | sort \ | uniq -c \ | awk '{printf("%11s | %6s\n",$2,$1)}' @@ -237,7 +237,7 @@ ggit-stat-weekly() { git --no-pager log \ --author="${user}" \ --format=%ad \ - --date="format:%u" "${date_filter[@]}" \ + --date=format:%u "${date_filter[@]}" \ | sort \ | uniq -c \ | awk '{printf("%18s | %6s\n",$2,$1)}' @@ -266,7 +266,7 @@ ggit-stat-monthly() { git --no-pager log \ --author="${user}" \ --format=%ad \ - --date="format:%d" "${date_filter[@]}" \ + --date=format:%d "${date_filter[@]}" \ | sort \ | uniq -c \ | awk '{printf("%12s | %6s\n",$2,$1)}' diff --git a/lib/github.sh b/lib/github.sh index 2cf0935..5e7fe12 100644 --- a/lib/github.sh +++ b/lib/github.sh @@ -11,7 +11,7 @@ ## @param $@ Extra args to gh ################################# ghub-list() { - local owner="${1?:"Owner missing"}" + local owner="${1?:Owner missing}" shift gh repo list "${owner}" --limit 100 "${@}" } @@ -22,7 +22,7 @@ ghub-list() { ## @param $@ Extra args to gh ################################# ghub-get() { - local owner="${1?:"Owner missing"}" + local owner="${1?:Owner missing}" shift # shellcheck disable=SC2312 gh repo list "${owner}" --limit 100 --json nameWithOwner --jq ".[].nameWithOwner" "${@}" | LC_COLLATE=C sort @@ -64,7 +64,7 @@ ghub-settings() { ## @param $@ Extra args to gh ################################# ghub-repo-clone() { - local repo="${1?:"Repo missing"}" + local repo="${1?:Repo missing}" shift gh repo clone "${repo}" "${@}" } @@ -75,7 +75,7 @@ ghub-repo-clone() { ## @param $@ Extra args to gh ################################# ghub-repo-new() { - local repo="${1?:"Repo missing"}" + local repo="${1?:Repo missing}" shift gh repo create "${repo}" "${@}" } @@ -86,7 +86,7 @@ ghub-repo-new() { ## @param $@ Extra args to gh ################################# ghub-sync-config() { - local repo="${1?:"Repo missing"}" + local repo="${1?:Repo missing}" shift gh repo edit "${repo}" \ --delete-branch-on-merge \ @@ -103,8 +103,8 @@ ghub-sync-config() { ## @param $2 Master repo ############################ ghub-sync-labels() { - local repo="${1?:"Repo missing"}" - local template="${2?:"Template missing"}" + local repo="${1?:Repo missing}" + local template="${2?:Template missing}" local label labels_current labels_template exist_in_template # Sync labels @@ -125,7 +125,7 @@ ghub-sync-labels() { ## @param $@ Topics ####################### ghub-topic() { - local repo="${1?:"Repo missing"}" + local repo="${1?:Repo missing}" local topics=() shift @@ -145,8 +145,8 @@ ghub-topic() { ## @param $@ Topics ################################ ghub-repo-template() { - local repo="${1?:"Repo missing"}" - local template="${2?:"Template missing"}" + local repo="${1?:Repo missing}" + local template="${2?:Template missing}" shift 2 ghub-repo-new "${repo}" --private --template "${template}" @@ -163,8 +163,8 @@ ghub-repo-template() { ## @param $@ Extra args to command ###################################### ghub-foreach-owner() { - local owner="${1?:"Owner missing"}" - local command="${2?:"Command missing"}" + local owner="${1?:Owner missing}" + local command="${2?:Command missing}" local repo shift 2 @@ -182,9 +182,9 @@ ghub-foreach-owner() { ## @param $@ Extra args to command ###################################### ghub-foreach-topic() { - local owner="${1?:"Owner missing"}" - local topic="${2?:"Topic missing"}" - local command="${3?:"Command missing"}" + local owner="${1?:Owner missing}" + local topic="${2?:Topic missing}" + local command="${3?:Command missing}" local repo shift 3 @@ -216,9 +216,9 @@ ghub-issue() { ## @param $@ Extra args to gh #################################### ghub-secret-set() { - local repo="${1?:"Repo missing"}" - local name="${2?:"Secret name missing"}" - local value="${3?:"Secret value missing"}" + local repo="${1?:Repo missing}" + local name="${2?:Secret name missing}" + local value="${3?:Secret value missing}" shift 3 gh secret set "${name}" --body "${value}" --app actions --repo "${repo}" "${@}" } @@ -230,8 +230,8 @@ ghub-secret-set() { ## @param $@ Extra args to gh ################################################ ghub-pr() { - local title="${1?:"Title missing"}" - local body="${2?:"PR body missing"}" + local title="${1?:Title missing}" + local body="${2?:PR body missing}" shift 2 if [[ -r "${body}" ]]; then diff --git a/lib/network.sh b/lib/network.sh index 0d2705f..5fad2f1 100644 --- a/lib/network.sh +++ b/lib/network.sh @@ -11,8 +11,8 @@ ## @param $2 DKIM selector ##################################### dns-mail() { - local domain="${1?:"Domain missing"}" - local selector="${2?:"DKIM selector missing"}" + local domain="${1?:Domain missing}" + local selector="${2?:DKIM selector missing}" print-header SPF dig TXT "${domain}" diff --git a/lib/process.sh b/lib/process.sh index 436b4c3..860dac0 100644 --- a/lib/process.sh +++ b/lib/process.sh @@ -11,7 +11,7 @@ check-root() { local uid uid=$(id -u) if [[ "${uid}" -ne 0 ]]; then - print-error "Run as root!" + print-error Run as root! return 1 fi return 0 @@ -50,8 +50,8 @@ foreach-subdir() { ## @param $2 Command to pipe to #################################### foreach-subdir-pipe() { - local command="${1?:"Command missing"}" - local pipe="${2?:"Pipe command missing"}" + local command="${1?:Command missing}" + local pipe="${2?:Pipe command missing}" # shellcheck disable=SC2312 while IFS= read -r -d '' dir; do print-section "${dir}" @@ -68,7 +68,7 @@ foreach-subdir-pipe() { ## @param $1 Command name ################################ proc-is-running() { - local command="${1?:"Command missing"}" + local command="${1?:Command missing}" shift pgrep -f "${@}" "${command}" >/dev/null 2>&1 } @@ -96,7 +96,7 @@ monitor-proc-memory() { # Print header if [[ "${counter}" -eq 1 ]]; then - printf "%20s %20s %20s\n" "Date" "RSS (KiB)" "MAX RSS (KiB)" + printf "%20s %20s %20s\n" Date "RSS (KiB)" "MAX RSS (KiB)" for ((i = 0 ; i < 62 ; i++)); do echo -n "-" done @@ -112,7 +112,7 @@ monitor-proc-memory() { max_print=$(numfmt --grouping <<<"${max}") printf "%20s %20s %20s\n" "${date}" "${rss_print}" "${max_print}" else - print-error "ps error (propably more than 1 process matched command)" + print-error "ps error (probably more than 1 process matched command)" return 1 fi ;; diff --git a/lib/ssh.sh b/lib/ssh.sh index cff9547..b0c3e01 100644 --- a/lib/ssh.sh +++ b/lib/ssh.sh @@ -13,8 +13,8 @@ ## @default 12 hours ################################# unlock-key() { - local key="${1?:"Path to SSH key missing"}" - local pass_path="${2?:"Path to password missing"}" + local key="${1?:Path to SSH key missing}" + local pass_path="${2?:Path to password missing}" local cache_time="${3:-12h}" local password public_key current_identities @@ -43,7 +43,7 @@ ssh-tunnel-open() { # Check if successful if ! proc-is-running "ssh ${*}"; then - echo "Failed to open tunnel" + echo Failed to open tunnel >&2 return 1 fi } @@ -63,7 +63,7 @@ ssh-tunnel-close() { # Check if successful if proc-is-running "ssh ${*}"; then - echo "Failed to close tunnel" + echo Failed to close tunnel >&2 return 1 fi } @@ -74,8 +74,8 @@ ssh-tunnel-close() { ## @param $2 Local port ############################ socks5-tunnel-open() { - local remote="${1?:"Remote missing"}" - local port="${2?:"Local port missing"}" + local remote="${1?:Remote missing}" + local port="${2?:Local port missing}" ssh-tunnel-open -fqN -D "${port}" "${remote}" } @@ -85,8 +85,8 @@ socks5-tunnel-open() { ## @param $2 Local port ############################ socks5-tunnel-close() { - local remote="${1?:"Remote missing"}" - local port="${2?:"Local port missing"}" + local remote="${1?:Remote missing}" + local port="${2?:Local port missing}" ssh-tunnel-close -fqN -D "${port}" "${remote}" } @@ -96,8 +96,8 @@ socks5-tunnel-close() { ## @param $2 Comment for key ################################ ssh-create-key() { - local key_name="${1?:"Key name missing"}" - local comment="${2?:"Key comment missing"}" + local key_name="${1?:Key name missing}" + local comment="${2?:Key comment missing}" shift 2 ssh-keygen \ -t ed25519 \ @@ -117,12 +117,12 @@ ssh-create-key() { ## @param $6 Path to user public key - this will be signed ############################################################## ssh-sign-user() { - local validity="${1?:"Validity interval missing"}" - local ca_key_path="${2?:"Path to CA key missing"}" - local identity="${3?:"Key identity missing"}" - local principals="${4?:"Principals missing"}" - local serial="${5?:"Serial number missing"}" - local pubkey_path="${6?:"User public key path missing"}" + local validity="${1?:Validity interval missing}" + local ca_key_path="${2?:Path to CA key missing}" + local identity="${3?:Key identity missing}" + local principals="${4?:Principals missing}" + local serial="${5?:Serial number missing}" + local pubkey_path="${6?:User public key path missing}" shift 6 ssh-keygen \ -V "${validity}" \ @@ -138,7 +138,7 @@ ssh-sign-user() { ## @param $1 Path to certificate #################################### ssh-view-cert() { - local cert="${1?:"Certificate path missing"}" + local cert="${1?:Certificate path missing}" shift ssh-keygen -L -f "${cert}" "${@}" } diff --git a/lib/text.sh b/lib/text.sh index f027db5..c12854f 100644 --- a/lib/text.sh +++ b/lib/text.sh @@ -11,7 +11,7 @@ ## @param $* Items to join ################################## implode() { - local IFS="${1:?"Field separator missing"}" + local IFS="${1:?Field separator missing}" shift echo "${*}" } @@ -22,7 +22,7 @@ implode() { ## @param $2 Section (read only this section) ################################################# read-file-cfg() { - local file="${1:?"File missing"}" + local file="${1:?File missing}" local section="${2:-}" local contents @@ -41,7 +41,7 @@ read-file-cfg() { ## @param $1 String to encode ################################ urlencode() { - local string="${1:?"String missing"}" + local string="${1:?String missing}" local encoded= local pos char enc_char @@ -79,7 +79,7 @@ urldecode() { ## @param $@ Extra args to 'find' #################################### lines-dir() { - local dir="${1:?"Directory missing"}" + local dir="${1:?Directory missing}" shift # shellcheck disable=SC2312 diff --git a/lib/ui.sh b/lib/ui.sh index 824fd7b..8a1298d 100644 --- a/lib/ui.sh +++ b/lib/ui.sh @@ -9,14 +9,26 @@ ## FORMAT CODES ## ################## -export TXT_NORM="\e[0m" -export TXT_BOLD="\e[1m" -export TXT_RED="\e[31m" -export TXT_GREEN="\e[32m" -export TXT_YELLOW="\e[33m" -export TXT_BLUE="\e[34m" -export TXT_PURPLE="\e[35m" -export BACK_BLUE="\e[44m" +if [[ -z "${TERM:-}" ]]; then + export TERM=xterm-256color +fi + +# shellcheck disable=SC2155 +export TXT_NORM=$(tput sgr0) +# shellcheck disable=SC2155 +export TXT_BOLD=$(tput bold) +# shellcheck disable=SC2155 +export TXT_RED=$(tput setaf 1) +# shellcheck disable=SC2155 +export TXT_GREEN=$(tput setaf 2) +# shellcheck disable=SC2155 +export TXT_YELLOW=$(tput setaf 3) +# shellcheck disable=SC2155 +export TXT_BLUE=$(tput setaf 4) +# shellcheck disable=SC2155 +export TXT_PURPLE=$(tput setaf 5) +# shellcheck disable=SC2155 +export BACK_BLUE=$(tput setab 4) ############### ## FUNCTIONS ## @@ -28,7 +40,8 @@ export BACK_BLUE="\e[44m" ######################## print-error() { [[ -n "${ES_PRINT_HUSH:-}" ]] && return 0 - echo -e "${TXT_RED}${TXT_BOLD}${*}${TXT_NORM}" >&2 + # shellcheck disable=SC2086 + echo -e ${TXT_RED}${TXT_BOLD}${*}${TXT_NORM} >&2 } ## Print title @@ -51,7 +64,8 @@ print-title() { for ((i = 0 ; i < padding_left ; i++)); do echo -n " " done - echo -n "${title}" + # shellcheck disable=SC2086 + echo -n ${title} for ((i = 0 ; i < padding_right ; i++)); do echo -n " " done @@ -71,7 +85,8 @@ print-section() { local header="${*}" [[ -n "${ES_PRINT_HUSH:-}" ]] && return 0 echo - echo -e "${BACK_BLUE}${header}${TXT_NORM}" + # shellcheck disable=SC2086 + echo -e ${BACK_BLUE}${header}${TXT_NORM} echo -ne "${BACK_BLUE}" for ((i = 0 ; i < ${#header} ; i++)); do echo -n "~" @@ -85,8 +100,8 @@ print-section() { ####################### print-header() { [[ -n "${ES_PRINT_HUSH:-}" ]] && return 0 - echo - echo -e "${TXT_YELLOW}${*}${TXT_NORM}" + # shellcheck disable=SC2086 + echo -e ${TXT_YELLOW}${*}${TXT_NORM} } ## Print status message @@ -95,7 +110,8 @@ print-header() { ######################## print-status() { [[ -n "${ES_PRINT_HUSH:-}" ]] && return 0 - echo -ne "${TXT_YELLOW}${*}${TXT_NORM}" + # shellcheck disable=SC2086 + echo -ne ${TXT_YELLOW}${*}${TXT_NORM} } ## Print OK message @@ -105,7 +121,8 @@ print-status() { ######################## print-finish() { [[ -n "${ES_PRINT_HUSH:-}" ]] && return 0 - echo -e "${TXT_GREEN}${TXT_BOLD}${*:-Done.}${TXT_NORM}" + # shellcheck disable=SC2086 + echo -e ${TXT_GREEN}${TXT_BOLD}${*:-Done.}${TXT_NORM} } ## Script running time @@ -120,7 +137,7 @@ print-run-time() { min=$((sec / 60)) sec=$((sec % 60)) - echo "Running time:" + echo Running time: printf "%d hour(s) %02d min(s) %02d second(s)\n" "${hour}" "${min}" "${sec}" } @@ -131,7 +148,7 @@ print-run-time() { #################################### confirm() { read -r -p "${*:-Are you sure? (y/n) }" - [[ ${REPLY} == "y" || ${REPLY} == "Y" ]] && return 0 || return 1 + [[ ${REPLY} == y || ${REPLY} == Y ]] } ## Clear console screen