fix all spellsheck

This commit is contained in:
fatalerrors
2026-04-16 17:53:46 +02:00
parent c011f03aee
commit 066f2e353e
15 changed files with 137 additions and 54 deletions

View File

@@ -44,36 +44,42 @@
# -n, --no-dir Never create a host directory # -n, --no-dir Never create a host directory
utaz() utaz()
{ {
# shellcheck disable=SC2329
_ununzip() _ununzip()
{ {
unzip -o "$1" -d "$2" >/dev/null 2>&1 unzip -o "$1" -d "$2" >/dev/null 2>&1
} }
# shellcheck disable=SC2329
_untar() _untar()
{ {
tar -xf "$1" -C "$2" tar -xf "$1" -C "$2"
} }
# shellcheck disable=SC2329
_ungzip() _ungzip()
{ {
tar -xzf "$1" -C "$2" tar -xzf "$1" -C "$2"
} }
# shellcheck disable=SC2329
_unbzip2() _unbzip2()
{ {
tar -xjf "$1" -C "$2" tar -xjf "$1" -C "$2"
} }
# shellcheck disable=SC2329
_unxz() _unxz()
{ {
tar -xJf "$1" -C "$2" tar -xJf "$1" -C "$2"
} }
# shellcheck disable=SC2329
_unlzop() _unlzop()
{ {
lzop -d "$1" -o "$2/$(basename "${1%.*}")" lzop -d "$1" -o "$2/$(basename "${1%.*}")"
} }
# shellcheck disable=SC2329
_unlzip() _unlzip()
{ {
if command -v plzip >/dev/null 2>&1; then if command -v plzip >/dev/null 2>&1; then
@@ -83,16 +89,19 @@ utaz()
fi fi
} }
# shellcheck disable=SC2329
_ununrar() _ununrar()
{ {
unrar x -o+ "$1" "$2/" >/dev/null 2>&1 unrar x -o+ "$1" "$2/" >/dev/null 2>&1
} }
# shellcheck disable=SC2329
_ununarj() _ununarj()
{ {
unarj e "$1" "$2/" >/dev/null 2>&1 unarj e "$1" "$2/" >/dev/null 2>&1
} }
# shellcheck disable=SC2329
_unlha() _unlha()
{ {
# lha typically extracts into the current directory # lha typically extracts into the current directory
@@ -100,40 +109,47 @@ utaz()
(cd "$2" && lha -x "../$1") >/dev/null 2>&1 (cd "$2" && lha -x "../$1") >/dev/null 2>&1
} }
# shellcheck disable=SC2329
_ununace() _ununace()
{ {
unace x "$1" "$2/" >/dev/null 2>&1 unace x "$1" "$2/" >/dev/null 2>&1
} }
# shellcheck disable=SC2329
_un7z() _un7z()
{ {
7z x "$1" -o"$2/" >/dev/null 2>&1 7z x "$1" -o"$2/" >/dev/null 2>&1
} }
# shellcheck disable=SC2329
_unzstd() _unzstd()
{ {
# Zstd decompresses files directly, often requiring tar for archives # Zstd decompresses files directly, often requiring tar for archives
tar --zstd -xf "$1" -C "$2" tar --zstd -xf "$1" -C "$2"
} }
# shellcheck disable=SC2329
_uncpio() _uncpio()
{ {
# CPIO requires careful directory handling # CPIO requires careful directory handling
(cd "$2" && cpio -id < "../$1") >/dev/null 2>&1 (cd "$2" && cpio -id < "../$1") >/dev/null 2>&1
} }
# shellcheck disable=SC2329
_uncabextract() _uncabextract()
{ {
# Requires 'cabextract' package # Requires 'cabextract' package
cabextract "$1" -d "$2/" >/dev/null 2>&1 cabextract "$1" -d "$2/" >/dev/null 2>&1
} }
# shellcheck disable=SC2329
_undeb() _undeb()
{ {
# Extracts data content from a Debian package # Extracts data content from a Debian package
dpkg-deb -x "$1" "$2/" >/dev/null 2>&1 dpkg-deb -x "$1" "$2/" >/dev/null 2>&1
} }
# shellcheck disable=SC2329
_unrpm() _unrpm()
{ {
# Extracts CPIO-based payload from an RPM package # Extracts CPIO-based payload from an RPM package
@@ -141,8 +157,9 @@ utaz()
rpm2cpio "$1" | (cd "$2/" && cpio -idmv) >/dev/null 2>&1 rpm2cpio "$1" | (cd "$2/" && cpio -idmv) >/dev/null 2>&1
} }
local PARSED=$(getopt -o hdcn --long help,delete,create-dir,no-dir -n 'utaz' -- "$@") local PARSED
PARSED=$(getopt -o hdcn --long help,delete,create-dir,no-dir -n 'utaz' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
disp E "Invalid options, use \"utaz --help\" to display usage." disp E "Invalid options, use \"utaz --help\" to display usage."
return 1 return 1
@@ -314,10 +331,10 @@ utaz()
fi fi
disp I "Processing archive ${f} with ${extractor}..." disp I "Processing archive ${f} with ${extractor}..."
mkdir -p "${dir}" if ! mkdir -p "${dir}"; then
[[ $? -gt 0 ]] &&
disp E "The filesystem can't create directories, exit!" && disp E "The filesystem can't create directories, exit!" &&
return 1 return 1
fi
${extractor} "${f}" "${dir}" ${extractor} "${f}" "${dir}"
case $? in case $? in
@@ -390,6 +407,7 @@ export -f utaz
# -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest] # -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]
taz() taz()
{ {
# shellcheck disable=SC2329
_doxz() _doxz()
{ {
command -v xz >/dev/null 2>&1 || { command -v xz >/dev/null 2>&1 || {
@@ -397,17 +415,19 @@ taz()
return 127 return 127
} }
[[ $4 ]] && local verb='-v' local verb=()
[[ $4 ]] && verb=('-v')
# Display a warning for this format # Display a warning for this format
disp W "xz format is not suited for long term archiving." disp W "xz format is not suited for long term archiving."
disp I "See https://www.nongnu.org/lzip/xz_inadequate.html for details." disp I "See https://www.nongnu.org/lzip/xz_inadequate.html for details."
# Compresse to xz (lzma2) - Deprecated # Compresse to xz (lzma2) - Deprecated
xz $verb --compress --keep -$3 -T $2 $1 xz "${verb[@]}" --compress --keep "-$3" -T "$2" "$1"
return $? return $?
} }
# shellcheck disable=SC2329
_dolz() _dolz()
{ {
local procopt="--threads $2" local procopt="--threads $2"
@@ -425,13 +445,16 @@ taz()
disp W "Consider installing plzip to obtain multithreading abilities." disp W "Consider installing plzip to obtain multithreading abilities."
} }
[[ $4 ]] && local verb="-vv" local opt=()
[[ $4 ]] && opt=('-vv')
opt+=("$procopt")
# Compresse au format lzip (lzma) # Compresse au format lzip (lzma)
$command $verb $procopt --keep -$3 $1 $command "${opt[@]}" --keep "-$3" "$1"
return $? return $?
} }
# shellcheck disable=SC2329
_dogz() _dogz()
{ {
local procopt="--processes $2" local procopt="--processes $2"
@@ -449,13 +472,16 @@ taz()
disp W "Consider installing pigz to obtain multithreading abilities." disp W "Consider installing pigz to obtain multithreading abilities."
} }
[[ $4 ]] && local verb="--verbose" local opt=()
[[ $4 ]] && opt=('--verbose')
opt+=("$procopt")
# Compresse au format bz2 # Compresse au format bz2
$command $verb $procopt --keep -$3 $1 $command "${opt[@]}" --keep "-$3" "$1"
return $? return $?
} }
# shellcheck disable=SC2329
_dobz2() _dobz2()
{ {
local procopt="-p$2" local procopt="-p$2"
@@ -473,13 +499,16 @@ taz()
disp W "Consider installing pbzip2 to obtain multithreading abilities." disp W "Consider installing pbzip2 to obtain multithreading abilities."
} }
[[ $4 ]] && local verb="-v" local opt=()
[[ $4 ]] && opt=('-v')
opt+=("$procopt")
# Compresse au format bz2 # Compresse au format bz2
$command $verb --compress $procopt --keep -$3 $1 $command "${opt[@]}" --compress --keep "-$3" "$1"
return $? return $?
} }
# shellcheck disable=SC2329
_dolzo() _dolzo()
{ {
command -v lzop >/dev/null 2>&1 || { command -v lzop >/dev/null 2>&1 || {
@@ -487,16 +516,18 @@ taz()
return 127 return 127
} }
[[ $4 ]] && local verb='-v' local verb=()
[[ $4 ]] && verb=('-v')
[[ $2 -gt 1 ]] && disp W "lzop doesn't support multithreading, falling back to 1 thread." [[ $2 -gt 1 ]] && disp W "lzop doesn't support multithreading, falling back to 1 thread."
# Compresse au format lzo # Compresse au format lzo
lzop --keep -$3 $1 lzop "${verb[@]}" --keep "-$3" "$1"
return $? return $?
} }
local PARSED local PARSED
PARSED=$(getopt -o hdf:p:vq123456789 --long help,delete,format:,parallel:,verbose,quiet --name "taz" -- "$@") PARSED=$(getopt -o hdf:p:vq123456789 --long help,delete,format:,parallel:,verbose,quiet --name "taz" -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
disp E "Invalid options, use \"taz --help\" to display usage." disp E "Invalid options, use \"taz --help\" to display usage."
return 1 return 1
@@ -587,8 +618,7 @@ taz()
if [[ -d "$item" ]]; then if [[ -d "$item" ]]; then
disp I "\t Creating $item.tar... " disp I "\t Creating $item.tar... "
tar -cf "$item.tar" "$item" if ! tar -cf "$item.tar" "$item"; then
if [[ ! $? -eq 0 ]]; then
disp E "tar file creation failed, skipping to next item." disp E "tar file creation failed, skipping to next item."
continue continue
fi fi
@@ -602,8 +632,9 @@ taz()
# Skip compression part if tar is asked # Skip compression part if tar is asked
if [[ $compform != "tar" ]]; then if [[ $compform != "tar" ]]; then
disp I "\t Compressing archive..." disp I "\t Compressing archive..."
_do$compform "$fname" "$nproc" "$complevel" "$verbose" local exec_code=0
[[ ! $? -eq 0 ]] && case $? in "_do$compform" "$fname" "$nproc" "$complevel" "$verbose" || exec_code=$?
[[ ! $exec_code -eq 0 ]] && case $exec_code in
127) 127)
disp E "Compression program unavailable, aborting." disp E "Compression program unavailable, aborting."
return 127 return 127

