bugfix, esthetic cleanup, better comments, version bump

This commit is contained in:
Geoffray Levasseur-Brandin
2024-06-21 16:19:44 +02:00
parent 9e49e3e4d7
commit bef205ae84
18 changed files with 634 additions and 571 deletions

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -38,9 +39,9 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
utaz() utaz()
{ {
for opt in $@ ; do for opt in $@; do
case $opt in case $opt in
"-h"|"--help") "-h" | "--help")
echo "utaz: uncompress all the given files and/or the ones found in the given" echo "utaz: uncompress all the given files and/or the ones found in the given"
echo " directories creating an host directory where needed." echo " directories creating an host directory where needed."
echo echo
@@ -55,15 +56,15 @@ utaz()
return 0 return 0
;; ;;
"-d"|"--delete") "-d" | "--delete")
local willrm=1 local willrm=1
;; ;;
"-c"|"--create-dir") "-c" | "--create-dir")
local createdir=1 local createdir=1
;; ;;
"-n"|"--no-dir") "-n" | "--no-dir")
local nodir=1 local nodir=1
;; ;;
@@ -85,7 +86,7 @@ utaz()
[[ ! $LIST ]] && local LIST="." [[ ! $LIST ]] && local LIST="."
for zitem in $LIST; do for zitem in $LIST; do
[[ $(ls $zitem/*.zip 2> /dev/null | wc -l) -eq 0 ]] && [[ $(ls $zitem/*.zip 2>/dev/null | wc -l) -eq 0 ]] &&
disp W "$zitem contains no supported archive file, skipping." && disp W "$zitem contains no supported archive file, skipping." &&
continue continue
@@ -98,7 +99,7 @@ utaz()
disp E "The filesystem can't create directories, exit!" && disp E "The filesystem can't create directories, exit!" &&
return 1 return 1
unzip -o $f -d $dir > /dev/null 2>&1 unzip -o $f -d $dir >/dev/null 2>&1
case $? in case $? in
0) 0)
[[ $willrm ]] && rm -f $f && disp I "File $zitem/$f deleted." [[ $willrm ]] && rm -f $f && disp I "File $zitem/$f deleted."
@@ -109,7 +110,7 @@ utaz()
;; ;;
*) *)
disp E "The zip file seems corrupted, failed." disp E "The zip file seems corrupted, failed."
rm -rf $dir > /dev/null 2>&1 rm -rf $dir >/dev/null 2>&1
continue continue
;; ;;
esac esac
@@ -136,7 +137,7 @@ export -f utaz
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Compress directories or files into one or more archive # Compress directories or files into one or more archive
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
taz () taz()
{ {
_doxz() _doxz()
{ {
@@ -170,7 +171,7 @@ taz ()
local procopt="" local procopt=""
[[ $2 -gt 1 ]] && [[ $2 -gt 1 ]] &&
disp W "lzip doesn't support multithreading, falling back to 1 thread." && disp W "lzip doesn't support multithreading, falling back to 1 thread." &&
disp W "Consitder installing plzip to obtain multithreading abilities." disp W "Consider installing plzip to obtain multithreading abilities."
} }
[[ $4 ]] && local verb="-vv" [[ $4 ]] && local verb="-vv"
@@ -243,9 +244,9 @@ taz ()
return $? return $?
} }
for opt in $@ ; do for opt in $@; do
case $opt in case $opt in
"-h"|"--help") "-h" | "--help")
echo "taz: archive all files of a directory." echo "taz: archive all files of a directory."
echo echo
echo "Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]" echo "Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]"
@@ -273,23 +274,23 @@ taz ()
return 0 return 0
;; ;;
"-d"|"--delete") "-d" | "--delete")
local willrm=1 local willrm=1
;; ;;
"-f"?*|"--format"?*) "-f"?* | "--format"?*)
local compform=$(echo "$opt" | cut -f 2- -d '=') local compform=$(echo "$opt" | cut -f 2- -d '=')
;; ;;
"-p"?*|"--parallel"?*) "-p"?* | "--parallel"?*)
local nproc=$(echo "$opt" | cut -f 2- -d '=') local nproc=$(echo "$opt" | cut -f 2- -d '=')
;; ;;
"-v"|"--verbose") "-v" | "--verbose")
local verbose=1 local verbose=1
;; ;;
"-q"|"--quiet") "-q" | "--quiet")
QUIET=1 QUIET=1
;; ;;
@@ -359,3 +360,6 @@ taz ()
unset QUIET unset QUIET
} }
export -f taz export -f taz
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -36,7 +37,7 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Display a backtrace # Display a backtrace
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function backtrace () function backtrace()
{ {
echo "========= Call stack =========" echo "========= Call stack ========="
typeset -i i=0 typeset -i i=0
@@ -45,7 +46,7 @@ function backtrace ()
for func in "${FUNCNAME[@]}"; do for func in "${FUNCNAME[@]}"; do
if [[ $i -ne 0 ]]; then if [[ $i -ne 0 ]]; then
printf '%15s() %s:%d\n' \ printf '%15s() %s:%d\n' \
"$func" "${BASH_SOURCE[$i]}" "${BASH_LINENO[ (( $i - 1)) ]}" "$func" "${BASH_SOURCE[$i]}" "${BASH_LINENO[(($i - 1))]}"
fi fi
let i++ || true let i++ || true
done done
@@ -56,25 +57,24 @@ function backtrace ()
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Function to be trapped for errors investigation # Function to be trapped for errors investigation
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function error () function error()
{ {
local errcode=$? local errcode=$?
backtrace backtrace
return $errcode return $errcode
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Activate or deactivate error trapping to display backtrace # Activate or deactivate error trapping to display backtrace
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
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 for opt in $@; do
case $opt in case $opt in
"-h"|"--help") "-h" | "--help")
echo "Try to activate backtrace display for script debugging." echo "Try to activate backtrace display for script debugging."
echo echo
echo "Options:" echo "Options:"
@@ -105,3 +105,6 @@ settrace ()
unset status unset status
} }
export -f settrace export -f settrace
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -111,7 +112,6 @@ 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
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -146,3 +146,6 @@ disp()
unset heads unset heads
} }
export -f disp export -f disp
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -47,19 +48,18 @@ expandlist()
echo $result echo $result
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Clean a directory or a tree from temporary or backup files # Clean a directory or a tree from temporary or backup files
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
clean () clean()
{ {
for opt in $@ ; do for opt in $@; do
case $opt in case $opt in
"-r"|"--recurs") "-r" | "--recurs")
local recursive=1 local recursive=1
;; ;;
"-h"|"--help") "-h" | "--help")
echo "clean: erase backup files in the given directories." echo "clean: erase backup files in the given directories."
echo echo
echo "Usage: clean [option] [directory1] [...[directoryX]]" echo "Usage: clean [option] [directory1] [...[directoryX]]"
@@ -73,11 +73,11 @@ clean ()
return 0 return 0
;; ;;
"-s"|"--shell") "-s" | "--shell")
local outshell=1 local outshell=1
;; ;;
"-f"|"--force") "-f" | "--force")
local force=1 local force=1
;; ;;
@@ -100,7 +100,7 @@ clean ()
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 "#*#" \ local dellist=$(find "$dir" $findopt -type f -name "*~" -o -name "#*#" \
-o -name "*.bak" -o -name ".~*#") -o -name "*.bak" -o -name ".~*#")
for f in $dellist; do for f in $dellist; do
if [[ ! $outshell ]]; then if [[ ! $outshell ]]; then
@@ -114,31 +114,29 @@ clean ()
} }
export -f clean export -f clean
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Create a directory then goes inside # Create a directory then goes inside
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
mcd () mcd()
{ {
if [[ ! $# -eq 1 ]] ; then if [[ ! $# -eq 1 ]]; then
disp E "Create a directory then goes inside." disp E "Create a directory then goes inside."
disp E "Usage: mcd <directory>" disp E "Usage: mcd <directory>"
return 1 return 1
fi fi
mkdir -pv $1 && cd $1 mkdir -pv "$1" && cd "$1" || echo "Failed create or change directory."
} }
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 _
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
rmspc () rmspc()
{ {
local lst="" local lst=""
for opt in $@ ; do for opt in $@; do
case $opt in case $opt in
"-h"|"--help") "-h" | "--help")
echo "rmspc: remove spaces from all filenames in current directories" echo "rmspc: remove spaces from all filenames in current directories"
echo echo
echo "Usage: rmspc [option]" echo "Usage: rmspc [option]"
@@ -156,11 +154,11 @@ rmspc ()
return 0 return 0
;; ;;
"-r"|"--recursive") "-r" | "--recursive")
local recurs=1 local recurs=1
;; ;;
"-c"?*|"--subst-char"?*) "-c"?* | "--subst-char"?*)
if [[ $(echo $opt | grep "=") ]]; then if [[ $(echo $opt | grep "=") ]]; then
local substchar=$(echo "$opt" | cut -f 2- -d '=') local substchar=$(echo "$opt" | cut -f 2- -d '=')
else else
@@ -168,11 +166,11 @@ rmspc ()
fi fi
;; ;;
"-v"|"--verbose") "-v" | "--verbose")
local verb=1 local verb=1
;; ;;
"-s"|"--shell") "-s" | "--shell")
local shell=1 local shell=1
;; ;;
@@ -192,9 +190,9 @@ rmspc ()
[[ $recurs ]] && [[ -d "$f" ]] && ( [[ $recurs ]] && [[ -d "$f" ]] && (
[[ $verb ]] && disp I "Entering directory $(pwd)/$f ..." [[ $verb ]] && disp I "Entering directory $(pwd)/$f ..."
local lastdir=$f local lastdir=$f
pushd "$f" > /dev/null pushd "$f" >/dev/null
rmspc $@ rmspc $@
popd > /dev/null popd >/dev/null
[[ $verb ]] && disp I "Leaving directory $(pwd)/$lastdir" [[ $verb ]] && disp I "Leaving directory $(pwd)/$lastdir"
unset lastdir unset lastdir
) )
@@ -212,3 +210,6 @@ rmspc ()
unset lst substchar verb shell newf command mvopt unset lst substchar verb shell newf command mvopt
} }
export -f rmspc export -f rmspc
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -46,3 +47,6 @@ busy()
cat /dev/urandom | hexdump -C | grep "$pattern" cat /dev/urandom | hexdump -C | grep "$pattern"
unset pattern unset pattern
} }
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -66,3 +67,5 @@ EOF
} }
export -f help export -f help
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -36,17 +37,16 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Show profile version # Show profile version
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
ver () 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)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
meteo () meteo()
{ {
cities=$@ cities=$@
[[ $# -eq 0 ]] && local cities=$DEFAULT_CITY [[ $# -eq 0 ]] && local cities=$DEFAULT_CITY
@@ -57,7 +57,6 @@ meteo ()
} }
export -f meteo export -f meteo
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Display system general information # Display system general information
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -88,3 +87,6 @@ showinfo()
fi fi
} }
export -f showinfo export -f showinfo
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -36,7 +37,7 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Change locale to French # Change locale to French
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
setfr () setfr()
{ {
# Set fr locale definitions # Set fr locale definitions
export LANG=fr_FR.UTF-8 export LANG=fr_FR.UTF-8
@@ -48,7 +49,7 @@ export -f setfr
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Change locale to C standard # Change locale to C standard
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
setc () setc()
{ {
# Locale definitions # Locale definitions
export LANG=C export LANG=C
@@ -60,7 +61,7 @@ export -f setc
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Change locale to US (needed by Steam) # Change locale to US (needed by Steam)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
setus () setus()
{ {
# Locale definitions # Locale definitions
export LANG=en_US.UTF-8 export LANG=en_US.UTF-8
@@ -68,3 +69,6 @@ setus ()
export LC_ALL=en_US.UTF-8 export LC_ALL=en_US.UTF-8
} }
export -f setus export -f setus
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -36,7 +37,7 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Determine if parameter is a valid IPv4 address # Determine if parameter is a valid IPv4 address
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
isipv4 () isipv4()
{ {
# Set up local variables # Set up local variables
local ip=$1 local ip=$1
@@ -47,8 +48,8 @@ isipv4 ()
IFS="." IFS="."
ip=($ip) ip=($ip)
IFS=$old_ifs IFS=$old_ifs
if [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ if [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 &&
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]; then ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]; then
if [[ -t 1 ]]; then if [[ -t 1 ]]; then
disp "The given IPv4 is valid." disp "The given IPv4 is valid."
fi fi
@@ -62,11 +63,10 @@ isipv4 ()
} }
export -f isipv4 export -f isipv4
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Determine if parameter is a valid IPv4 address # Determine if parameter is a valid IPv4 address
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
isipv6 () isipv6()
{ {
local ip="$1" local ip="$1"
local regex='^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$' local regex='^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$'
@@ -82,3 +82,6 @@ isipv6 ()
return 1 return 1
} }
export -f isipv6 export -f isipv6
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -36,12 +37,12 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Look for a package within installed one # Look for a package within installed one
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
pkgs () pkgs()
{ {
local count=0 local count=0
for opt in $@ ; do for opt in $@; do
case $opt in case $opt in
"-h"|"--help") "-h" | "--help")
echo "dpkgs: look for an installed package by it's name." echo "dpkgs: look for an installed package by it's name."
echo echo
echo "Usage: dpkgs <string>" echo "Usage: dpkgs <string>"
@@ -56,7 +57,7 @@ pkgs ()
*) *)
local pkg=$1 && shift local pkg=$1 && shift
count=$(( $count + 1 )) count=$(($count + 1))
[[ $count -gt 1 ]] && [[ $count -gt 1 ]] &&
disp E "Please specify a package name, without space, eventually partial." && disp E "Please specify a package name, without space, eventually partial." &&
return 1 return 1
@@ -77,3 +78,6 @@ pkgs ()
$cmd | grep $pkg $cmd | grep $pkg
} }
export -f pkgs export -f pkgs
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -36,17 +37,16 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Search processes matching the given string # Search processes matching the given string
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
ppg () ppg()
{ {
ps -edf | grep $@ | grep -v "grep $@" ps -edf | grep "$@" | grep -v "grep $@"
} }
export -f ppg export -f ppg
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Get PID list of the given process name # Get PID list of the given process name
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
gpid () gpid()
{ {
[[ $UID -eq 0 ]] && local psopt="-A" [[ $UID -eq 0 ]] && local psopt="-A"
[[ $# -eq 1 ]] && local single=1 [[ $# -eq 1 ]] && local single=1
@@ -62,14 +62,33 @@ gpid ()
} }
export -f gpid export -f gpid
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Kill all processes owned by the given users # Kill all processes owned by the given users
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
ku () ku()
{ {
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
# ------------------------------------------------------------------------------
kt()
{
[[ -z $1 ]] && echo -e "Usage:\n\tkt <pid> [kill_options]"
local parent_pid="$1" children_pids
shift
children_pids=$(pgrep -P "$parent_pid")
for pid in $children_pids; do
kill_tree "$pid" "$@"
done
kill "$@" "$parent_pid"
}
# ------------------------------------------------------------------------------
# EOF

View File

@@ -76,7 +76,7 @@ function timer_stop
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Function triguered internaly by bash : defining prompt # Function triguered internaly by bash : defining prompt
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
set_prompt () set_prompt()
{ {
Last_Command=$? # Must come first! Last_Command=$? # Must come first!
Blue='\[\e[0;34m\]' Blue='\[\e[0;34m\]'
@@ -123,3 +123,6 @@ set_prompt ()
# the text color to the default. # the text color to the default.
PS1+="$ICyan\\w \\\$$Default " PS1+="$ICyan\\w \\\$$Default "
} }
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -47,7 +48,7 @@ genpwd()
for opt in $@; do for opt in $@; do
case $opt in case $opt in
"-h"|"--help") "-h" | "--help")
echo "genpwd: generate one or more secure random password." echo "genpwd: generate one or more secure random password."
echo echo
echo "Usage: genpwd [options] [--extracars=<cars>] [--length=<n>] [nb_passwd]" echo "Usage: genpwd [options] [--extracars=<cars>] [--length=<n>] [nb_passwd]"
@@ -75,29 +76,29 @@ genpwd()
echo echo
return 0 return 0
;; ;;
"-s"|"--nosymbols") "-s" | "--nosymbols")
symb=0 symb=0
;; ;;
"-n"|"--nonumbers") "-n" | "--nonumbers")
numb=0 numb=0
;; ;;
"-u"|"--noup") "-u" | "--noup")
maj=0 maj=0
;; ;;
"-l"|"--nolow") "-l" | "--nolow")
min=0 min=0
;; ;;
"-e"?*|"--extracars"?*) "-e"?* | "--extracars"?*)
local extcar=$(echo "$opt" | cut -f 2- -d '=') local extcar=$(echo "$opt" | cut -f 2- -d '=')
;; ;;
"-L"?*|"--length"?*) "-L"?* | "--length"?*)
local length=$(echo "$opt" | cut -f 2- -d '=') local length=$(echo "$opt" | cut -f 2- -d '=')
if ! [[ $length =~ ^[0-9]+$ ]]; then if ! [[ $length =~ ^[0-9]+$ ]]; then
disp E "The --length parameter requires a number." disp E "The --length parameter requires a number."
return 1 return 1
fi fi
;; ;;
"-o"?*|"--occurences"?*) "-o"?* | "--occurences"?*)
local occurs=$(echo "$opt" | cut -f 2- -d '=') local occurs=$(echo "$opt" | cut -f 2- -d '=')
if ! [[ $occurs =~ ^[1-9]+$ ]]; then if ! [[ $occurs =~ ^[1-9]+$ ]]; then
disp E "The --occurs parameter requires a number from 1 to 9." disp E "The --occurs parameter requires a number from 1 to 9."
@@ -120,13 +121,12 @@ genpwd()
done done
# 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
# elsewhere, we choose an other char, to compensate weak bash randomizer # elsewhere, we choose an other char, to compensate weak bash randomizer
while [[ -z $char ]]; do while [[ -z $char ]]; do
local char=$(echo ${1:RANDOM%${#1}:1} $RANDOM) local char="${1:RANDOM%${#1}:1} $RANDOM"
if [[ $(awk -F"$char" '{print NF-1}' <<< "$picked") -gt $occurs ]]; then if [[ $(awk -F"$char" '{print NF-1}' <<<"$picked") -gt $occurs ]]; then
unset char unset char
fi fi
done done
@@ -135,7 +135,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 in $(seq 1 $nbpwd); 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
@@ -145,27 +145,27 @@ genpwd()
if [[ $symb == 1 ]]; then if [[ $symb == 1 ]]; then
pickcar '!.@#&%/^-_' pickcar '!.@#&%/^-_'
carset+='!.@#&%/^-_' carset+='!.@#&%/^-_'
(( rlength++ )) ((rlength++))
fi fi
if [[ $numb == 1 ]]; then if [[ $numb == 1 ]]; then
pickcar '0123456789' pickcar '0123456789'
carset+='0123456789' carset+='0123456789'
(( rlength++ )) ((rlength++))
fi fi
if [[ $maj == 1 ]]; then if [[ $maj == 1 ]]; then
pickcar 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' pickcar 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
carset+='ABCDEFGHIJKLMNOPQRSTUVWXYZ' carset+='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
(( rlength++ )) ((rlength++))
fi fi
if [[ $min == 1 ]]; then if [[ $min == 1 ]]; then
pickcar 'abcdefghijklmnopqrstuvwxyz' pickcar 'abcdefghijklmnopqrstuvwxyz'
carset+='abcdefghijklmnopqrstuvwxyz' carset+='abcdefghijklmnopqrstuvwxyz'
(( rlength++ )) ((rlength++))
fi fi
if [[ -n $extcar ]]; then if [[ -n $extcar ]]; then
pickcar "$extcar" pickcar "$extcar"
carset+=$extcar carset+=$extcar
(( rlength++ )) ((rlength++))
fi fi
# Check if we have enough car to have something viable # Check if we have enough car to have something viable
@@ -175,7 +175,7 @@ genpwd()
return 1 return 1
fi fi
for i in $( seq 1 $(( $length - $rlength )) ); do for i in $(seq 1 $(($length - $rlength))); do
pickcar "$carset" pickcar "$carset"
done done
} | sort -R | awk '{printf "%s", $1}' } | sort -R | awk '{printf "%s", $1}'
@@ -184,3 +184,6 @@ genpwd()
done done
} }
export -f genpwd export -f genpwd
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -43,7 +44,7 @@ rain()
local rain_colors=("\e[37m" "\e[37;1m") local rain_colors=("\e[37m" "\e[37;1m")
# More from 256 color mode # More from 256 color mode
for i in {244..255}; do for i in {244..255}; do
rain_colors=( "${rain_colors[@]}" "\e[38;5;${i}m" ) rain_colors=("${rain_colors[@]}" "\e[38;5;${i}m")
done done
local rain_tab=${#rain_cars[@]} local rain_tab=${#rain_cars[@]}
local rain_color_tab=${#rain_colors[@]} local rain_color_tab=${#rain_colors[@]}
@@ -54,18 +55,17 @@ rain()
local X=0 Y=0 drop_length=0 rain_drop=0 local X=0 Y=0 drop_length=0 rain_drop=0
local max_rain_width=0 new_rain_odd=0 falling_odd=0 local max_rain_width=0 new_rain_odd=0 falling_odd=0
sigwinch() { sigwinch() {
term_width=$(tput cols) term_width=$(tput cols)
term_height=$(tput lines) term_height=$(tput lines)
#step_duration=0.025 #step_duration=0.025
(( max_rain_width = term_width * term_height / 4 )) ((max_rain_width = term_width * term_height / 4))
(( max_rain_height = term_height < 10 ? 1 : term_height / 10 )) ((max_rain_height = term_height < 10 ? 1 : term_height / 10))
# In percentage # In percentage
(( new_rain_odd = term_height > 50 ? 100 : term_height * 2 )) ((new_rain_odd = term_height > 50 ? 100 : term_height * 2))
(( new_rain_odd = new_rain_odd * 75 / 100 )) ((new_rain_odd = new_rain_odd * 75 / 100))
(( falling_odd = term_height > 25 ? 100 : term_height * 4 )) ((falling_odd = term_height > 25 ? 100 : term_height * 4))
(( falling_odd = falling_odd * 90 / 100 )) ((falling_odd = falling_odd * 90 / 100))
} }
do_exit() { do_exit() {
@@ -80,19 +80,19 @@ rain()
Y=${rains[idx + 1]} Y=${rains[idx + 1]}
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 " echo -ne "\e[${y};${X}H "
done done
done done
for ((idx = 0; idx < num_rains * num_rain_metadata; idx += num_rain_metadata)); do for ((idx = 0; idx < num_rains * num_rain_metadata; idx += num_rain_metadata)); do
if (( 100 * RANDOM / 32768 < falling_odd )); then if ((100 * RANDOM / 32768 < falling_odd)); then
# Falling # Falling
if (( ++rains[idx + 1] > term_height )); then if ((++rains[idx + 1] > term_height)); then
# Out of screen, bye sweet <3 # Out of screen, bye sweet <3
rains=("${rains[@]:0:idx}" rains=("${rains[@]:0:idx}"
"${rains[@]:idx+num_rain_metadata:num_rains*num_rain_metadata}") "${rains[@]:idx+num_rain_metadata:num_rains*num_rain_metadata}")
(( num_rains-- )) ((num_rains--))
continue continue
fi fi
fi fi
@@ -102,7 +102,7 @@ rain()
drop_color=${rains[idx + 3]} drop_color=${rains[idx + 3]}
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}" echo -ne "\e[${y};${X}H${drop_color}${rain_drop}"
done done
done done
@@ -118,24 +118,24 @@ rain()
local rains=() local rains=()
local num_rains=0 local num_rains=0
sigwinch sigwinch
while (( exit_st <= 0 )); do while ((exit_st <= 0)); do
if (( $exit_st <=0 )); then if (($exit_st <= 0)); then
read -n 1 -t $step_duration ch read -n 1 -t $step_duration ch
case "$ch" in case "$ch" in
q|Q) q | Q)
do_exit do_exit
;; ;;
esac esac
if (( num_rains < max_rain_width )) && (( 100 * RANDOM / 32768 < new_rain_odd )); then if ((num_rains < max_rain_width)) && ((100 * RANDOM / 32768 < new_rain_odd)); then
# Need new |, 1-based # Need new |, 1-based
rain_drop="${rain_cars[rain_tab * RANDOM / 32768]}" rain_drop="${rain_cars[rain_tab * RANDOM / 32768]}"
drop_color="${rain_colors[rain_color_tab * RANDOM / 32768]}" drop_color="${rain_colors[rain_color_tab * RANDOM / 32768]}"
drop_length=$(( max_rain_height * RANDOM / 32768 + 1 )) drop_length=$((max_rain_height * RANDOM / 32768 + 1))
X=$(( term_width * RANDOM / 32768 + 1 )) X=$((term_width * RANDOM / 32768 + 1))
Y=$(( 1 - drop_length )) Y=$((1 - drop_length))
rains=( "${rains[@]}" "$X" "$Y" "$rain_drop" "$drop_color" "$drop_length" ) rains=("${rains[@]}" "$X" "$Y" "$rain_drop" "$drop_color" "$drop_length")
(( num_rains++ )) ((num_rains++))
fi fi
# Let rain fall! # Let rain fall!
@@ -152,3 +152,6 @@ rain()
trap - WINCH trap - WINCH
} }
export -f rain export -f rain
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -36,7 +37,7 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Remove host from know_host (name and IP) for the active user # Remove host from know_host (name and IP) for the active user
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
rmhost () rmhost()
{ {
if [[ "$#" -lt 1 ]]; then if [[ "$#" -lt 1 ]]; then
disp E "Incorrect number of parameters." disp E "Incorrect number of parameters."
@@ -46,9 +47,9 @@ rmhost ()
while [[ $1 ]]; do while [[ $1 ]]; do
local hst=$1 && shift local hst=$1 && shift
isipv4 $hst > /dev/null isipv4 $hst >/dev/null
local v4=$? local v4=$?
isipv6 $hst > /dev/null isipv6 $hst >/dev/null
local v6=$? local v6=$?
if [[ $v4 -eq 0 || $v6 -eq 0 ]]; then if [[ $v4 -eq 0 || $v6 -eq 0 ]]; then
@@ -66,26 +67,25 @@ rmhost ()
if [[ $hst ]]; then if [[ $hst ]]; then
disp I "Removing host $hst from ssh known_host..." disp I "Removing host $hst from ssh known_host..."
ssh-keygen -R $hst > /dev/null ssh-keygen -R $hst >/dev/null
fi fi
if [[ $ip ]]; then if [[ $ip ]]; then
disp I "Removing IP $ip from ssh known_host..." disp I "Removing IP $ip from ssh known_host..."
ssh-keygen -R $ip > /dev/null ssh-keygen -R $ip >/dev/null
fi fi
unset hst ip unset hst ip
done done
} }
export -f rmhost export -f rmhost
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Login root via SSH on the given machine # Login root via SSH on the given machine
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
ssr () ssr()
{ {
for opt in $@ ; do for opt in $@; do
case $opt in case $opt in
"-h"|"--help") "-h" | "--help")
echo "ssr: do a root user ssh login." echo "ssr: do a root user ssh login."
echo echo
echo "Usage: ssr <server [ssh options]>" echo "Usage: ssr <server [ssh options]>"
@@ -103,3 +103,6 @@ ssr ()
ssh -Y root@$srv $@ ssh -Y root@$srv $@
} }
export -f ssr export -f ssr
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -50,6 +51,7 @@ check_updates()
disp E "Can't download version file, impossible to proceed!" disp E "Can't download version file, impossible to proceed!"
return 5 return 5
} }
if [[ -s /tmp/version ]]; then if [[ -s /tmp/version ]]; then
local lastver=$(cat /tmp/version) local lastver=$(cat /tmp/version)
if [[ $lastver != $PROFVERSION ]]; then if [[ $lastver != $PROFVERSION ]]; then

View File

@@ -44,35 +44,34 @@ fi
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# path* : private functions for PATH variable management # path* : private functions for PATH variable management
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
pathremove () pathremove()
{ {
local ifs=':' local ifs=':'
local newpath local newpath
local dir local dir
local pathvar=${2:-PATH} local pathvar=${2:-PATH}
for dir in ${!pathvar} ; do for dir in ${!pathvar}; do
if [ "$dir" != "$1" ] ; then if [ "$dir" != "$1" ]; then
newpath=${newpath:+$newpath:}$dir newpath=${newpath:+$newpath:}$dir
fi fi
done done
export $pathvar="$newpath" export $pathvar="$newpath"
} }
pathprepend () pathprepend()
{ {
pathremove $1 $2 pathremove $1 $2
local pathvar=${2:-PATH} local pathvar=${2:-PATH}
export $pathvar="$1${!pathvar:+:${!pathvar}}" export $pathvar="$1${!pathvar:+:${!pathvar}}"
} }
pathappend () pathappend()
{ {
pathremove $1 $2 pathremove $1 $2
local pathvar=${2:-PATH} local pathvar=${2:-PATH}
export $pathvar="${!pathvar:+${!pathvar}:}$1" export $pathvar="${!pathvar:+${!pathvar}:}$1"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# ********************************** MAIN PROGRAM ****************************** # ********************************** MAIN PROGRAM ******************************
@@ -99,7 +98,7 @@ fi
export PROFVERSION=$(cat $MYPATH/version) export PROFVERSION=$(cat $MYPATH/version)
# Build PATH environment variable # Build PATH environment variable
if [[ $EUID -eq 0 ]] ; then if [[ $EUID -eq 0 ]]; then
pathappend /sbin:/usr/sbin pathappend /sbin:/usr/sbin
fi fi
[[ -d /share/services/gestparc ]] && pathappend /share/services/gestparc [[ -d /share/services/gestparc ]] && pathappend /share/services/gestparc
@@ -139,7 +138,7 @@ export DEFAULT_CITY="Toulouse"
[[ -f ~/.profile.conf ]] && . ~/.profile.conf [[ -f ~/.profile.conf ]] && . ~/.profile.conf
# Load module scripts # Load module scripts
for script in $MYPATH/profile.d/*.sh ; do for script in $MYPATH/profile.d/*.sh; do
if [[ -r $script ]]; then if [[ -r $script ]]; then
. $script . $script
fi fi

View File

@@ -1 +1 @@
3.3.1 3.3.2