3 Commits

Author SHA1 Message Date
fatalerrors
2ece711e1a huge longrun improvements 2026-03-06 17:46:26 +01:00
fatalerrors
39a7e7b40f version bump 2026-03-05 11:56:15 +01:00
fatalerrors
6d5d872b71 add a missing fi 2026-03-05 11:49:10 +01:00
18 changed files with 1238 additions and 482 deletions

View File

@@ -7,6 +7,9 @@ Current version from Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
Version history: Version history:
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
# 05/03/2026 v3.6.1
Fix a typo in compress.sh
# 05/03/2026 v3.6.0 # 05/03/2026 v3.6.0
Improved utaz to make it multiformat with lot of it Improved utaz to make it multiformat with lot of it
Introduced ppu and ppn Introduced ppu and ppn

View File

@@ -35,8 +35,13 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Smartly uncompress archives (zip only for now) # Smartly uncompress archives
# ------------------------------------------------------------------------------ # Usage: utaz [option] [directorie(s)|file(s)]
# Options:
# -h, --help Display that help screen
# -d, --delete If decompression succeeded, delete the source file
# -c, --create-dir Always create a host directory
# -n, --no-dir Never create a host directory
utaz() utaz()
{ {
_ununzip() _ununzip()
@@ -136,53 +141,73 @@ utaz()
rpm2cpio "$1" | (cd "$2/" && cpio -idmv) >/dev/null 2>&1 rpm2cpio "$1" | (cd "$2/" && cpio -idmv) >/dev/null 2>&1
} }
for opt in $@; do local PARSED=$(getopt -o hdcn --long help,delete,create-dir,no-dir -n 'utaz' -- "$@")
case ${opt} in
"-h" | "--help") if [ $? -ne 0 ]; then
echo "utaz: uncompress all the given files and/or the ones found in the given" disp E "Invalid options, use \"utaz --help\" to display usage."
echo " directories creating an host directory where needed." return 1
echo fi
echo "Usage: utaz [option] [directorie(s)|file(s)]" eval set -- "$PARSED"
echo while true; do
echo "Options:" case "$1" in
echo " -h, --help Display that help screen" -h|--help)
echo " -d, --delete If decompression succeeded, delete the source file" printf "utaz: uncompress all the given files and/or the ones found in the given\n"
echo " -c, --create-dir Always create a host directory" printf " directories creating an host directory where needed.\n\n"
echo " -n, --no-dir Never create a host directory" printf "Usage: utaz [option] [directorie(s)|file(s)]\n\n"
echo printf "Options:\n"
printf "\t-h, --help\t\tDisplay that help screen\n"
printf "\t-d, --delete\t\tIf decompression succeeded, delete the source file\n"
printf "\t-c, --create-dir\tAlways create a host directory\n"
printf "\t-n, --no-dir\t\tNever create a host directory\n\n"
printf "Supported archive format:\n"
printf "\t- zip\n"
printf "\t- tar.gz, .tgz\n"
printf "\t- tar.bz2, .tbz2\n"
printf "\t- tar.xz, .txz\n"
printf "\t- tar.lz, .tlz\n"
printf "\t- rar\n"
printf "\t- arj\n"
printf "\t- lha, lzh\n"
printf "\t- ace\n"
printf "\t- 7z, p7z\n"
printf "\t- zst\n"
printf "\t- cpio\n"
printf "\t- cab\n"
printf "\t- deb\n"
printf "\t- rpm\n"
return 0 return 0
;; ;;
-d|--delete)
"-d" | "--delete")
local willrm=1 local willrm=1
shift
;; ;;
-c|--create-dir)
"-c" | "--create-dir")
local createdir=1 local createdir=1
shift
;; ;;
-n|--no-dir)
"-n" | "--no-dir")
local nodir=1 local nodir=1
shift
;; ;;
--)
"-"*) shift
disp E "Invalid option, use \"utaz --help\" to display options list" break
echo
return 1
;; ;;
*) *)
# The ${opt%/} writing is to remove trailing / if any disp E "Invalid option, use \"utaz --help\" to display options list"
local LIST="${LIST} ${opt%/}" return 1
;; ;;
esac esac
done done
# The remaining arguments after -- are the files/directories to process,
# "." is used if none is given
local FILES=("$@")
[[ ${#FILES[@]} -eq 0 ]] && FILES=(".")
[[ -n ${createdir} && -n ${nodir} ]] && \ [[ -n ${createdir} && -n ${nodir} ]] && \
disp E "The --create-dir and --no-dir options are mutually exclusive." disp E "The --create-dir and --no-dir options are mutually exclusive."
[[ -z ${LIST} ]] && local LIST="." for zitem in "${FILES[@]}"; do
for zitem in ${LIST}; do
for f in "${zitem}"/*; do for f in "${zitem}"/*; do
local dir="${f%.*}" local dir="${f%.*}"
local extractor="" local extractor=""
@@ -193,13 +218,13 @@ utaz()
*.tar.gz|*.tgz) *.tar.gz|*.tgz)
extractor="_ungzip" extractor="_ungzip"
;; ;;
*.tar.bz2) *.tar.bz2|*.tbz2)
extractor="_unbzip2" extractor="_unbzip2"
;; ;;
*.tar.xz) *.tar.xz|*.txz)
extractor="_unxz" extractor="_unxz"
;; ;;
*.tar.lz) *.tar.lz|*.tlz)
extractor="_unlzop" extractor="_unlzop"
;; ;;
*.tar) *.tar)
@@ -217,7 +242,7 @@ utaz()
*.ace) *.ace)
extractor="_ununace" extractor="_ununace"
;; ;;
*.7z) *.7z|*.p7z)
extractor="_un7z" extractor="_un7z"
;; ;;
*.zst) *.zst)
@@ -261,7 +286,8 @@ utaz()
command -v ${cmd} >/dev/null 2>&1 || { command -v ${cmd} >/dev/null 2>&1 || {
disp E "Binary ${cmd} necessary to extract ${f} is missing." disp E "Binary ${cmd} necessary to extract ${f} is missing."
continue continue
} }
fi
disp I "Processing archive ${f} with ${extractor}..." disp I "Processing archive ${f} with ${extractor}..."
mkdir -p "${dir}" mkdir -p "${dir}"
@@ -276,10 +302,14 @@ utaz()
rm -f "${f}" && disp I "File ${zitem}/${f} deleted." rm -f "${f}" && disp I "File ${zitem}/${f} deleted."
;; ;;
1) 1)
disp W "Compression program returned a warning: deletion canceled." if [[ -n ${willrm} ]]; then
disp W "Compression program returned a warning: deletion canceled."
else
disp W "Compression program returned a warning."
fi
;; ;;
*) *)
disp E "The zip file seems corrupted, failed." disp E "The compressed file ${f} seems corrupted, failed."
rm -rf "${dir}" >/dev/null 2>&1 rm -rf "${dir}" >/dev/null 2>&1
continue continue
;; ;;
@@ -309,10 +339,21 @@ utaz()
done done
} }
export -f utaz export -f utaz
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Compress directories or files into one or more archive # Compress directories or files into one or more archive
# ------------------------------------------------------------------------------ # Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]
# Options:
# -h, --help Display that help screen
# -d, --delete Delete source file or directory after success
# -f, --format Chose archive format in the given list. If several format are
# given, the smalest is kept
# -p, --parallel Number of threads to use (if allowed by underlying utility)
# -v, --verbose Display progress where possible
# -q, --quiet Display less messages (only errors and warnings)
# -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]
taz() taz()
{ {
_doxz() _doxz()
@@ -420,78 +461,92 @@ taz()
return $? return $?
} }
for opt in $@; do local PARSED
case $opt in PARSED=$(getopt -o hdf:p:vq123456789 --long help,delete,format:,parallel:,verbose,quiet --name "taz" -- "$@")
"-h" | "--help") if [ $? -ne 0 ]; then
echo "taz: archive all files of a directory." disp E "Invalid options, use \"taz --help\" to display usage."
echo return 1
echo "Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]" fi
echo eval set -- "$PARSED"
echo "Options:" while true; do
echo " -h, --help Display that help screen" case "$1" in
echo " -d, --delete Delete source file or directory after success" -h|--help)
echo " -f, --format Chose archive format in the given list. If several format are" printf "taz: archive all files of a directory.\n\n"
echo " given, the smalest is kept" printf "Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]\n\n"
echo " -p, --parallel Number of threads to use (if allowed by underlying utility)" printf "Options:\n"
echo " -v, --verbose Display progress where possible" printf "\t-h, --help\tDisplay that help screen\n"
echo " -q, --quiet Display less messages (only errors and warnings)" printf "\t-d, --delete\tDelete source file or directory after success\n"
echo " -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]" printf "\t-f, --format\tChose archive format in the given list. If several format are"
echo printf "\t\t\tgiven, the smalest is kept\n"
echo "Supported archive format:" printf "\t-p, --parallel\tNumber of threads to use (if allowed by underlying utility)\n"
echo " Param.| programs | Algo. | Description" printf "\t-v, --verbose\tDisplay progress where possible\n"
echo " ------+---------------+-------+----------------------------------------" printf "\t-q, --quiet\tDisplay less messages (only errors and warnings)\n"
echo " lz | plzip, lzip | lzma | Safe efficient default format" printf "\t-1, .., -9\tCompression level to use [1=fast/biggest, 9=slow/smallest]\n\n"
echo " xz | xz | lzma2 | Unsafe, not for long term" printf "Supported archive format:\n"
echo " bz2 | pbzip2, bzip2 | bzip2 | Historical but less efficient than lz" printf "\tParam.| programs | Algo. | Description\n"
echo " gz | pigz, gzip | lz77 | Historical, safe, fast" printf "\t------+---------------+-------+----------------------------------------\n"
echo " lzo | lzop | lzo | Very fast but no multithread" printf "\t lz | plzip, lzip | lzma | Safe efficient default format\n"
echo " tar | tar | tar | No compression" printf "\t xz | xz | lzma2 | Unsafe, not for long term\n"
echo printf "\t bz2 | pbzip2, bzip2 | bzip2 | Historical but less efficient than lz\n"
printf "\t gz | pigz, gzip | lz77 | Historical, safe, fast\n"
printf "\t lzo | lzop | lzo | Very fast but no multithread\n"
printf "\t tar | tar | tar | No compression\n"
printf "\n"
return 0 return 0
;; ;;
"-d" | "--delete") -d|--delete)
local willrm=1 local willrm=1
shift
;; ;;
"-f"?* | "--format"?*) -f|--format)
local compform=$(echo "$opt" | cut -f 2- -d '=') local compform=$2
shift 2
;; ;;
"-p"?* | "--parallel"?*) -p|--parallel)
local nproc=$(echo "$opt" | cut -f 2- -d '=') local nproc=$2
shift 2
;; ;;
"-v" | "--verbose") -v|--verbose)
local verbose=1 local verbose=1
shift
;; ;;
"-q" | "--quiet") -q|--quiet)
local quiet=1 local quiet=1
shift
;; ;;
"-"*) -[1-9])
local complevel=$(echo $opt | sed 's/-//') compression="${1#-}"
if ! [[ $complevel =~ ^[1-9]+$ ]]; then shift
disp E "Invalid option, use taz --help to display options list" ;;
echo --)
return 1 shift
fi break
;; ;;
*) *)
local LIST="$LIST ${opt%/}" disp E "Invalid option, use \"taz --help\" to display options list"
return 1
;; ;;
esac esac
done done
# The remaining arguments after -- are the files/directories to process,
# "." is used if none is given
local FILES=("$@")
[[ ${#FILES[@]} -eq 0 ]] && FILES=(".")
[[ ! $compform ]] && compform=lz # safe and efficient (unless data are already compressed) [[ ! $compform ]] && compform=lz # safe and efficient (unless data are already compressed)
[[ ! $nproc ]] && nproc=1 [[ ! $nproc ]] && nproc=1
[[ ! $complevel ]] && complevel=6 [[ ! $complevel ]] && complevel=6
[[ $verbose -gt 1 && $quiet -gt 1 ]] && [[ $verbose -gt 1 && $quiet -gt 1 ]] &&
disp E "The --verbose and --quiet options can't be used together." disp E "The --verbose and --quiet options can't be used together."
for item in $LIST; do for item in "${FILES[@]}"; do
local donetar=0 local donetar=0
disp I "Processing $item..." disp I "Processing $item..."
@@ -536,6 +591,7 @@ taz()
unset quiet unset quiet
} }
export -f taz export -f taz
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# EOF # EOF

View File

@@ -36,27 +36,22 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Display a backtrace # Display a backtrace
# ------------------------------------------------------------------------------ # Usage: backtrace
function backtrace() function backtrace()
{ {
echo "========= Call stack =========" printf "========= Call stack =========\n"
typeset -i i=0 local i=1 # We begin at 1 to ignore backtrace itself
while [[ $i -lt ${#FUNCNAME[@]} ]]; do
local func= printf '%15s() %s:%d\n' \
for func in "${FUNCNAME[@]}"; do "${FUNCNAME[$i]}" "${BASH_SOURCE[$i]}" "${BASH_LINENO[$(( i-1 ))]}"
if [[ $i -ne 0 ]]; then ((i++))
printf '%15s() %s:%d\n' \
"$func" "${BASH_SOURCE[$i]}" "${BASH_LINENO[(($i - 1))]}"
fi
let i++ || true
done done
unset func i unset func i
echo "==============================" printf "==============================\n"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Function to be trapped for errors investigation # Function to be trapped for errors investigation
# ------------------------------------------------------------------------------
function error() function error()
{ {
local errcode=$? local errcode=$?
@@ -66,45 +61,63 @@ function error()
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Activate or deactivate error trapping to display backtrace # Activate or deactivate error trapping to display backtrace
# ------------------------------------------------------------------------------ # Usage: settrace <--on|--off|--status>
settrace() settrace()
{ {
local status="off" local status="off"
[[ $(trap -p ERR) ]] && status="on" [[ $(trap -p ERR) ]] && status="on"
#trap -p ERR #trap -p ERR
for opt in $@; do
case $opt in local PARSED
"-h" | "--help") PARSED=$(getopt -oh --long help,on,off,status -- "$@")
echo "Try to activate backtrace display for script debugging." if [[ $? -ne 0 ]]; then
echo disp E "Invalid options, use \"settrace --help\" to display usage."
echo "Options:" return 1
echo " --on Activate backtrace generation" fi
echo " --off Deactivate backtrace generation" eval set -- "$PARSED"
echo while true; do
echo "That function active a trap event on error. If the script you want to" case $1 in
echo "debug overload the ERR bash trap, it will not work." -h|--help)
echo printf "Try to activate backtrace display for script debugging.\n\n"
printf "Options:\n"
printf "\t--on\t\tActivate backtrace generation\n"
printf "\t--off\t\tDeactivate backtrace generation\n\n"
printf "That function active a trap event on error. If the script you want to\n"
printf "debug overload the ERR bash trap, it will not work.\n"
return 0
;; ;;
"--on") --on)
if [[ $status == "on" ]]; then if [[ ${status} == "on" ]]; then
disp W "ERR signal trap is already set, replacing previous trap!" disp W "ERR signal trap is already set, replacing previous trap!"
fi fi
trap "error" ERR trap "error" ERR
shift
;; ;;
"--off") --off)
if [[ $status != "on" ]]; then if [[ ${status} != "on" ]]; then
disp W "ERR signal trap is already unset!" disp W "ERR signal trap is already unset!"
fi fi
trap - ERR trap - ERR
shift
;; ;;
"--status") --status)
disp "ERR trap signal is ${status}." disp "ERR trap signal is ${status}."
shift
;; ;;
--)
shift
break
;;
*)
disp E "Invalid options, use \"settrace --help\" to display usage."
return 1
;;
esac esac
done done
unset status unset status
} }
export -f settrace export -f settrace
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# EOF # EOF

View File

@@ -36,11 +36,10 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Color definitions # Color definitions
# ------------------------------------------------------------------------------
# Standard 16 colors display declaration # Standard 16 colors display declaration
export DEFAULTFG="\e[0;39m" export DEFAULTFG='\e[0;39m'
export DEFAULTBG="\e[0;49m" export DEFAULTBG='\e[0;49m'
export DEFAULTCOL=${DEFAULTBG}${DEFAULTFG} export DEFAULTCOL="${DEFAULTBG}${DEFAULTFG}"
export RESETCOL=$'\e[0m' export RESETCOL=$'\e[0m'
# Regular Colors # Regular Colors
@@ -112,10 +111,17 @@ export On_IBlue='\e[0;104m'
export On_IPurple='\e[0;105m' export On_IPurple='\e[0;105m'
export On_ICyan='\e[0;106m' export On_ICyan='\e[0;106m'
export On_IWhite='\e[0;107m' export On_IWhite='\e[0;107m'
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Display a message # Display a message
# ------------------------------------------------------------------------------ # Usage: disp <type> <message>
# Types:
# I : info (green)
# W : warning (yellow)
# E : error (red)
# D : debug (cyan)
disp() disp()
{ {
case $1 in case $1 in
@@ -149,4 +155,6 @@ disp()
} }
export -f disp export -f disp
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# EOF # EOF

View File

@@ -36,9 +36,17 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# expandlist : treat wildcards in a file/directory list # expandlist : treat wildcards in a file/directory list
# ------------------------------------------------------------------------------ # Usage: expandlist <item1 [item2 ... itemN]>
expandlist() expandlist()
{ {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
printf "expandlist: Wraps a list of items in double quotes.\n\n"
printf "Usage: expandlist <item1 [item2 ... itemN]>\n\n"
printf "Options:\n"
printf "\t-h, --help\t\tDisplay this help screen\n"
return 0
fi
local result="" local result=""
for item in "$1"; do for item in "$1"; do
for content in "$item"; do for content in "$item"; do
@@ -47,62 +55,78 @@ expandlist()
done done
echo $result echo $result
} }
export -f expandlist
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Clean a directory or a tree from temporary or backup files # Clean a directory or a tree from temporary or backup files
# ------------------------------------------------------------------------------ # Usage: clean [options] [directory1] [...[directoryX]]
# Options:
# -h, --help: display help screen
# -r, --recurs: do a recursive cleaning
# -f, --force: do not ask for confirmation (use with care)
# -s, --shell: do nothing and display what will be executed
clean() clean()
{ {
for opt in $@; do local recursive=0 force=0 outshell=0
case $opt in
"-r" | "--recurs")
local recursive=1
;;
"-h" | "--help") # Define short and long options
echo "clean: erase backup files in the given directories." local PARSED
echo PARSED=$(getopt -o hrsf --long help,recurs,shell,force -n 'clean' -- "$@")
echo "Usage: clean [option] [directory1] [...[directoryX]]"
echo
echo "Options:"
echo " -h, --help Display that help screen"
echo " -r, --recurs Do a recursive cleaning"
echo " -f, --force Do not ask for confirmation (use with care)"
echo " -s, --shell Do nothing and display what will be executed"
echo
return 0
;;
"-s" | "--shell") if [[ $? -ne 0 ]]; then
local outshell=1 disp E "Invalid options, use \"clean --help\" to display usage."
;; return 1
fi
"-f" | "--force") eval set -- "$PARSED"
local force=1
;;
"-"*) while true; do
disp E "Invalid option, use \"clean --help\" to display usage." case "$1" in
echo -r|--recurs)
return 1 local recursive=1
;; shift
;;
*) -h|--help)
local dirlist="$dirlist $opt" printf "clean: erase backup files in the given directories.\n\n"
;; printf "Usage: clean [option] [directory1] [...[directoryX]]\n"
printf "Options:\n"
printf "\t-h, --help\t\tDisplay that help screen\n"
printf "\t-r, --recurs\t\tDo a recursive cleaning\n"
printf "\t-f, --force\t\tDo not ask for confirmation (use with care)\n"
printf "\t-s, --shell\t\tDo nothing and display what will be executed\n"
printf "\n"
return 0
;;
-s|--shell)
local outshell=1
shift
;;
-f|--force)
local force=1
shift
;;
--)
shift
break
;;
*)
disp E "Invalid parameter, use \"clean --help\" to display options list"
return 1
esac esac
done done
[[ ! $dirlist ]] && local dirlist=$(pwd) # Handle remaining arguments as directories
local dirlist=("$@")
[[ ${#dirlist[@]} -eq 0 ]] && dirlist=(".")
[[ ! $recursive ]] && local findopt="-maxdepth 1" [[ ! $recursive ]] && local findopt="-maxdepth 1"
[[ ! $force ]] && local rmopt="-i" [[ ! $force ]] && local rmopt="-i"
unset recursive force unset recursive force
for dir in $dirlist; do for dir in $dirlist; do
local dellist=$(find "$dir" $findopt -type f -name "*~" -o -name "#*#" \ find "$dir" "${findopt[@]}" -type f \( -name "*~" -o -name "#*#" -o -name "*.bak" -o -name ".~*#" \) -print0 | while IFS= read -r -d '' f; do
-o -name "*.bak" -o -name ".~*#")
for f in $dellist; do
if [[ ! $outshell ]]; then if [[ ! $outshell ]]; then
rm $rmopt $f rm $rmopt $f
else else
@@ -113,72 +137,103 @@ clean()
unset outshell dirlist dellist findopt rmopt unset outshell dirlist dellist findopt rmopt
} }
export -f clean export -f clean
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Create a directory then goes inside # Create a directory then goes inside
# ------------------------------------------------------------------------------ # Usage: mcd <directory>
mcd() mcd()
{ {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
printf "mcd: Create a directory and enter it.\n\n"
printf "Usage: mcd <directory>\n"
printf "Options:\n"
printf "\t-h, --help\t\tDisplay this help screen\n"
return 0
fi
if [[ ! $# -eq 1 ]]; then if [[ ! $# -eq 1 ]]; then
disp E "Create a directory then goes inside." disp E "Missing parameter. Use \"mcd --help\" to display usage."
disp E "Usage: mcd <directory>"
return 1 return 1
fi fi
mkdir -pv "$1" && cd "$1" || echo "Failed create or change directory." mkdir -pv "$1" && cd "$1" || {
printf "Failed create and/or change directory.\n"
return 1
}
} }
export -f mcd export -f mcd
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Rename all files in current directory to replace spaces with _ # Rename all files in current directory to replace spaces with _
# ------------------------------------------------------------------------------ # Usage: rmspc [options]
# Options:
# -h, --help: display help screen
# -r, --recursive: treat subdirectories of the given directory
# -c, --subst-char: change the replacement character (default is underscore)
# -v, --verbose: display more details (recursive mode only)
# -s, --shell: do nothing and display commands that would be executed
rmspc() rmspc()
{ {
local lst="" local lst=""
for opt in $@; do local PARSED
case $opt in PARSED=$(getopt -o hr:c::vs --long help,recursive,subst-char::,verbose,shell -n 'rmspc' -- "$@")
"-h" | "--help") if [[ $? -ne 0 ]]; then
echo "rmspc: remove spaces from all filenames in current directories" disp E "Invalid options, use \"rmspc --help\" to display usage."
echo return 1
echo "Usage: rmspc [option]" fi
echo eval set -- "$PARSED"
echo "Options:"
echo " -h, --help Display that help screen"
echo " -r, --recursive Treat subdirectories of the given directory"
echo " -c, --subst-char Change the replacement character (default is underscore)"
echo " -v, --verbose Display more details (recursive mode only)"
echo " -s, --shell Do nothing and display commands that would be executed"
echo
echo "Note: if the --subst-char option is given without parameters, spaces will be"
echo " replaced with nothing (concatenation)."
echo
return 0
;;
"-r" | "--recursive") while true; do
local recurs=1 case "$1" in
;; -h|--help)
printf "rmspc: remove spaces from all filenames in current directories\n\n"
"-c"?* | "--subst-char"?*) printf "Usage: rmspc [option]\n\n"
if [[ $(echo $opt | grep "=") ]]; then printf "Options:\n"
local substchar=$(echo "$opt" | cut -f 2- -d '=') printf "\t-h, --help\t\tDisplay that help screen\n"
else printf "\t-r, --recursive\t\tTreat subdirectories of the given directory\n"
local substchar='none' printf "\t-c, --subst-char\tChange the replacement character (default is underscore)\n"
fi printf "\t-v, --verbose\t\tDisplay more details (recursive mode only)\n"
;; printf "\t-s, --shell\t\tDo nothing and display commands that would be executed\n\n"
printf "Note: if the --subst-char option is given without parameters, spaces will be\n"
"-v" | "--verbose") printf " replaced with nothing (concatenation).\n"
local verb=1 return 0
;; ;;
-r|--recursive)
"-s" | "--shell") local recurs=1
local shell=1 shift
;; ;;
-c|--subst-char)
*) # Handle optional argument for short/long options
disp E "Invalid parameter, use \"rmspc --help\" to display options list" case "$2" in
echo "")
return 1 substchar=""
;; ;;
*)
substchar="$2"
;;
esac
shift 2
;;
-v|--verbose)
local verb=1
shift
;;
-s|--shell)
local shell=1
shift
;;
--)
shift
break
;;
*)
disp E "Invalid parameter, use \"rmspc --help\" to display options list"
echo
return 1
;;
esac esac
done done
@@ -210,38 +265,119 @@ rmspc()
unset lst substchar verb shell newf command mvopt unset lst substchar verb shell newf command mvopt
} }
export -f rmspc export -f rmspc
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# display stats about a file structure # display stats about a file structure
# ------------------------------------------------------------------------------ # Usage: file_stats [options] [path]
# Options:
# -H, --human Human readable sizes\n"
# -d, --details Display details (min/max/average/median)
# -m, --average Display only average size
# -M, --median Display only median size
# -c, --count Display only count of files
# -t, --total Display only total size
# -a, --all Display all stats in human readable format (shortcut for -H -d)
# -x, --ext [ext] Filter by extension (e.g. -x log for .log files)
# -X, --ext-list [list] Filter by multiple extensions (e.g. -X log,txt)
# --min [size] Minimum size (e.g., 10M)
# --max [size] Maximum size (e.g., 100M)
file_stats() file_stats()
{ {
local human=0 details=0 only_avg=0 only_med=0 only_count=0 only_total=0 local human=0 details=0 only_avg=0 only_med=0 only_count=0 only_total=0
local path="." show_all=1 ext_filter="" ext_list="" min_size="" max_size="" local path="." show_all=1 ext_filter="" ext_list="" min_size="" max_size=""
local OPTIND opt
# Analyse options local PARSED
while [[ "$1" =~ ^- ]]; do # Short: H, d, m, M, c, t, a, x:, X:
# 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' -- "$@")
if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"file_stats --help\" to display usage."
return 1
fi
eval set -- "$PARSED"
while true; do
case "$1" in case "$1" in
-H) human=1 ;; -h|--help)
-d) details=1 ;; printf "Usage: file_stats [options] [path]\n\n"
-m) only_avg=1; show_all=0 ;; printf "Options:\n"
-M) only_med=1; show_all=0 ;; printf "\t-H, --human\t\tHuman readable sizes\n"
-c) only_count=1; show_all=0 ;; printf "\t-d, --details\t\tShow detailed histogram\n"
-t) only_total=1; show_all=0 ;; printf "\t-m, --average\t\tShow only average size\n"
-a) human=1; details=1 ;; printf "\t-M, --median\t\tShow only median size\n"
-x) ext_filter="${2#.}"; shift ;; printf "\t-c, --count\t\tShow only file count\n"
-X) ext_list="${2}"; shift ;; printf "\t-t, --total\t\tShow only total size\n"
--min) min_size="$2"; shift ;; printf "\t-a, --all\t\tShow all (human + details)\n"
--max) max_size="$2"; shift ;; printf "\t-x, --ext [ext]\t\tFilter by extension\n"
--) shift; break ;; printf "\t-X, --ext-list [list]\tFilter by comma-separated list\n"
-*) echo "Usage: file_stats [-h] [-d] [-mMctaxX --min N --max N] [path]"; return 1 ;; printf "\t--min [size]\t\tMinimum size (e.g., 10M)\n"
printf "\t--max [size]\t\tMaximum size (e.g., 100M)\n"
return 0 ;;
-H|--human)
human=1
shift
;;
-d|--details)
details=1
shift
;;
-m|--average)
only_avg=1
show_all=0
shift
;;
-M|--median)
only_med=1
show_all=0
shift
;;
-c|--count)
only_count=1
show_all=0
shift
;;
-t|--total)
only_total=1
show_all=0
shift
;;
-a|--all)
human=1
details=1
shift
;;
-x|--ext)
ext_filter="${2#.}"
shift 2
;;
-X|--ext-list)
ext_list="$2"
shift 2
;;
--min)
min_size="$2"
shift 2
;;
--max)
max_size="$2"
shift 2
;;
--)
shift
break
;;
*)
disp E "Invalid option: $1"
return 1
;;
esac esac
shift shift
done done
[ -n "$1" ] && path="$1" [[ -n "$1" ]] && path="$1"
# Prepare find filters # Prepare find filters
local find_cmd=(find "$path" -type f) local find_cmd=(find "$path" -type f)
@@ -271,12 +407,27 @@ file_stats()
fi fi
# Exécution # Exécution
"${find_cmd[@]}" -printf "%s\n" 2>/dev/null | sort -n | awk -v human="$human" -v details="$details" -v only_avg="$only_avg" -v only_med="$only_med" -v only_count="$only_count" -v only_total="$only_total" -v show_all="$show_all" -v path="$path" ' "${find_cmd[@]}" -printf "%s\n" 2>/dev/null | sort -n | \
awk -v human="$human" -v details="$details" -v only_avg="$only_avg" \
-v only_med="$only_med" -v only_count="$only_count" \
-v only_total="$only_total" -v show_all="$show_all" -v path="$path" '
# Convert function
function human_readable(x) { function human_readable(x) {
split("B KiB MiB GiB TiB", units) split("B KiB MiB GiB TiB", units)
for (i=1; x>=1024 && i<5; i++) x /= 1024 i = 1
while (x >= 1024 && i < 5) {
x /= 1024
i++
}
return sprintf("%.2f %s", x, units[i]) return sprintf("%.2f %s", x, units[i])
} }
# Display function
function out(label, val, is_size) {
if (human == 1 && is_size == 1) val = human_readable(val)
printf "%-20s : %s\n", label, val
}
{ {
sizes[NR] = $1 sizes[NR] = $1
total += $1 total += $1
@@ -288,50 +439,51 @@ file_stats()
bucket[b]++ bucket[b]++
} }
} }
END { END {
count = NR count = NR
if (count == 0) { if (count == 0) {
print "Aucun fichier trouvé."; exit print "No files found."
exit
} }
moyenne = total / count average = total / count
if (count % 2 == 1) # Simple sort for median (awk is not very good at this, we use existing logic)
mediane = sizes[(count + 1) / 2] if (count % 2 == 1) median = sizes[(count + 1) / 2]
else else median = (sizes[count / 2] + sizes[count / 2 + 1]) / 2
mediane = (sizes[count / 2] + sizes[count / 2 + 1]) / 2
function out(label, val) { if (only_avg) out("Average size", average, 1)
if (human) val = human_readable(val) else if (only_med) out("Median size", median, 1)
printf "%-20s : %s\n", label, val else if (only_count) out("Number of files", count, 0)
} else if (only_total) out("Total size", total, 1)
if (only_avg) out("Taille moyenne", moyenne)
else if (only_med) out("Taille médiane", mediane)
else if (only_count) printf "Nombre de fichiers : %d\n", count
else if (only_total) out("Taille totale", total)
else { else {
if (show_all || human || details) { if (show_all || human || details) {
printf "Statistiques sur \"%s\"\n", path printf "Statistics for \"%s\"\n", path
printf "-------------------------\n" printf "-------------------------\n"
} }
out("Nombre de fichiers", count) out("Number of files", count, 0)
out("Taille totale", total) out("Total size", total, 1)
out("Taille moyenne", moyenne) out("Average size", average, 1)
out("Taille médiane", mediane) out("Median size", median, 1)
out("Taille minimale", min) out("Minimum size", min, 1)
out("Taille maximale", max) out("Maximum size", max, 1)
} }
if (details) { if (details) {
print "\nHistogramme des tailles :" print "\nSize histogram:"
for (i = 0; i in bucket; i++) {
low = 2^i # Use a separate array for the loop to avoid collision
high = 2^(i+1) for (b in bucket) {
if (i == 0) # Pre-calculate label parts
label = sprintf("%4s %4s", "0", "1K") # 1024^0 = 1 (B), 1024^1 = 1K, etc.
else low = (b == 0) ? 0 : (1024^b)
label = sprintf("%4s %4s", human_readable(low), human_readable(high)) high = 1024^(b+1)
printf "%-20s : %5d fichiers\n", label, bucket[i]
label = sprintf("%-9s %-9s",
(b == 0) ? "0" : human_readable(low),
human_readable(high))
# We store buckets in an array, access them by index b
printf "%-25s : %6d fichiers\n", label, bucket[b]
} }
} }
}' }'
@@ -341,4 +493,222 @@ export -f file_stats
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Find the biggest files in a directory tree
# Usage: findbig [options] [directory]
# Options:
# -h : display help screen
# -d : display details (ls -l) for each file
# -x : do not cross filesystem boundaries
# -l : limit : number of files to return (default is 10)
findbig()
{
local details=0 limit=10 no_change=0 one_fs=0
local PARSED
PARSED=$(getopt -o hd:l:x --long help,details,one-fs,limit: -n 'findbig' -- "$@")
if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"findbig --help\" to display usage."
return 1
fi
eval set -- "$PARSED"
while true; do
case "$1" in
-h|--help)
printf "findbig: Find the N biggest files in a directory tree.\n\n"
printf "Usage: findbig [options] [directory]\n\n"
printf "Options:\n"
printf "\t-h, --help\t\tDisplay this help screen\n"
printf "\t-d, --details\t\tShow detailed file info (ls -ld)\n"
printf "\t-l, --limit N\t\tNumber of files to return (default: 10)\n"
printf "\t-x, --one-fs\t\tDo not cross filesystem boundaries\n"
return 0
;;
-d|--details)
details=1
shift
;;
-n|--no-change)
no_change=1
shift
;;
-l|--limit)
limit="$2"
shift 2
;;
--)
shift
break
;;
*)
disp E "Invalid option: $1"
return 1
;;
esac
done
local dir="${1:-.}"
# Prepare find arguments in an array for cleaner handling
local find_args=("-L" "$dir" "-type" "f")
(( one_fs )) && find_args+=("-xdev")
# Logic: find files, print size and path, sort numeric reverse, take N
if (( details )); then
find "${find_args[@]}" -printf "%s %p\n" 2>/dev/null | sort -rn | head -n "$limit" | while read -r size path; do
ls -ld "$path"
done
else
find "${find_args[@]}" -printf "%s %p\n" 2>/dev/null | sort -rn | head -n "$limit"
fi
}
export -f findbig
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Find empty files in a directory tree
# Usage: findzero [options] [directory]
# Options:
# -h : display help screen
# -d : display details (ls -l) for each file
# -x : do not cross filesystem boundaries
# --delete : delete empty files and display their paths
findzero() {
local delete=0 details=0 one_fs=0 no_change=0
local PARSED
# o: options, long: long equivalents
PARSED=$(getopt -o hdx --long help,details,one-fs,delete -n 'findzero' -- "$@")
if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"findzero --help\" to display usage."
return 1
fi
eval set -- "$PARSED"
while true; do
case "$1" in
-h|--help)
printf "findzero: Find or delete empty files in a directory tree.\n\n"
printf "Usage: findzero [options] [directory]\n\n"
printf "Options:\n"
printf "\t-h, --help\t\tDisplay this help screen\n"
printf "\t-d, --details\t\tShow detailed file info (ls -ls)\n"
printf "\t-x, --one-fs\t\tDo not cross filesystem boundaries\n"
printf "\t--delete\t\tActually remove the empty files\n"
return 0 ;;
-d|--details)
details=1
shift
;;
-x|--one-fs)
one_fs=1
shift
;;
--delete)
delete=1
shift
;;
--)
shift
break
;;
*)
disp E "Invalid option: $1"
return 1
;;
esac
done
local dir="${1:-.}"
local find_args=("-L" "$dir" "-type" "f" "-empty")
(( one_fs )) && find_args+=("-xdev")
# Execution logic
if (( delete )); then
disp W "Deleting empty files in $dir..."
find "${find_args[@]}" -delete -print
elif (( details )); then
find "${find_args[@]}" -ls
else
find "${find_args[@]}"
fi
}
export -f findzero
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Find dead symbolic links in a directory tree
# Usage: finddead [options] [directory]
# Options:
# -h : display help screen
# -d : display details (ls -l) for each link
# -x : do not cross filesystem boundaries
# --delete : delete dead links and display their paths
finddead() {
local delete=0 details=0 one_fs=0 no_change=0
local PARSED
PARSED=$(getopt -o hdx --long help,details,one-fs,delete -n 'finddead' -- "$@")
if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"finddead --help\" to display usage."
return 1
fi
eval set -- "$PARSED"
while true; do
case "$1" in
-h|--help)
printf "finddead: Find or delete dead/broken symbolic links.\n\n"
printf "Usage: finddead [options] [directory]\n\n"
printf "Options:\n"
printf "\t-h, --help\t\tDisplay this help screen\n"
printf "\t-d, --details\t\tShow detailed symlink info (ls -ls)\n"
printf "\t-x, --one-fs\t\tDo not cross filesystem boundaries\n"
printf "\t--delete\t\tActually remove the dead links\n"
return 0 ;;
-d|--details)
details=1
shift
;;
-x|--one-fs)
one_fs=1
shift
;;
--delete)
delete=1
shift
;;
--)
shift
break
;;
*)
disp E "Invalid option: $1"
return 1
;;
esac
done
local dir="${1:-.}"
# -xtype l searches for links that do not point to an existing file
local find_args=("$dir" "-xtype" "l")
(( one_fs )) && find_args+=("-xdev")
# Execution logic
if (( delete )); then
disp W "Deleting dead symlinks in $dir..."
find "${find_args[@]}" -delete -print
elif (( details )); then
find "${find_args[@]}" -ls
else
find "${find_args[@]}"
fi
}
export -f finddead
# ------------------------------------------------------------------------------
# EOF # EOF

View File

@@ -36,35 +36,73 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Make non-IT peoples think you're busy doing something hard # Make non-IT peoples think you're busy doing something hard
# ------------------------------------------------------------------------------ # Usage: busy [options] [pattern]
# Options:
# --delay=<ms> : add a delay between each line output (milliseconds)
# pattern : the string to search for in the hexdump output (default is "ca fe")
busy() busy()
{ {
local pattern="ca fe" local pattern="ca fe" delay_ms=0
for arg in "$@"; do
case "$arg" in local PARSED
--delay=*) # Short: h, p:, d:
delay_ms="${arg#*=}" # Long: help, pattern:, delay:
if ! [[ $delay_ms =~ ^[0-9]+$ ]]; then PARSED=$(getopt -o hp:d: --long help,pattern:,delay: -n 'busy' -- "$@")
disp E "Invalid delay value, must be an integer (milliseconds)." if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"busy --help\" to display usage."
return 1
fi
eval set -- "$PARSED"
while true; do
case "$1" in
-h|--help)
printf "busy: Monitor /dev/urandom for a specific pattern.\n\n"
printf "Usage: busy [options] [pattern]\n\n"
printf "Options:\n"
printf "\t-h, --help\t\tDisplay this help screen\n"
printf "\t-p, --pattern PATTERN\tHex pattern to search (default: \"ca fe\")\n"
printf "\t-d, --delay MS\t\tDelay between matches in milliseconds\n"
return 0
;;
-p|--pattern)
pattern="$2"
shift 2
;;
-d|--delay)
delay_ms="$2"
if ! [[ "$delay_ms" =~ ^[0-9]+$ ]]; then
disp E "Invalid delay: must be an integer (milliseconds)."
return 1 return 1
fi fi
shift 2
;;
--)
shift
break
;; ;;
*) *)
pattern="$arg" disp E "Invalid option: $1"
return 1
;; ;;
esac esac
done done
# If a pattern was provided as a positional argument (e.g., 'busy "ff 00"'),
# it is captured here.
[[ -n "$1" ]] && pattern="$1"
# Convert milliseconds to seconds for 'sleep' # Convert milliseconds to seconds for 'sleep'
local delay_s=$(awk "BEGIN { printf \"%.3f\", $delay_ms / 1000 }") local delay_s=$(awk "BEGIN { printf \"%.3f\", $delay_ms / 1000 }")
# Monitor /dev/urandom
cat /dev/urandom | hexdump -C | grep --line-buffered "$pattern" | \ cat /dev/urandom | hexdump -C | grep --line-buffered "$pattern" | \
while read -r line; do while read -r line; do
echo $line echo "$line"
[[ $delay_ms -gt 0 ]] && sleep "$delay_s" [[ $delay_ms -gt 0 ]] && sleep "$delay_s"
done done
unset pattern
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# EOF # EOF

View File

@@ -36,38 +36,43 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Display list of commands and general informations # Display list of commands and general informations
# ------------------------------------------------------------------------------ # Usage: help
help() help()
{ {
cat <<EOF printf "check_updates\tCheck for profile updates\n"
clean Erase backup files printf "clean\t\tErase backup files\n"
dpkgs Search for the given package in the installed ones printf "dpkgs\t\tSearch for the given package in the installed ones\n"
gpid Give the list of PIDs for the given process name printf "findbig\t\tFind big files in the given (or current) directory\n"
isipv4 Tell if the given IPv4 is valid printf "findempty\tFind empty files and directories in the given (or current) directory\n"
isipv6 Tell if the given IPv6 is valid printf "finddead\tFind dead symbolic links in the given (or current) directory\n"
ku Kill process owned by users in parameter printf "gpid\t\tGive the list of PIDs for the given process name\n"
mcd Create a directory and go inside printf "isipv4\t\tTell if the given IPv4 is valid\n"
meteo Display curent weather forecast for the configured city printf "isipv6\t\tTell if the given IPv6 is valid\n"
ppg Display process matching the given parameter printf "ku\t\tKill process owned by users in parameter\n"
ppn Display process matching the exact process name given in parameter printf "mcd\t\tCreate a directory and go inside\n"
ppu Display processes owned by the given user printf "meteo\t\tDisplay curent weather forecast for the configured city\n"
rain Let the rain fall printf "ppg\t\tDisplay process matching the given parameter\n"
rmhost Remove host (IP and/or DNS name) for current known_host printf "ppn\t\tDisplay process matching the exact process name given in parameter\n"
rmspc Remove spaces from all the files in working directory printf "ppu\t\tDisplay processes owned by the given user\n"
setc Set console language to C printf "profile_update\tUpdate profile to the latest version\n"
setfr Set console language to French printf "rain\t\tLet the rain fall\n"
settrace Activate/deactivate call trace for script debugging printf "rmhost\t\tRemove host (IP and/or DNS name) for current known_host\n"
setus Set console language to US English printf "rmspc\t\tRemove spaces from all the files in working directory\n"
showinfo Show the welcoming baner with basic system information printf "setlocale\tSet console language to the current locale\n"
ssr Do a root login to the given address printf " * setc\tSet console language to C\n"
taz Compress smartly the given files or directory printf " * setfr\tSet console language to French\n"
utaz Uncompress all zip files in the given (or current) directory printf " * setus\tSet console language to US English\n"
ver Display version of your copy of profile printf "settrace\tActivate/deactivate call trace for script debugging\n"
printf "showinfo\tShow the welcoming baner with basic system information\n"
printf "ssr\t\tDo a root login to the given address\n"
printf "taz\t\tCompress smartly the given files or directory\n"
printf "utaz\t\tUncompress all zip files in the given (or current) directory\n"
printf "ver\t\tDisplay version of your copy of profile\n\n"
Please use <command> --help to obtain usage details. printf "\nPlease use <command> --help to obtain usage details.\n"
EOF
} }
export -f help export -f help
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# EOF # EOF

View File

@@ -36,7 +36,7 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Show profile version # Show profile version
# ------------------------------------------------------------------------------ # Usage: ver
ver() ver()
{ {
[[ -z $PROFVERSION ]] && \ [[ -z $PROFVERSION ]] && \
@@ -45,10 +45,12 @@ ver()
disp "Profile version $PROFVERSION." disp "Profile version $PROFVERSION."
} }
export -f ver export -f ver
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Display weather of the given city (or default one) # Display weather of the given city (or default one)
# ------------------------------------------------------------------------------ # Usage: meteo [city1 city2 ...]
meteo() meteo()
{ {
local encoded cities=("$@") local encoded cities=("$@")
@@ -61,10 +63,12 @@ meteo()
done done
} }
export -f meteo export -f meteo
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Display system general information # Display system general information
# ------------------------------------------------------------------------------ # Usage: showinfo
showinfo() showinfo()
{ {
echo -e "\n" echo -e "\n"
@@ -99,6 +103,7 @@ showinfo()
fi fi
} }
export -f showinfo export -f showinfo
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# EOF # EOF

View File

@@ -34,7 +34,8 @@
# * OF SUCH DAMAGE. # * OF SUCH DAMAGE.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
locale_check() { locale_check()
{
locale -a | grep -qx "$1" || { locale -a | grep -qx "$1" || {
disp W "Locale '$1' is not installed on this system." disp W "Locale '$1' is not installed on this system."
return 1 return 1
@@ -45,9 +46,34 @@ locale_check() {
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Change locale to the given one in parameter # Change locale to the given one in parameter
# ------------------------------------------------------------------------------ # Usage: setlocale <locale>
setlocale() setlocale()
{ {
local PARSED
PARSED=$(getopt -o h --long help -n 'setlocale' -- "$@")
if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"setlocale --help\" to display usage."
return 1
fi
eval set -- "$PARSED"
case "$1" in
-h|--help)
printf "setlocale: Configure system environment locale variables.\n\n"
printf "Usage: setlocale <locale>\n\n"
printf "Options:\n"
printf " -h, --help Display this help screen\n"
return 0
;;
--)
shift
break
;;
*)
disp E "Invalid options, use \"setlocale --help\" to display usage."
return 1
;;
esac
local loc=$1 local loc=$1
[[ -z $loc ]] && disp E "No locale specified." && return 1 [[ -z $loc ]] && disp E "No locale specified." && return 1
@@ -64,11 +90,12 @@ setlocale()
disp I "Locale set to $loc." disp I "Locale set to $loc."
} }
export -f setlocale export -f setlocale
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Special case : change locale to C standard # Special case : change locale to C standard
# ------------------------------------------------------------------------------ # Usage: setc
setc() setc()
{ {
# Locale definitions # Locale definitions
@@ -76,27 +103,31 @@ setc()
disp I "Locale changed to standard C (POSIX)." disp I "Locale changed to standard C (POSIX)."
} }
export -f setc export -f setc
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Change locale to French # Change locale to French
# ------------------------------------------------------------------------------ # Usage: setfr
setfr() setfr()
{ {
# Set fr locale definitions # Set fr locale definitions
setlocale "fr_FR.UTF-8" setlocale "fr_FR.UTF-8"
} }
export -f setfr export -f setfr
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Change locale to US (needed by Steam) # Change locale to US (needed by Steam)
# ------------------------------------------------------------------------------ # Usage: setus
setus() setus()
{ {
setlocale "en_US.UTF-8" setlocale "en_US.UTF-8"
} }
export -f setus export -f setus
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# EOF # EOF

View File

@@ -36,7 +36,7 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Determine if parameter is a valid IPv4 address # Determine if parameter is a valid IPv4 address
# ------------------------------------------------------------------------------ # Usage: isipv4 <ip_address>
isipv4() isipv4()
{ {
# Set up local variables # Set up local variables
@@ -63,10 +63,12 @@ isipv4()
return 1 return 1
} }
export -f isipv4 export -f isipv4
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Determine if parameter is a valid IPv4 address # Determine if parameter is a valid IPv4 address
# ------------------------------------------------------------------------------ # Usage: isipv6 <ip_address>
isipv6() isipv6()
{ {
local ip="$1" local ip="$1"
@@ -83,10 +85,12 @@ isipv6()
return 1 return 1
} }
export -f isipv6 export -f isipv6
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Encode a string so it can be used as a URL parameter # Encode a string so it can be used as a URL parameter
# ------------------------------------------------------------------------------ # Usage: urlencode <string>
urlencode() { urlencode() {
local LANG=C local LANG=C
local str="$*" local str="$*"
@@ -101,6 +105,7 @@ urlencode() {
done done
} }
export -f urlencode export -f urlencode
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View File

@@ -36,38 +36,53 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Look for a package within installed one # Look for a package within installed one
# ------------------------------------------------------------------------------ # Usage: dpkgs <string>
pkgs() pkgs()
{ {
local count=0 local ignore_case=0
for opt in $@; do
case $opt in
"-h" | "--help")
echo "dpkgs: look for an installed package by it's name."
echo
echo "Usage: dpkgs <string>"
return 0
;;
"-"*) local PARSED
disp E "Invalid option, use \"dpkgs --help\" to display usage." PARSED=$(getopt -o hi --long help,ignore-case -n 'pkgs' -- "$@")
echo if [[ $? -ne 0 ]]; then
return 1 disp E "Invalid options, use \"pkgs --help\" to display usage."
;; return 1
fi
eval set -- "$PARSED"
*) while true; do
local pkg=$1 && shift case "$1" in
count=$(($count + 1)) -h|--help)
[[ $count -gt 1 ]] && printf "pkgs: Look for an installed package by its name.\n\n"
disp E "Please specify a package name, without space, eventually partial." && printf "Usage: pkgs [options] <string>\n\n"
printf "Options:\n"
printf "\t-h, --help\tDisplay this help screen\n"
printf "\t-i, --ignore-case\tIgnore case distinctions\n"
return 0
;;
-i|--ignore-case)
ignore_case=1
shift
;;
--)
shift
break
;;
*)
disp E "Invalid option: $1"
return 1 return 1
;;
;;
esac esac
done done
[[ $count -lt 1 ]] &&
disp E "Please specify a package name, without space, eventually partial." && local pkg="$1"
[[ -z "$pkg" ]] && {
disp E "Please specify a package name, without space, eventually partial."
return 1 return 1
}
# Build grep command
local grep_opt=""
(( ignore_case )) && grep_opt="-i"
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"
@@ -75,9 +90,10 @@ pkgs()
disp E "No usable package manager seems unavialable." disp E "No usable package manager seems unavialable."
return 2 return 2
fi fi
$cmd | grep $pkg $cmd | grep $grep_opt $pkg
} }
export -f pkgs export -f pkgs
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# EOF # EOF

View File

@@ -36,18 +36,38 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Search processes matching the given string # Search processes matching the given string
# ------------------------------------------------------------------------------ # Usage: ppg <string>
ppg() ppg()
{ {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
printf "ppg: Search processes matching the given string.\n\n"
printf "Usage: ppg <string>\n\n"
printf "Options:\n"
printf "\t-h, --help\t\tDisplay this help screen\n"
return 0
fi
if [[ -z "$1" ]]; then
disp E "Usage: ppg <string>"
return 1
fi
ps -edf | grep "$@" | grep -v "grep $@" ps -edf | grep "$@" | grep -v "grep $@"
} }
export -f ppg export -f ppg
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# List processes owned by a specific user # List processes owned by a specific user
# ------------------------------------------------------------------------------ # Usage: ppu <username>
ppu() ppu()
{ {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
printf "ppu: List processes owned by a specific user.\n\n"
printf "Usage: ppu <username>\n\n"
printf "Options:\n"
printf "\t-h, --help\t\tDisplay this help screen\n"
return 0
fi
if [[ -z "$1" ]]; then if [[ -z "$1" ]]; then
disp E "Usage: ppu <username>" disp E "Usage: ppu <username>"
return 1 return 1
@@ -58,12 +78,21 @@ ppu()
ps -u "$1" -o pid,user,%cpu,%mem,start,time,command ps -u "$1" -o pid,user,%cpu,%mem,start,time,command
} }
export -f ppu export -f ppu
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# List processes by exact command name (no path/parameters) # List processes by exact command name (no path/parameters)
# ------------------------------------------------------------------------------ # Usage: ppn <command_name>
ppn() ppn()
{ {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
printf "ppn: List processes by exact command name (no path/parameters).\n\n"
printf "Usage: ppn <command_name>\n\n"
printf "Options:\n"
printf "\t-h, --help\t\tDisplay this help screen\n"
return 0
fi
if [[ -z "$1" ]]; then if [[ -z "$1" ]]; then
disp E "Usage: ppn <command_name>" disp E "Usage: ppn <command_name>"
return 1 return 1
@@ -75,12 +104,25 @@ ppn()
ps -eo pid,comm | grep -w "$1" ps -eo pid,comm | grep -w "$1"
} }
export -f ppn export -f ppn
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Get PID list of the given process name # Get PID list of the given process name
# ------------------------------------------------------------------------------ # Usage: ppid <process_name [process_name2 ...]>
gpid() gpid()
{ {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
printf "gpid: Get PID list of the given process name.\n\n"
printf "Usage: gpid <process_name [process_name2 ...]>\n\n"
printf "Options:\n"
printf "\t-h, --help\t\tDisplay this help screen\n"
return 0
fi
if [[ -z "$1" ]]; then
disp E "Usage: gpid <process_name [process_name2 ...]>"
return 1
fi
[[ $UID -eq 0 ]] && local psopt="-A" [[ $UID -eq 0 ]] && local psopt="-A"
[[ $# -eq 1 ]] && local single=1 [[ $# -eq 1 ]] && local single=1
for pid in $@; do for pid in $@; do
@@ -94,34 +136,65 @@ gpid()
[[ $result ]] || return 1 [[ $result ]] || return 1
} }
export -f gpid export -f gpid
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Kill all processes owned by the given users (kill user) # Kill all processes owned by the given users (kill user)
# ------------------------------------------------------------------------------ # Usage: ku <username1 [username2 ...]>
ku() ku()
{ {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
printf "ku: Kill all processes owned by the given users.\n\n"
printf "Usage: ku <username1 [username2 ...]>\n\n"
printf "Options:\n"
printf "\t-h, --help\t\tDisplay this help screen\n"
return 0
fi
if [[ -z "$1" ]]; then
disp E "Usage: ku <username1 [username2 ...]>"
return 1
fi
for u in $@; do for u in $@; do
killall -u "$u" killall -u "$u"
done done
} }
export -f ku export -f ku
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Kill all children of a process then the process (kill tree) # Kill all children of a process then the process (kill tree)
# ------------------------------------------------------------------------------ # Usage: kt <pid> [kill_options]
kt() kt()
{ {
[[ -z $1 ]] && echo -e "Usage:\n\tkt <pid> [kill_options]" if [[ "$1" == "-h" || "$1" == "--help" ]]; then
printf "kt: Kill all children of a process then the process (kill tree).\n\n"
printf "Usage: kt <pid> [kill_options]\n\n"
printf "Options:\n"
printf "\t-h, --help\t\tDisplay this help screen\n"
return 0
fi
if [[ -z "$1" ]]; then
disp E "Usage: ppg <string>"
return 1
fi
local parent_pid="$1" local parent_pid="$1"
shift shift
if [[ "$parent_pid" == "0" || "$parent_pid" == "1" ]]; then
disp E "Safety abort: Refusing to kill PID $parent_pid (system critical)."
return 1
fi
children_pids=$(pgrep -P "$parent_pid") children_pids=$(pgrep -P "$parent_pid")
for pid in $children_pids; do for pid in $children_pids; do
kt "$pid" "$@" kt "$pid" "$@" || break
done done
kill "$@" "$parent_pid" kill "$@" "$parent_pid"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# EOF # EOF

View File

@@ -35,17 +35,26 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# timer_* functions : internal timing function for prompt # timer_* functions : internal timing function for prompt
# ------------------------------------------------------------------------------ # Usage: timer_now
# This function returns the current time in nanoseconds since the epoch. It
# first tries to use the %N format specifier for nanoseconds, but if that is
# not supported (e.g., on older systems), it falls back to seconds.
function timer_now function timer_now
{ {
date +%s%N 2>/dev/null || date +%s date +%s%N 2>/dev/null || date +%s
} }
# Usage: timer_start
# This function initializes the timer_start variable with the current time in
# nanoseconds. It is used to measure the elapsed time for the prompt.
function timer_start function timer_start
{ {
timer_start=${timer_start:-$(timer_now)} timer_start=${timer_start:-$(timer_now)}
} }
# Usage: timer_stop
# This function calculates the elapsed time since timer_start and formats it
# 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))
@@ -74,8 +83,11 @@ function timer_stop
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Function triguered internaly by bash : defining prompt # Function triggered internally by bash : defining prompt
# ------------------------------------------------------------------------------ # Usage: set_prompt
# This function is called by bash before displaying the prompt. It sets the
# PS1 variable to a custom prompt that includes the exit status of the last
# command, the elapsed time of the last command, and the current user and host.
set_prompt() set_prompt()
{ {
local Last_Command=$? # Must come first! local Last_Command=$? # Must come first!
@@ -123,6 +135,7 @@ set_prompt()
# the text color to the default. # the text color to the default.
PS1+="$ICyan\\w \\\$$Default " PS1+="$ICyan\\w \\\$$Default "
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# EOF # EOF

View File

@@ -36,9 +36,20 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# genpwd : generate a password with different criteria # genpwd : generate a password with different criteria
# default 16 car with up and low car, symbol and number # Usage: genpwd [options] [--extracars=<cars>] [--length=<n>] [nb_passwd]
# Options:
# -h, --help Display that help screen
# -s, --nosymbols Exclude symbols
# -n, --nonumbers Exclude numbers
# -u, --noup Exclude uppercase letters
# -l, --nolow Exclude lowercase letters
# -e=<c>, --extracars=<c>
# Add the given caracters to the possible caracter list
# -L=<n>, --length=<n>
# Set length of the password (default is 16)
# -o=<n>, --occurences=<n>
# Set the maximum occurences of a same caracter (default is 2)
# The function is very slow on Windows # The function is very slow on Windows
# ------------------------------------------------------------------------------
genpwd() genpwd()
{ {
local length=16 local length=16
@@ -47,80 +58,81 @@ genpwd()
local nbpwd=1 local nbpwd=1
local extcar local extcar
for opt in $@; do local PARSED
case $opt in PARSED=$(getopt -o hsnu l e:L:o: --long \
"-h" | "--help") help,nosymbols,nonumbers,noup,nolow,extracars:,length:,occurences: -n 'genpwd' -- "$@")
echo "genpwd: generate one or more secure random password." if [[ $? -ne 0 ]]; then return 1; fi
echo eval set -- "$PARSED"
echo "Usage: genpwd [options] [--extracars=<cars>] [--length=<n>] [nb_passwd]"
echo while true; do
echo "Options:" case "$1" in
echo " -h, --help Display that help screen" -h|--help)
echo " -s, --nosymbols Exclude symbols" printf "genpwd: Generate secure random password(s).\n\n"
echo " -n, --nonumbers Exclude numbers" printf "Usage: genpwd [options] [nb_passwd]\n\n"
echo " -u, --noup Exclude uppercase letters" printf "Options:\n"
echo " -l, --nolow Exclude lowercase letters" printf "\t-h, --help\t\tDisplay this help screen\n"
echo " -e=<c>, --extracars=<c>" printf "\t-s, --nosymbols\t\tExclude symbols\n"
echo " Add the given caracters to the possible caracter list" printf "\t-n, --nonumbers\t\tExclude numbers\n"
echo " -L=<n>, --length=<n>" printf "\t-u, --noup\t\tExclude uppercase letters\n"
echo " Set length of the password (default is $length)" printf "\t-l, --nolow\t\tExclude lowercase letters\n"
echo " -o=<n>, --occurences=<n>" printf "\t-e, --extracars <c>\tAdd characters to list\n"
echo " Set the maximum occurences of a same caracter (default is $occurs)" printf "\t-L, --length <n>\tSet password length (default: 16)\n"
echo printf "\t-o, --occurences <n>\tMax occurences per character (default: 2)\n"
echo "If the --extracars parameter is given, at least one of the given caracter will" return 0
echo "be used in the final password." ;;
echo -s|--nosymbols)
echo "Please note that some caracters might be interpreted by Bash or Awk programs," symb=0
echo "and thus, cannot be used without provoquing errors. Those identified caracters" shift
echo "are :" ;;
echo ' * ? \ $ { }' -n|--nonumbers)
echo numb=0
return 0 shift
;; ;;
"-s" | "--nosymbols") -u|--noup)
symb=0 maj=0
;; shift
"-n" | "--nonumbers") ;;
numb=0 -l|--nolow)
;; min=0
"-u" | "--noup") shift
maj=0 ;;
;; -e|--extracars)
"-l" | "--nolow") extcar="$2"
min=0 shift 2
;; ;;
"-e"?* | "--extracars"?*) -L|--length)
extcar=$(echo "$opt" | cut -f 2- -d '=') length="$2"
;; if ! [[ $length =~ ^[0-9]+$ ]]; then
"-L"?* | "--length"?*) disp E "The --length parameter requires a number."
local length=$(echo "$opt" | cut -f 2- -d '=') return 1
if ! [[ $length =~ ^[0-9]+$ ]]; then fi
disp E "The --length parameter requires a number." shift 2
return 1 ;;
fi -o|--occurences)
;; occurs="$2"
"-o"?* | "--occurences"?*) if ! [[ $occurs =~ ^[1-9]+$ ]]; then
local occurs=$(echo "$opt" | cut -f 2- -d '=') disp E "The --occurs parameter requires a number from 1 to 9."
if ! [[ $occurs =~ ^[1-9]+$ ]]; then return 1
disp E "The --occurs parameter requires a number from 1 to 9." fi
return 1 shift 2
fi ;;
;; --)
"-*") shift; break
disp E "Unknow parameter ${opt}." ;;
return 1 *)
;; break
*) ;;
if ! [[ $opt =~ ^[1-9]+$ ]]; then
disp E "Unknow parameter ${opt}."
return 1
else
nbpwd=$opt
fi
;;
esac esac
done done
if [[ -n "$1" ]]; then
nbpwd="$1"
if ! [[ $nbpwd =~ ^[0-9]+$ ]]; then
disp E "The number of password to generate must be a number."
return 1
fi
fi
# Function selecting a random caracter from the list in parameter # Function selecting a random caracter from the list in parameter
pickcar() { pickcar() {
# When a character is picked we check if it's not appearing already twice # When a character is picked we check if it's not appearing already twice
@@ -136,7 +148,7 @@ genpwd()
} }
disp I "Generating $nbpwd passwords, please wait..." disp I "Generating $nbpwd passwords, please wait..."
for n in $(seq 1 $nbpwd); do for (( n=1; n<=nbpwd; n++ )); do
{ {
local carset='' # store final caracter set to use local carset='' # store final caracter set to use
local picked='' # store already used caracter local picked='' # store already used caracter
@@ -185,6 +197,7 @@ genpwd()
done done
} }
export -f genpwd export -f genpwd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# EOF # EOF

View File

@@ -36,27 +36,36 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Let the rain fall # Let the rain fall
# ------------------------------------------------------------------------------ # Usage: rain [OPTIONS]
# Options:
# -s, --speed NUM Set the drop delay in seconds (default: 0.050).
# Lower values = faster rain.
# -c, --color COLOR Set the color theme (default: white).
# -h, --help Display this help message and exit.
# Available Colors:
# green : The classic Matrix digital rain
# blue : Deep ocean blue gradients
# red : Crimson/Blood rain
# yellow : Amber and gold tones
# cyan : Electric cyan/turquoise
# white : Greyscale and white (original style)
rain() rain()
{ {
show_usage() { show_usage() {
echo -e "Usage: rain [OPTIONS]" printf "Usage: rain [OPTIONS]\n"
echo -e "" printf "Options:\n"
echo -e "Options:" printf "\t-s, --speed NUM Set the drop delay in seconds (default: 0.050).\n"
echo -e " -s, --speed NUM Set the drop delay in seconds (default: 0.050)." printf "\t Lower values = faster rain.\n"
echo -e " Lower values = faster rain." printf "\t-c, --color COLOR Set the color theme (default: white).\n"
echo -e " -c, --color COLOR Set the color theme (default: white)." printf "\t-h, --help Display this help message and exit.\n\n"
echo -e " -h, --help Display this help message and exit." printf "Available Colors:\n"
echo -e "" printf "\t\e[32mgreen\e[0m\t: The classic Matrix digital rain\n"
echo -e "Available Colors:" printf "\t\e[34mblue\e[0m\t: Deep ocean blue gradients\n"
echo -e " \e[32mgreen\e[0m : The classic Matrix digital rain" printf "\t\e[31mred\e[0m\t: Crimson/Blood rain\n"
echo -e " \e[34mblue\e[0m : Deep ocean blue gradients" printf "\t\e[33myellow\e[0m\t: Amber and gold tones\n"
echo -e " \e[31mred\e[0m : Crimson/Blood rain" printf "\t\e[36mcyan\e[0m\t: Electric cyan/turquoise\n"
echo -e " \e[33myellow\e[0m : Amber and gold tones" printf "\twhite\t: Greyscale and white (original style)\n\n"
echo -e " \e[36mcyan\e[0m : Electric cyan/turquoise" printf "Example: rain --color green --speed 0.03\n"
echo -e " white : Greyscale and white (original style)"
echo -e ""
echo -e "Example: rain --color green --speed 0.03"
} }
local step_duration=0.050 local step_duration=0.050
@@ -69,7 +78,7 @@ rain()
if [[ -n "$2" && ! "$2" =~ ^- ]]; then if [[ -n "$2" && ! "$2" =~ ^- ]]; then
step_duration="$2"; shift step_duration="$2"; shift
else else
echo -e "\e[31mError: --speed requires a numeric value.\e[0m" disp E "--speed requires a numeric value."
show_usage && return 1 show_usage && return 1
fi fi
;; ;;
@@ -77,7 +86,7 @@ rain()
if [[ -n "$2" && ! "$2" =~ ^- ]]; then if [[ -n "$2" && ! "$2" =~ ^- ]]; then
base_color="$2"; shift base_color="$2"; shift
else else
echo -e "\e[31mError: --color requires a color name.\e[0m" disp E "--color requires a color name."
show_usage && return 1 show_usage && return 1
fi fi
;; ;;
@@ -85,7 +94,7 @@ rain()
show_usage && return 0 show_usage && return 0
;; ;;
*) *)
echo -e "\e[31mUnknown option: $1\e[0m" disp E "Unknown option: $1"
show_usage && return 1 show_usage && return 1
;; ;;
esac esac
@@ -168,7 +177,7 @@ rain()
drop_length=${rains[idx + 4]} drop_length=${rains[idx + 4]}
for ((y = Y; y < Y + drop_length; y++)); do for ((y = Y; y < Y + drop_length; y++)); do
((y < 1 || y > term_height)) && continue ((y < 1 || y > term_height)) && continue
echo -ne "\e[${y};${X}H${drop_color}${rain_drop}" printf "\e[${y};${X}H${drop_color}${rain_drop}"
done done
done done
} }
@@ -177,9 +186,9 @@ rain()
trap sigwinch WINCH trap sigwinch WINCH
# No echo stdin and hide the cursor # No echo stdin and hide the cursor
stty -echo stty -echo
echo -ne "\e[?25l" printf "\e[?25l"
printf "\e[2J"
echo -ne "\e[2J"
local rains=() local rains=()
local num_rains=0 local num_rains=0
sigwinch sigwinch

View File

@@ -36,17 +36,42 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Remove host from know_host (name and IP) for the active user # Remove host from know_host (name and IP) for the active user
# ------------------------------------------------------------------------------ # Usage: rmhost <hostname|ip> [hostname2|ip2 [...]]
rmhost() rmhost()
{ {
if [[ "$#" -lt 1 ]]; then local PARSED
disp E "Incorrect number of parameters." PARSED=$(getopt -o h --long help -n 'rmhost' -- "$@")
disp E "Usage: rmhost <hostname|ip> [hostname2|ip2 [...]]" if [[ $? -ne 0 ]]; then return 1; fi
eval set -- "$PARSED"
while true; do
case "$1" in
-h|--help)
printf "rmhost: Remove host/IP from ~/.ssh/known_hosts.\n\n"
printf "Usage: rmhost <hostname|ip> [hostname2|ip2 ...]\n\n"
printf "Options:\n"
printf " -h, --help Display this help screen\n"
return 0
;;
--)
shift
break
;;
*)
disp E "Invalid options, use \"rmhost --help\" to display usage."
break
;;
esac
done
# Validation: Ensure at least one argument remains
if [[ $# -eq 0 ]]; then
disp E "Missing argument. Use 'rmhost --help' for usage."
return 1 return 1
fi fi
while [[ $1 ]]; do for target in "$@"; do
local hst=$1 && shift local hst=$target
isipv4 "$hst" >/dev/null isipv4 "$hst" >/dev/null
local v4=$? local v4=$?
isipv6 "$hst" >/dev/null isipv6 "$hst" >/dev/null
@@ -81,20 +106,36 @@ rmhost()
done done
} }
export -f rmhost export -f rmhost
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Login root via SSH on the given machine # Login root via SSH on the given machine
# ------------------------------------------------------------------------------ # Usage: ssr <server [ssh options]>
ssr() ssr()
{ {
for opt in $@; do local PARSED
case $opt in PARSED=$(getopt -o h --long help -n 'ssr' -- "$@")
"-h" | "--help") if [[ $? -ne 0 ]]; then return 1; fi
echo "ssr: do a root user ssh login." eval set -- "$PARSED"
echo
echo "Usage: ssr <server [ssh options]>" while true; do
return 0 case "$1" in
;; -h|--help)
printf "ssr: SSH into a server as root.\n\n"
printf "Usage: ssr <server> [ssh_options...]\n\n"
printf "Options:\n"
printf "\t-h, --help\t\tDisplay this help screen\n"
return 0
;;
--)
shift
break
;;
*)
disp E "Invalid options, use \"ssr --help\" to display usage."
return 1
;;
esac esac
done done
@@ -102,15 +143,17 @@ ssr()
disp E "ssh is not installed." disp E "ssh is not installed."
return 127 return 127
} }
[[ ! $1 ]] && [[ ! $1 ]] && {
disp E "Please specify the server you want to log in." && disp E "Please specify the server you want to log in."
return 1 return 1
}
local srv=$1 && shift local srv=$1 && shift
ssh -Y root@"$srv" "$@" ssh -Y root@"$srv" "$@"
} }
export -f ssr export -f ssr
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# EOF # EOF

View File

@@ -40,14 +40,40 @@ export ARCH_URL="$BASE_URL/archive/master.tar.gz"
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Check for profile updates # Check for profile updates
# ------------------------------------------------------------------------------ # Usage: check_updates [-q]
# If -q is specified, the function will operate in quiet mode (internal use only)
check_updates() check_updates()
{ {
if [[ $1 == "-q" ]]; then local quiet=0
# Quiet mode is mostly used internally when profile_upgrade is called local PARSED=$(getopt -o hq --long help,quiet -n 'check_updates' -- "$@")
quiet=1 if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"check_updates --help\" to display usage."
return 1
fi fi
[[ -n $quiet ]] && disp I "Checking for updates..." eval set -- "$PARSED"
while true; do
case "$1" in
-h|--help)
printf "check_updates: Check for new versions.\n\n"
printf "Usage: check_updates\n"
return 0
;;
-q|--quiet)
quiet=1
shift
;;
--)
shift
break
;;
*)
break
;;
esac
done
[[ $quiet != 1 ]] && disp I "Checking for updates..."
local vfile="/tmp/version" local vfile="/tmp/version"
wget "$UPDT_URL/version" -O $vfile >/dev/null 2>&1 || { wget "$UPDT_URL/version" -O $vfile >/dev/null 2>&1 || {
disp E "Can't download version file, impossible to proceed!" disp E "Can't download version file, impossible to proceed!"
@@ -58,10 +84,10 @@ check_updates()
local lastver=$(cat $vfile) local lastver=$(cat $vfile)
if [[ $lastver != $PROFVERSION ]]; then if [[ $lastver != $PROFVERSION ]]; then
disp I "You have version $PROFVERSION installed. Version $lastver is available." disp I "You have version $PROFVERSION installed. Version $lastver is available."
[[ $quiet ]] && disp I "You should upgrade to last version when possible." [[ $quiet != 1 ]] && disp I "You should upgrade to last version when possible."
result=1 result=1
else else
[[ -n $quiet ]] && disp I "Your version is up-to-date." [[ $quiet != 1 ]] && disp I "Your version is up-to-date."
result=0 result=0
fi fi
rm -f $vfile rm -f $vfile
@@ -71,12 +97,38 @@ check_updates()
unset lastver vfile unset lastver vfile
return $result return $result
} }
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Apply update to profile # Apply update to profile
# ------------------------------------------------------------------------------ # Usage: profile_upgrade
profile_upgrade() profile_upgrade()
{ {
local PARSED=$(getopt -o h --long help -n 'profile_upgrade' -- "$@")
if [[ $? -ne 0 ]]; then
printf "Invalid options, use \"profile_upgrade --help\" to display usage."
return 1
fi
eval set -- "$PARSED"
while true; do
case "$1" in
-h|--help)
printf "profile_upgrade: Upgrade the profile to the latest version.\n\n"
printf "Usage: profile_upgrade\n"
return 0
;;
--)
shift
break
;;
*)
disp E "Invalid options, use \"profile_upgrade --help\" to display usage."
return 1
;;
esac
done
if check_updates -q; then if check_updates -q; then
disp "No update available." disp "No update available."
return 0 return 0
@@ -130,4 +182,7 @@ profile_upgrade()
rm -rf "$tmpdir" rm -rf "$tmpdir"
fi fi
} }
# ------------------------------------------------------------------------------
# EOF # EOF

View File

@@ -1 +1 @@
3.6.0 3.90.1-4_alpha_1