View File

@@ -70,6 +70,7 @@ settrace()
local PARSED local PARSED
PARSED=$(getopt -oh --long help,on,off,status,force -- "$@") PARSED=$(getopt -oh --long help,on,off,status,force -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"settrace --help\" to display usage." disp E "Invalid options, use \"settrace --help\" to display usage."
return 1 return 1

View File

@@ -41,8 +41,8 @@ expandlist()
{ {
local separator="${EXPANDLIST_DEFAULT_SEPARATOR:- }" local separator="${EXPANDLIST_DEFAULT_SEPARATOR:- }"
local PARSED local PARSED
PARSED=$(getopt -o hs:n --long help,separator:,newline -n 'expandlist' -- "$@") PARSED=$(getopt -o hs:n --long help,separator:,newline -n 'expandlist' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"expandlist --help\" to display usage." disp E "Invalid options, use \"expandlist --help\" to display usage."
return 1 return 1
@@ -87,6 +87,7 @@ expandlist()
# True glob expansion when wildcards are present. # True glob expansion when wildcards are present.
if [[ "$item" == *'*'* || "$item" == *'?'* || "$item" == *'['* ]]; then if [[ "$item" == *'*'* || "$item" == *'?'* || "$item" == *'['* ]]; then
# shellcheck disable=SC2206 # We actually want the word splitting
expanded=( $item ) expanded=( $item )
else else
expanded=( "$item" ) expanded=( "$item" )
@@ -127,7 +128,7 @@ clean()
# Define short and long options # Define short and long options
local PARSED local PARSED
PARSED=$(getopt -o hrsf --long help,recurs,shell,force -n 'clean' -- "$@") PARSED=$(getopt -o hrsf --long help,recurs,shell,force -n 'clean' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"clean --help\" to display usage." disp E "Invalid options, use \"clean --help\" to display usage."
return 1 return 1
@@ -215,10 +216,14 @@ mcd()
disp E "Missing parameter. Use \"mcd --help\" to display usage." disp E "Missing parameter. Use \"mcd --help\" to display usage."
return 1 return 1
fi fi
mkdir -pv "$1" && cd "$1" || { if ! mkdir -pv "$1"; then
printf "Failed create and/or change directory.\n" disp E "Failed to create directory \"$1\"."
return 1 return 1
} fi
if ! cd "$1"; then
disp E "Failed to change to directory \"$1\"."
return 1
fi
} }
export -f mcd export -f mcd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -241,6 +246,7 @@ rmspc()
local PARSED local PARSED
PARSED=$(getopt -o hr:c::vs --long help,recursive,subst-char::,verbose,shell -n 'rmspc' -- "$@") PARSED=$(getopt -o hr:c::vs --long help,recursive,subst-char::,verbose,shell -n 'rmspc' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"rmspc --help\" to display usage." disp E "Invalid options, use \"rmspc --help\" to display usage."
return 1 return 1
@@ -359,7 +365,7 @@ file_stats()
# Short: H, d, m, M, c, t, a, x:, X: # Short: H, d, m, M, c, t, a, x:, X:
# Long: human, details, average, median, count, total, all, ext:, ext-list:, min:, max:, help # Long: human, details, average, median, count, total, all, ext:, ext-list:, min:, max:, help
PARSED=$(getopt -o HdmMctax:X:h --long human,details,average,median,count,total,all,ext:,ext-list:,min:,max:,help -n 'file_stats' -- "$@") PARSED=$(getopt -o HdmMctax:X:h --long human,details,average,median,count,total,all,ext:,ext-list:,min:,max:,help -n 'file_stats' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"file_stats --help\" to display usage." disp E "Invalid options, use \"file_stats --help\" to display usage."
return 1 return 1
@@ -578,6 +584,7 @@ findbig()
local PARSED local PARSED
PARSED=$(getopt -o hdl:x --long help,details,limit:,one-fs -n 'findbig' -- "$@") PARSED=$(getopt -o hdl:x --long help,details,limit:,one-fs -n 'findbig' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"findbig --help\" to display usage." disp E "Invalid options, use \"findbig --help\" to display usage."
return 1 return 1
@@ -660,6 +667,7 @@ findzero()
local PARSED local PARSED
# o: options, long: long equivalents # o: options, long: long equivalents
PARSED=$(getopt -o hdx --long help,details,one-fs,delete -n 'findzero' -- "$@") PARSED=$(getopt -o hdx --long help,details,one-fs,delete -n 'findzero' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"findzero --help\" to display usage." disp E "Invalid options, use \"findzero --help\" to display usage."
return 1 return 1
@@ -733,6 +741,7 @@ finddead()
local PARSED local PARSED
PARSED=$(getopt -o hdx --long help,details,one-fs,delete -n 'finddead' -- "$@") PARSED=$(getopt -o hdx --long help,details,one-fs,delete -n 'finddead' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"finddead --help\" to display usage." disp E "Invalid options, use \"finddead --help\" to display usage."
return 1 return 1

View File

@@ -48,6 +48,7 @@ busy()
# Short: h, p:, d: # Short: h, p:, d:
# Long: help, pattern:, delay: # Long: help, pattern:, delay:
PARSED=$(getopt -o hp:d: --long help,pattern:,delay: -n 'busy' -- "$@") PARSED=$(getopt -o hp:d: --long help,pattern:,delay: -n 'busy' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"busy --help\" to display usage." disp E "Invalid options, use \"busy --help\" to display usage."
return 1 return 1
@@ -89,7 +90,8 @@ busy()
done done
# Convert milliseconds to seconds for 'sleep' # Convert milliseconds to seconds for 'sleep'
local delay_s=$(awk "BEGIN{ local delay_s
delay_s=$(awk "BEGIN{
printf \"%.3f\", $delay_ms / 1000 }") printf \"%.3f\", $delay_ms / 1000 }")
# Monitor /dev/urandom # Monitor /dev/urandom

View File

@@ -39,6 +39,8 @@
# Usage: help # Usage: help
help() help()
{ {
# shellcheck disable=SC2154 # color code in disp.sh
# shellcheck disable=SC2059 # printf format is a color variable
printf "${BIWhite}Welcome to your profile! Here is a list of available commands:${DEFAULTCOL}\n\n" printf "${BIWhite}Welcome to your profile! Here is a list of available commands:${DEFAULTCOL}\n\n"
printf "busy\t\tMonitor /dev/urandom for a hex pattern — look busy\n" printf "busy\t\tMonitor /dev/urandom for a hex pattern — look busy\n"
printf "check_updates\tCheck for new versions of profile\n" printf "check_updates\tCheck for new versions of profile\n"

View File

@@ -42,6 +42,7 @@ ver()
local PARSED local PARSED
PARSED=$(getopt -o h --long help -n 'ver' -- "$@") PARSED=$(getopt -o h --long help -n 'ver' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"ver --help\" to display usage." disp E "Invalid options, use \"ver --help\" to display usage."
return 1 return 1
@@ -82,6 +83,7 @@ meteo()
local PARSED local PARSED
PARSED=$(getopt -o h --long help -n 'meteo' -- "$@") PARSED=$(getopt -o h --long help -n 'meteo' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"meteo --help\" to display usage." disp E "Invalid options, use \"meteo --help\" to display usage."
return 1 return 1
@@ -133,6 +135,7 @@ showinfo()
local PARSED local PARSED
PARSED=$(getopt -o h --long help -n 'showinfo' -- "$@") PARSED=$(getopt -o h --long help -n 'showinfo' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"showinfo --help\" to display usage." disp E "Invalid options, use \"showinfo --help\" to display usage."
return 1 return 1

View File

@@ -51,6 +51,7 @@ setlocale()
{ {
local PARSED local PARSED
PARSED=$(getopt -o h --long help -n 'setlocale' -- "$@") PARSED=$(getopt -o h --long help -n 'setlocale' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"setlocale --help\" to display usage." disp E "Invalid options, use \"setlocale --help\" to display usage."
return 1 return 1

View File

@@ -70,9 +70,32 @@ dwl()
# Honour preferred tool from configuration; fall back to auto-detection. # Honour preferred tool from configuration; fall back to auto-detection.
local preferred="${DWL_PREFERRED_TOOL:-}" local preferred="${DWL_PREFERRED_TOOL:-}"
_try_curl() { [ -z "$output" ] && curl -sL "$url" || curl -sL -o "$output" "$url"; } _try_curl()
_try_wget() { [ -z "$output" ] && wget -qO- "$url" || wget -q -O "$output" "$url"; } {
_try_fetch() { [ -z "$output" ] && fetch -o - "$url" || fetch -o "$output" "$url"; } if [[ -z "$output" ]]; then
curl -sL "$url"
else
curl -sL -o "$output" "$url"
fi
}
_try_wget()
{
if [[ -z "$output" ]]; then
wget -qO- "$url"
else
wget -q -O "$output" "$url"
fi
}
_try_fetch()
{
if [[ -z "$output" ]]; then
fetch -o - "$url"
else
fetch -o "$output" "$url"
fi
}
if [[ -n "$preferred" ]]; then if [[ -n "$preferred" ]]; then
command -v "$preferred" >/dev/null 2>&1 || { command -v "$preferred" >/dev/null 2>&1 || {

View File

@@ -43,6 +43,7 @@ pkgs()
local PARSED local PARSED
PARSED=$(getopt -o hi --long help,ignore-case -n 'pkgs' -- "$@") PARSED=$(getopt -o hi --long help,ignore-case -n 'pkgs' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"pkgs --help\" to display usage." disp E "Invalid options, use \"pkgs --help\" to display usage."
return 1 return 1
@@ -87,10 +88,10 @@ pkgs()
command -v dpkg >/dev/null 2>&1 && local cmd="dpkg -l" command -v dpkg >/dev/null 2>&1 && local cmd="dpkg -l"
command -v rpm >/dev/null 2>&1 && local cmd="rpm -qa" command -v rpm >/dev/null 2>&1 && local cmd="rpm -qa"
if [[ -z $cmd ]]; then if [[ -z $cmd ]]; then
disp E "No usable package manager seems unavialable." disp E "No usable package manager seems avialable."
return 2 return 2
fi fi
$cmd | grep $grep_opt $pkg $cmd | grep "$grep_opt" "$pkg"
} }
export -f pkgs export -f pkgs
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View File

@@ -121,6 +121,7 @@ ppn()
# -e: select all processes # -e: select all processes
# -o: specify custom output columns (PID and Command name) # -o: specify custom output columns (PID and Command name)
# grep -w: ensures exact word matching so 'bash' doesn't match 'dbash' # grep -w: ensures exact word matching so 'bash' doesn't match 'dbash'
# shellcheck disable=SC2009 # pgrep do not offer the -w switch
ps -eo pid,comm | grep -w "$1" ps -eo pid,comm | grep -w "$1"
} }
export -f ppn export -f ppn
@@ -200,8 +201,7 @@ ku()
disp E "Usage: ku <username1 [username2 ...]>" disp E "Usage: ku <username1 [username2 ...]>"
return 1 return 1
fi fi
local users="$@" for u in "$@"; do
for u in $users; do
if ! id "$u" >/dev/null 2>&1; then if ! id "$u" >/dev/null 2>&1; then
disp E "User '$u' does not exist." disp E "User '$u' does not exist."
return 1 return 1
@@ -238,7 +238,8 @@ kt()
return 1 return 1
fi fi
local children_pids=$(pgrep -P "$parent_pid") local children_pids
children_pids=$(pgrep -P "$parent_pid")
for pid in $children_pids; do for pid in $children_pids; do
kt "$pid" "$@" || break kt "$pid" "$@" || break

View File

@@ -252,7 +252,7 @@ function timer_start
# into a human-readable string with appropriate units (us, ms, s, m, h # into a human-readable string with appropriate units (us, ms, s, m, h
function timer_stop function timer_stop
{ {
local delta_us=$((($(timer_now) - $timer_start) / 1000)) local delta_us=$((($(timer_now) - timer_start) / 1000))
local us=$((delta_us % 1000)) local us=$((delta_us % 1000))
local ms=$(((delta_us / 1000) % 1000)) local ms=$(((delta_us / 1000) % 1000))
local s=$(((delta_us / 1000000) % 60)) local s=$(((delta_us / 1000000) % 60))

View File

@@ -65,6 +65,7 @@ genpwd()
PARSED=$(getopt -o hsnule:L:o: --long \ PARSED=$(getopt -o hsnule:L:o: --long \
help,nosymbols,nonumbers,noup,nolow,extracars:,length:,occurences:,occurrences: \ help,nosymbols,nonumbers,noup,nolow,extracars:,length:,occurences:,occurrences: \
-n 'genpwd' -- "$@") -n 'genpwd' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then return 1; fi if [[ $? -ne 0 ]]; then return 1; fi
eval set -- "$PARSED" eval set -- "$PARSED"

View File

@@ -44,6 +44,7 @@ rmhost()
local -a known_hosts_files=() local -a known_hosts_files=()
PARSED=$(getopt -o ha --long help,all-users -n 'rmhost' -- "$@") PARSED=$(getopt -o ha --long help,all-users -n 'rmhost' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then return 1; fi if [[ $? -ne 0 ]]; then return 1; fi
eval set -- "$PARSED" eval set -- "$PARSED"
@@ -194,6 +195,7 @@ ssr()
ssh_default_opts=(-Y) ssh_default_opts=(-Y)
fi fi
# shellcheck disable=SC2029
ssh "${ssh_default_opts[@]}" root@"$srv" "$@" ssh "${ssh_default_opts[@]}" root@"$srv" "$@"
} }
export -f ssr export -f ssr

View File

@@ -54,6 +54,7 @@ check_updates()
local vfile="" lastver="" local vfile="" lastver=""
PARSED=$(getopt -o hq --long help,quiet -n 'check_updates' -- "$@") PARSED=$(getopt -o hq --long help,quiet -n 'check_updates' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"check_updates --help\" to display usage." disp E "Invalid options, use \"check_updates --help\" to display usage."
return 2 return 2
@@ -128,6 +129,7 @@ profile_upgrade()
local tmpdir="" archive="" extracted_root="" local tmpdir="" archive="" extracted_root=""
PARSED=$(getopt -o hf:t:nFb:g --long help,file:,tmpdir:,dry-run,force,branch:,switch-to-git -n 'profile_upgrade' -- "$@") PARSED=$(getopt -o hf:t:nFb:g --long help,file:,tmpdir:,dry-run,force,branch:,switch-to-git -n 'profile_upgrade' -- "$@")
# shellcheck disable=SC2181 # getopt return code is checked immediately after
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"profile_upgrade --help\" to display usage." disp E "Invalid options, use \"profile_upgrade --help\" to display usage."
return 2 return 2
@@ -215,8 +217,8 @@ profile_upgrade()
} }
if (( dry_run )); then if (( dry_run )); then
disp I "[dry-run] rm -rf \"$MYPATH\"/.git" disp I "[dry-run] rm -rf \"$MYPATH\"/.git"
disp I "[dry-run] git clone "$BASE_URL" \"$MYPATH\"" disp I "[dry-run] git clone $BASE_URL \"$MYPATH\""
[[ -n "$branch" ]] && disp I "[dry-run] git -C \"$MYPATH\" checkout "$branch"" [[ -n "$branch" ]] && disp I "[dry-run] git -C \"$MYPATH\" checkout $branch"
return 0 return 0
fi fi

View File

@@ -45,7 +45,7 @@ fi
if ((BASH_VERSINFO[0] < 4)) || [[ ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 3 ]]; then if ((BASH_VERSINFO[0] < 4)) || [[ ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 3 ]]; then
echo "[ Error ] This profile requires Bash 4.3 or higher." echo "[ Error ] This profile requires Bash 4.3 or higher."
echo "Current version: $BASH_VERSION" echo "Current version: $BASH_VERSION"
return 1 2>/dev/null || exit 1 (return 0 2>/dev/null) && return 1 || exit 1
fi fi
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -66,17 +66,17 @@ pathremove()
export "$pathvar=$newpath" export "$pathvar=$newpath"
} }
pathprepend() #pathprepend() # Unused for now, but might be useful in the future
{ #{
[[ -z "$1" ]] && return 0 # [[ -z "$1" ]] && return 0
local pathvar="${2:-PATH}" # local pathvar="${2:-PATH}"
[[ "$pathvar" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] || { # [[ "$pathvar" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] || {
printf "pathprepend: unsafe variable name '%s'\n" "$pathvar" >&2 # printf "pathprepend: unsafe variable name '%s'\n" "$pathvar" >&2
return 1 # return 1
} # }
pathremove "$1" "$pathvar" # pathremove "$1" "$pathvar"
export "$pathvar=$1${!pathvar:+:${!pathvar}}" # export "$pathvar=$1${!pathvar:+:${!pathvar}}"
} #}
pathappend() pathappend()
{ {
@@ -98,7 +98,7 @@ parse_conf()
{ {
local config_file="$1" local config_file="$1"
local current_section="" local current_section=""
local line key value local key value
[[ ! -f "$config_file" ]] && return 1 [[ ! -f "$config_file" ]] && return 1
@@ -140,6 +140,7 @@ parse_conf()
# Use a nameref for safe, eval-free assignment # Use a nameref for safe, eval-free assignment
local -n current_array="CONF_$current_section" local -n current_array="CONF_$current_section"
# shellcheck disable=SC2034 # Dynamic var creation
current_array["$key"]="$value" current_array["$key"]="$value"
fi fi
done < "$config_file" done < "$config_file"
@@ -168,6 +169,7 @@ load_alias()
# Only alias if the base command is executable # Only alias if the base command is executable
if command -v "$base_cmd" >/dev/null 2>&1; then if command -v "$base_cmd" >/dev/null 2>&1; then
# shellcheck disable=SC2139 # Dynamic alias creation
alias "$key"="$cmd" alias "$key"="$cmd"
fi fi
done done
@@ -204,10 +206,11 @@ load_conf()
# Because we're more likely to be sourced, we use BASH_SOURCE to get the path # Because we're more likely to be sourced, we use BASH_SOURCE to get the path
# of the sourced file instead of $0 # of the sourced file instead of $0
if [[ -z "$PROFILE_PATH" ]]; then if [[ -z "$PROFILE_PATH" ]]; then
export MYPATH=$(dirname "$(realpath -s "${BASH_SOURCE[0]}")") MYPATH=$(dirname "$(realpath -s "${BASH_SOURCE[0]}")")
else else
export MYPATH="$PROFILE_PATH" MYPATH="$PROFILE_PATH"
fi fi
export MYPATH
if [[ ! -e "$MYPATH/profile.sh" ]]; then if [[ ! -e "$MYPATH/profile.sh" ]]; then
echo "[ Warning ] Path detection failed, trying to use pwd..." echo "[ Warning ] Path detection failed, trying to use pwd..."
MYPATH=$(pwd) MYPATH=$(pwd)
@@ -219,7 +222,8 @@ fi
if [[ ! -s "$MYPATH/version" ]]; then if [[ ! -s "$MYPATH/version" ]]; then
echo "[ Warning ] Impossible to determine running version of profile, your installation might be broken." echo "[ Warning ] Impossible to determine running version of profile, your installation might be broken."
fi fi
export PROFVERSION=$(cat "$MYPATH"/version) PROFVERSION=$(cat "$MYPATH"/version)
export PROFVERSION
# Build PATH environment variable # Build PATH environment variable
if [[ $EUID -eq 0 ]]; then if [[ $EUID -eq 0 ]]; then
@@ -262,7 +266,7 @@ if [[ $INTERACTIVE ]]; then
# The value must match one of the alias names defined in SET_LOCALE so that # The value must match one of the alias names defined in SET_LOCALE so that
# the corresponding set<alias> function exists after build_locale_shortcuts. # the corresponding set<alias> function exists after build_locale_shortcuts.
if [[ -n "${DEFAULT_LANG:-}" ]]; then if [[ -n "${DEFAULT_LANG:-}" ]]; then
local _lang_fn="set${DEFAULT_LANG}" _lang_fn="set${DEFAULT_LANG}"
if declare -F "$_lang_fn" >/dev/null 2>&1; then if declare -F "$_lang_fn" >/dev/null 2>&1; then
"$_lang_fn" "$_lang_fn"
else else