25 Commits

Author SHA1 Message Date
fatalerrors
128cfe8c87 improved upgrade system, version bump 2026-03-05 11:25:05 +01:00
fatalerrors
e1c2705fdd added ppu and ppn 2026-03-05 11:20:23 +01:00
fatalerrors
368bc11acf add many compression format to utaz 2026-03-05 10:55:17 +01:00
fatalerrors
a068d57ba5 utaz finally work with many formats, with optimizations 2026-03-05 10:24:25 +01:00
fatalerrors
ffee8c2e47 added help to rain, fixed french comments 2026-03-04 16:17:36 +01:00
geoffray.levasseur
9ff5792790 configurable rain 2026-03-04 15:55:11 +01:00
root
6a2d9b0fee adaptation to trixie and excalibur 2025-11-19 14:35:40 +01:00
Geoffray Levasseur-Brandin
9b2c764181 typos 2025-06-19 14:50:46 +02:00
Geoffray Levasseur-Brandin
3d5a5e7718 typos 2025-06-19 14:50:21 +02:00
Geoffray Levasseur-Brandin
47e89b3b09 compress.sh: multiple correction and securisation 2025-06-19 14:49:49 +02:00
Geoffray Levasseur-Brandin
f0f80e2924 better display implementation 2025-06-19 14:47:14 +02:00
Geoffray Levasseur-Brandin
b08e457146 version bump 2025-06-19 14:42:14 +02:00
Geoffray Levasseur-Brandin
56e34bc346 few varaible securisation, new alias hdu 2025-06-19 14:41:31 +02:00
Geoffray Levasseur-Brandin
e9e9993dfc finished profile_uprade implementation 2025-06-19 14:40:02 +02:00
Geoffray Levasseur-Brandin
ff4c6702b7 secured rmhost 2025-06-19 14:39:10 +02:00
Geoffray Levasseur-Brandin
87dea45295 fixed some variable declarations 2025-06-19 14:38:18 +02:00
Geoffray Levasseur-Brandin
0abf481cf6 various improvement and securisation 2025-06-19 14:37:32 +02:00
Geoffray Levasseur-Brandin
a75299f7b4 non gnu date compatible, use local vars where possible 2025-06-19 14:36:13 +02:00
Geoffray Levasseur-Brandin
eeb87c5bfc make delay parametrable 2025-06-19 14:34:22 +02:00
Geoffray Levasseur-Brandin
4879b418db factorized code / thiner implementation 2025-06-19 14:33:36 +02:00
Geoffray Levasseur-Brandin
f944271488 added file_stats function 2025-06-19 14:32:29 +02:00
Geoffray Levasseur-Brandin
4be2e5ea87 add url encode / secure isipv4 2025-06-19 14:31:19 +02:00
Geoffray Levasseur-Brandin
9d528a6491 fix kt function 2025-06-19 14:30:38 +02:00
Geoffray Levasseur-Brandin
bef205ae84 bugfix, esthetic cleanup, better comments, version bump 2024-06-21 16:19:44 +02:00
Geoffray Levasseur
9e49e3e4d7 fixed url and redirection 2023-10-06 12:52:15 +02:00
19 changed files with 1260 additions and 663 deletions

View File

@@ -7,6 +7,14 @@ Current version from Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
Version history: Version history:
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
# 05/03/2026 v3.6.0
Improved utaz to make it multiformat with lot of it
Introduced ppu and ppn
Improved update system
# 04/03/2026 v3.5.0
rain has now configurable speed and color
showinfo adapted to fastfetch, replacing neofetch
# 24/02/2022 v3.3.1 # 24/02/2022 v3.3.1
Fixed version detection Fixed version detection

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.
@@ -34,12 +35,109 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Smartly uncompress archives (zip only) # Smartly uncompress archives (zip only for now)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
utaz() utaz()
{ {
_ununzip()
{
unzip -o "$1" -d "$2" >/dev/null 2>&1
}
_untar()
{
tar -xf "$1" -C "$2"
}
_ungzip()
{
tar -xzf "$1" -C "$2"
}
_unbzip2()
{
tar -xjf "$1" -C "$2"
}
_unxz()
{
tar -xJf "$1" -C "$2"
}
_unlzop()
{
lzop -d "$1" -o "$2/$(basename "${1%.*}")"
}
_unlzip()
{
if command -v plzip >/dev/null 2>&1; then
plzip -d -c "$1" > "$2/$(basename "${1%.*}")"
else
lzip -d -c "$1" > "$2/$(basename "${1%.*}")"
fi
}
_ununrar()
{
unrar x -o+ "$1" "$2/" >/dev/null 2>&1
}
_ununarj()
{
unarj e "$1" "$2/" >/dev/null 2>&1
}
_unlza()
{
# lha typically extracts into the current directory
# We ensure it hits the target directory
(cd "$2" && lha -x "../$1") >/dev/null 2>&1
}
_ununace()
{
unace x "$1" "$2/" >/dev/null 2>&1
}
_un7z()
{
7z x "$1" -o"$2/" >/dev/null 2>&1
}
_unzstd()
{
# Zstd decompresses files directly, often requiring tar for archives
tar --zstd -xf "$1" -C "$2"
}
_uncpio()
{
# CPIO requires careful directory handling
(cd "$2" && cpio -id < "../$1") >/dev/null 2>&1
}
_uncabextract()
{
# Requires 'cabextract' package
cabextract "$1" -d "$2/" >/dev/null 2>&1
}
_undeb()
{
# Extracts data content from a Debian package
dpkg-deb -x "$1" "$2/" >/dev/null 2>&1
}
_unrpm()
{
# Extracts CPIO-based payload from an RPM package
# Needs rpm2cpio and cpio
rpm2cpio "$1" | (cd "$2/" && cpio -idmv) >/dev/null 2>&1
}
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."
@@ -75,58 +173,137 @@ utaz()
*) *)
# The ${opt%/} writing is to remove trailing / if any # The ${opt%/} writing is to remove trailing / if any
local LIST="$LIST ${opt%/}" local LIST="${LIST} ${opt%/}"
;; ;;
esac esac
done done
[[ $createdir && $nodir ]] && disp E "The --create-dir and --no-dir options are mutually exclusive." [[ -n ${createdir} && -n ${nodir} ]] && \
disp E "The --create-dir and --no-dir options are mutually exclusive."
[[ ! $LIST ]] && local LIST="." [[ -z ${LIST} ]] && local LIST="."
for zitem in ${LIST}; do
for zitem in $LIST; do for f in "${zitem}"/*; do
[[ $(ls $zitem/*.zip 2> /dev/null | wc -l) -eq 0 ]] && local dir="${f%.*}"
disp W "$zitem contains no supported archive file, skipping." && local extractor=""
case "$f" in
*.zip)
extractor="_ununzip"
;;
*.tar.gz|*.tgz)
extractor="_ungzip"
;;
*.tar.bz2)
extractor="_unbzip2"
;;
*.tar.xz)
extractor="_unxz"
;;
*.tar.lz)
extractor="_unlzop"
;;
*.tar)
extractor="_untar"
;;
*.rar)
extractor="_ununrar"
;;
*.arj)
extractor="_ununarj"
;;
*.lzh|*.lha)
extractor="_unlha"
;;
*.ace)
extractor="_ununace"
;;
*.7z)
extractor="_un7z"
;;
*.zst)
extractor="_unzstd"
;;
*.cpio)
extractor="_uncpio"
;;
*.cab)
extractor="_uncabextract"
;;
*.deb)
extractor="_undeb"
;;
*.rpm)
extractor="_unrpm"
;;
*)
disp I "File ${f} is not a supported archive, skipping."
continue continue
;; # Skip non-archive files
esac
for f in $zitem/*.zip; do # Verify binary existence
disp I "Processing archive $zitem/$f... " local cmd=${extractor//_un/}
local dir=${f::-4} if [[ $cmd == "deb" ]]; then
command -v dpkg-deb >/dev/null 2>&1 || {
disp E "The program 'dpkg-deb' is not installed, aborting."
continue
}
elif [[ $cmd == "rpm" ]]; then
command -v rpm2cpio >/dev/null 2>&1 || {
disp E "The program 'rpm2cpio' is not installed, aborting."
continue
}
command -v cpio >/dev/null 2>&1 || {
disp E "The program 'cpio' is not installed, aborting."
continue
}
else
command -v ${cmd} >/dev/null 2>&1 || {
disp E "Binary ${cmd} necessary to extract ${f} is missing."
continue
}
mkdir -p $dir disp I "Processing archive ${f} with ${extractor}..."
mkdir -p "${dir}"
[[ $? -gt 0 ]] && [[ $? -gt 0 ]] &&
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 ${extractor} "${f}" "${dir}"
case $? in case $? in
0) 0)
[[ $willrm ]] && rm -f $f && disp I "File $zitem/$f deleted." [[ -n ${willrm} ]] &&
rm -f "${f}" && disp I "File ${zitem}/${f} deleted."
;; ;;
1) 1)
disp W "Compression program returned a warning: deletion canceled." disp W "Compression program returned a warning: deletion canceled."
;; ;;
*) *)
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
if [[ $createdir ]]; then if [[ -n ${createdir} ]]; then
disp I "Archive extracted successfully in subdirectory." disp I "Archive extracted successfully in subdirectory."
elif [[ $nodir ]]; then elif [[ -n ${nodir} ]]; then
mv ./$dir/* ./ && rmdir $dir mv "./${dir}/"* ./ && rmdir "${dir}"
disp I "Archive extracted successfully, no subdirectory needed." disp I "Archive extracted successfully, no subdirectory needed."
else else
subdirs=$(find $dir -maxdepth 1 | wc -l) # Set nullglob to ensure the array is empty if no files match
if [[ $subdirs -eq 2 ]]; then shopt -s nullglob
mv ./$dir/* ./ && rmdir $dir local contents=( "${dir}"/* )
# Check if exactly one item exists and if that item is a directory
if [[ ${#contents[@]} -eq 1 ]] && [[ -d "${contents[0]}" ]]; then
# Single directory detected
mv "${contents[0]}"/* ./ && rmdir "${dir}"
disp I "Archive extracted successfully, no subdirectory needed." disp I "Archive extracted successfully, no subdirectory needed."
else else
disp I "Archive extracted successfully in subdirectory." disp I "Archive extracted successfully in subdirectory."
fi fi
shopt -u nullglob
fi fi
done done
done done
@@ -166,11 +343,11 @@ taz ()
disp E "Program 'plzip' or 'lzip' are not installed, aborting." disp E "Program 'plzip' or 'lzip' are not installed, aborting."
return 127 return 127
} }
local command=lzip command=lzip
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"
@@ -194,7 +371,7 @@ taz ()
local procopt="" local procopt=""
[[ $2 -gt 1 ]] && [[ $2 -gt 1 ]] &&
disp W "gzip doesn't support multithreading, falling back to 1 thread." && disp W "gzip doesn't support multithreading, falling back to 1 thread." &&
disp W "Consitder installing pigz to obtain multithreading abilities." disp W "Consider installing pigz to obtain multithreading abilities."
} }
[[ $4 ]] && local verb="--verbose" [[ $4 ]] && local verb="--verbose"
@@ -218,7 +395,7 @@ taz ()
local procopt="" local procopt=""
[[ $2 -gt 1 ]] && [[ $2 -gt 1 ]] &&
disp W "bzip2 doesn't support multithreading, falling back to 1 thread." && disp W "bzip2 doesn't support multithreading, falling back to 1 thread." &&
disp W "Consitder installing pbzip2 to obtain multithreading abilities." disp W "Consider installing pbzip2 to obtain multithreading abilities."
} }
[[ $4 ]] && local verb="-v" [[ $4 ]] && local verb="-v"
@@ -290,7 +467,7 @@ taz ()
;; ;;
"-q" | "--quiet") "-q" | "--quiet")
QUIET=1 local quiet=1
;; ;;
"-"*) "-"*)
@@ -311,17 +488,17 @@ taz ()
[[ ! $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 $LIST; do
local donetar=0 local donetar=0
disp I "Processing $item..." disp I "Processing $item..."
if [[ -d $item ]]; then if [[ -d "$item" ]]; then
disp I "\t Creating $item.tar... " disp I "\t Creating $item.tar... "
tar -cf $item{.tar,} tar -cf "$item.tar" "$item"
if [[ ! $? -eq 0 ]]; then if [[ ! $? -eq 0 ]]; then
disp E "tar file creation failed, skipping to next item." disp E "tar file creation failed, skipping to next item."
continue continue
@@ -336,7 +513,7 @@ taz ()
# Skip compression part if tar is asked # Skip compression part if tar is asked
if [[ $compform != "tar" ]]; then if [[ $compform != "tar" ]]; then
disp I "\t Compressing archive..." disp I "\t Compressing archive..."
_do$compform $fname $nproc $complevel $verbose _do$compform "$fname" "$nproc" "$complevel" "$verbose"
[[ ! $? -eq 0 ]] && case $? in [[ ! $? -eq 0 ]] && case $? in
127) 127)
disp E "Compression program unavailable, aborting." disp E "Compression program unavailable, aborting."
@@ -348,14 +525,17 @@ taz ()
;; ;;
esac esac
[[ $donetar -gt 0 ]] && rm $fname [[ $donetar -gt 0 ]] && rm "$fname"
fi fi
if [[ $willrm ]]; then if [[ $willrm ]]; then
disp I "\t Deleting original source as asked... " disp I "\t Deleting original source as asked... "
rm -r $item rm -r "$item"
fi fi
done done
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.
@@ -63,7 +64,6 @@ function error ()
return $errcode return $errcode
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Activate or deactivate error trapping to display backtrace # Activate or deactivate error trapping to display backtrace
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -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.
@@ -40,6 +41,7 @@
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'
# Regular Colors # Regular Colors
export Black='\e[0;30m' export Black='\e[0;30m'
@@ -111,7 +113,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
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -121,28 +122,31 @@ disp()
"I") "I")
local heads="[ ${IGreen}info${DEFAULTFG} ]" local heads="[ ${IGreen}info${DEFAULTFG} ]"
shift shift
[[ -z $QUIET || $QUIET -ne 1 ]] && echo -e "${heads} $@" [[ -z $QUIET || $QUIET -ne 1 ]] && \
printf "%b\n" "${heads} $*${RESETCOL}"
;; ;;
"W") "W")
local heads="[ ${IYellow}Warning${DEFAULTFG} ]" local heads="[ ${IYellow}Warning${DEFAULTFG} ]"
shift shift
echo -e "${heads} $@" >&2 printf "%b\n" "${heads} $*${RESETCOL}" >&2
;; ;;
"E") "E")
local heads="[ ${IRed}ERROR${DEFAULTFG} ]" local heads="[ ${IRed}ERROR${DEFAULTFG} ]"
shift shift
echo -e "${heads} $@" >&2 printf "%b\n" "${heads} $*${RESETCOL}" >&2
;; ;;
"D") "D")
local heads"[ ${ICyan}debug${DEFAULTFG} ]" local heads="[ ${ICyan}debug${DEFAULTFG} ]"
shift shift
[[ -n $DEBUG && $DEBUG -gt 1 ]] && echo -e "${heads} $@" [[ -n $DEBUG && $DEBUG -gt 1 ]] && \
printf "%b\n" "${heads} $*${RESETCOL}"
;; ;;
"*") * )
local heads="" [[ -z $QUIET || $QUIET -ne 1 ]] && \
[[ -z $QUIET || $QUIET -ne 1 ]] && echo -e "$@" printf "%b\n" "$*"
;; ;;
esac esac
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,7 +48,6 @@ 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
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -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,7 +114,6 @@ clean ()
} }
export -f clean export -f clean
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Create a directory then goes inside # Create a directory then goes inside
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -125,11 +124,10 @@ mcd ()
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 _
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -212,3 +210,135 @@ 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
# ------------------------------------------------------------------------------
file_stats()
{
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 OPTIND opt
# Analyse options
while [[ "$1" =~ ^- ]]; do
case "$1" in
-H) human=1 ;;
-d) details=1 ;;
-m) only_avg=1; show_all=0 ;;
-M) only_med=1; show_all=0 ;;
-c) only_count=1; show_all=0 ;;
-t) only_total=1; show_all=0 ;;
-a) human=1; details=1 ;;
-x) ext_filter="${2#.}"; shift ;;
-X) ext_list="${2}"; shift ;;
--min) min_size="$2"; shift ;;
--max) max_size="$2"; shift ;;
--) shift; break ;;
-*) echo "Usage: file_stats [-h] [-d] [-mMctaxX --min N --max N] [path]"; return 1 ;;
esac
shift
done
[ -n "$1" ] && path="$1"
# Prepare find filters
local find_cmd=(find "$path" -type f)
# Extension simple
if [[ -n "$ext_filter" ]]; then
find_cmd+=(-iname "*.$ext_filter")
fi
# Extension liste
if [[ -n "$ext_list" ]]; then
IFS=',' read -ra exts <<< "$ext_list"
find_cmd+=('(')
for i in "${!exts[@]}"; do
[[ $i -ne 0 ]] && find_cmd+=(-o)
find_cmd+=(-iname "*.${exts[$i]}")
done
find_cmd+=(')')
fi
# Taille min/max (à évaluer en octets)
if [[ -n "$min_size" ]]; then
find_cmd+=(-size +"$(numfmt --from=iec "$min_size")"c)
fi
if [[ -n "$max_size" ]]; then
find_cmd+=(-size -"$(( $(numfmt --from=iec "$max_size") + 1 ))"c)
fi
# 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" '
function human_readable(x) {
split("B KiB MiB GiB TiB", units)
for (i=1; x>=1024 && i<5; i++) x /= 1024
return sprintf("%.2f %s", x, units[i])
}
{
sizes[NR] = $1
total += $1
if (min == "" || $1 < min) min = $1
if (max == "" || $1 > max) max = $1
if ($1 == 0) bucket[0]++
else {
b = int(log($1)/log(1024))
bucket[b]++
}
}
END {
count = NR
if (count == 0) {
print "Aucun fichier trouvé."; exit
}
moyenne = total / count
if (count % 2 == 1)
mediane = sizes[(count + 1) / 2]
else
mediane = (sizes[count / 2] + sizes[count / 2 + 1]) / 2
function out(label, val) {
if (human) val = human_readable(val)
printf "%-20s : %s\n", label, val
}
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 {
if (show_all || human || details) {
printf "Statistiques sur \"%s\"\n", path
printf "-------------------------\n"
}
out("Nombre de fichiers", count)
out("Taille totale", total)
out("Taille moyenne", moyenne)
out("Taille médiane", mediane)
out("Taille minimale", min)
out("Taille maximale", max)
}
if (details) {
print "\nHistogramme des tailles :"
for (i = 0; i in bucket; i++) {
low = 2^i
high = 2^(i+1)
if (i == 0)
label = sprintf("%4s %4s", "0", "1K")
else
label = sprintf("%4s %4s", human_readable(low), human_readable(high))
printf "%-20s : %5d fichiers\n", label, bucket[i]
}
}
}'
}
export -f file_stats
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# 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.
@@ -38,11 +39,32 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
busy() busy()
{ {
if [[ -n $1 ]]; then
local pattern="$@"
else
local pattern="ca fe" local pattern="ca fe"
for arg in "$@"; do
case "$arg" in
--delay=*)
delay_ms="${arg#*=}"
if ! [[ $delay_ms =~ ^[0-9]+$ ]]; then
disp E "Invalid delay value, must be an integer (milliseconds)."
return 1
fi fi
cat /dev/urandom | hexdump -C | grep "$pattern" ;;
*)
pattern="$arg"
;;
esac
done
# Convert milliseconds to seconds for 'sleep'
local delay_s=$(awk "BEGIN { printf \"%.3f\", $delay_ms / 1000 }")
cat /dev/urandom | hexdump -C | grep --line-buffered "$pattern" | \
while read -r line; do
echo $line
[[ $delay_ms -gt 0 ]] && sleep "$delay_s"
done
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.
@@ -48,6 +49,8 @@ ku Kill process owned by users in parameter
mcd Create a directory and go inside mcd Create a directory and go inside
meteo Display curent weather forecast for the configured city meteo Display curent weather forecast for the configured city
ppg Display process matching the given parameter ppg Display process matching the given parameter
ppn Display process matching the exact process name given in parameter
ppu Display processes owned by the given user
rain Let the rain fall rain Let the rain fall
rmhost Remove host (IP and/or DNS name) for current known_host rmhost Remove host (IP and/or DNS name) for current known_host
rmspc Remove spaces from all the files in working directory rmspc Remove spaces from all the files in working directory
@@ -66,3 +69,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.
@@ -38,26 +39,29 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
ver() ver()
{ {
[[ -z $PROFVERSION ]] && \
disp W "No version defined. Profile is probably badly installed." && \
return 1
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=$@ local encoded cities=("$@")
[[ $# -eq 0 ]] && local cities=$DEFAULT_CITY [[ $# -eq 0 ]] && cities=("$DEFAULT_CITY")
for city in $cities; do for city in "${cities[@]}"; do
curl https://wttr.in/$city || disp E "Failed fetching datas for $city." encoded=$(urlencode "$city")
curl -s "https://wttr.in/$encoded" || \
disp E "Failed fetching datas for $city."
done done
} }
export -f meteo export -f meteo
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Display system general information # Display system general information
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -68,23 +72,33 @@ showinfo()
if [[ -s /usr/share/figlet/ansi_shadow.flf ]]; then if [[ -s /usr/share/figlet/ansi_shadow.flf ]]; then
local figopt="-f ansi_shadow" local figopt="-f ansi_shadow"
fi fi
figlet -k $(hostname) $figopt if [[ -n $figopt ]]; then
figlet -k $figopt $(hostname)
else else
echo "$(hostname -f)" figlet $(hostname)
fi
else
hostname -f
fi fi
echo "" echo ""
if command -v neofetch >/dev/null 2>&1; then if command -v neofetch >/dev/null 2>&1; then
neofetch neofetch
elif command -v fastfetch >/dev/null 2>&1; then
fastfetch
else else
( (
if [[ -s /etc/os-release ]]; then if [[ -s /etc/os-release ]]; then
# shellcheck disable=SC1091
. /etc/os-release . /etc/os-release
echo "$NAME $VERSION" echo "$NAME $VERSION"
else else
cat /proc/version cat /proc/version
fi fi
echo "Uptime: $(uptime)" echo "Uptime: $(uptime -p)"
) )
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.
@@ -33,38 +34,69 @@
# * OF SUCH DAMAGE. # * OF SUCH DAMAGE.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
locale_check() {
locale -a | grep -qx "$1" || {
disp W "Locale '$1' is not installed on this system."
return 1
}
return 0
}
# ------------------------------------------------------------------------------
# Change locale to the given one in parameter
# ------------------------------------------------------------------------------
setlocale()
{
local loc=$1
[[ -z $loc ]] && disp E "No locale specified." && return 1
locale_check "$loc" || return 1
export LANG=$loc
export LC_MESSAGES=$loc
export LC_TIME=$loc
export LC_NUMERIC=$loc
export LC_MONETARY=$loc
export LC_COLLATE=$loc
export LC_CTYPE=$loc
disp I "Locale set to $loc."
}
export -f setlocale
# ------------------------------------------------------------------------------
# Special case : change locale to C standard
# ------------------------------------------------------------------------------
setc()
{
# Locale definitions
export LC_ALL=C
disp I "Locale changed to standard C (POSIX)."
}
export -f setc
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Change locale to French # Change locale to French
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
setfr() setfr()
{ {
# Set fr locale definitions # Set fr locale definitions
export LANG=fr_FR.UTF-8 setlocale "fr_FR.UTF-8"
export LC_MESSAGES=fr_FR.UTF-8
export LC_ALL=fr_FR.UTF-8
} }
export -f setfr export -f setfr
# ------------------------------------------------------------------------------
# Change locale to C standard
# ------------------------------------------------------------------------------
setc ()
{
# Locale definitions
export LANG=C
export LC_MESSAGES=C
export LC_ALL=C
}
export -f setc
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Change locale to US (needed by Steam) # Change locale to US (needed by Steam)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
setus() setus()
{ {
# Locale definitions setlocale "en_US.UTF-8"
export LANG=en_US.UTF-8
export LC_MESSAGES=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.
@@ -40,6 +41,7 @@ isipv4 ()
{ {
# Set up local variables # Set up local variables
local ip=$1 local ip=$1
[[ -z $ip ]] && return 1
# Start with a regex format test # Start with a regex format test
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
@@ -47,8 +49,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,7 +64,6 @@ isipv4 ()
} }
export -f isipv4 export -f isipv4
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Determine if parameter is a valid IPv4 address # Determine if parameter is a valid IPv4 address
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -82,3 +83,25 @@ isipv6 ()
return 1 return 1
} }
export -f isipv6 export -f isipv6
# ------------------------------------------------------------------------------
# Encode a string so it can be used as a URL parameter
# ------------------------------------------------------------------------------
urlencode() {
local LANG=C
local str="$*"
local length="${#str}"
for (( i = 0; i < length; i++ )); do
local c="${str:i:1}"
case "$c" in
[a-zA-Z0-9.~_-]) printf "$c" ;;
' ') printf '+' ;;
*) printf '%%%02X' "'$c" #| cut -d' ' -f2 ;;
esac
done
}
export -f urlencode
# ------------------------------------------------------------------------------
# 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.
@@ -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.
@@ -38,10 +39,42 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
ppg() ppg()
{ {
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
# ------------------------------------------------------------------------------
ppu()
{
if [[ -z "$1" ]]; then
disp E "Usage: ppu <username>"
return 1
fi
# -u lists processes for a specific user
# -o provides a clean, standard output format
ps -u "$1" -o pid,user,%cpu,%mem,start,time,command
}
export -f ppu
# ------------------------------------------------------------------------------
# List processes by exact command name (no path/parameters)
# ------------------------------------------------------------------------------
ppn()
{
if [[ -z "$1" ]]; then
disp E "Usage: ppn <command_name>"
return 1
fi
# -e: select all processes
# -o: specify custom output columns (PID and Command name)
# grep -w: ensures exact word matching so 'bash' doesn't match 'dbash'
ps -eo pid,comm | grep -w "$1"
}
export -f ppn
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Get PID list of the given process name # Get PID list of the given process name
@@ -62,14 +95,33 @@ gpid ()
} }
export -f gpid export -f gpid
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Kill all processes owned by the given users # Kill all processes owned by the given users (kill user)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
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 (kill tree)
# ------------------------------------------------------------------------------
kt()
{
[[ -z $1 ]] && echo -e "Usage:\n\tkt <pid> [kill_options]"
local parent_pid="$1"
shift
children_pids=$(pgrep -P "$parent_pid")
for pid in $children_pids; do
kt "$pid" "$@"
done
kill "$@" "$parent_pid"
}
# ------------------------------------------------------------------------------
# EOF

View File

@@ -38,7 +38,7 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function timer_now function timer_now
{ {
date +%s%N date +%s%N 2>/dev/null || date +%s
} }
function timer_start function timer_start
@@ -78,19 +78,19 @@ function timer_stop
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
set_prompt() set_prompt()
{ {
Last_Command=$? # Must come first! local Last_Command=$? # Must come first!
Blue='\[\e[0;34m\]' local Blue='\[\e[0;34m\]'
White='\[\e[01;37m\]' local White='\[\e[01;37m\]'
Yellow='\[\e[01;93m\]' local Yellow='\[\e[01;93m\]'
Red='\[\e[01;31m\]' local Red='\[\e[01;31m\]'
Green='\[\e[01;32m\]' local Green='\[\e[01;32m\]'
OnGrey='\[\e[47m\]' local OnGrey='\[\e[47m\]'
OnRed='\[\e[41m\]' local OnRed='\[\e[41m\]'
OnBlue='\[\e[44m\]' local OnBlue='\[\e[44m\]'
ICyan='\[\e[0;96m\]' local ICyan='\[\e[0;96m\]'
Default='\[\e[00m\]' local Default='\[\e[00m\]'
FancyX='\342\234\227' local FancyX='\342\234\227'
Checkmark='\342\234\223' local Checkmark='\342\234\223'
# Begin with time # Begin with time
PS1="\[\e[s$Blue$OnGrey [ \t ] $OnBlue" PS1="\[\e[s$Blue$OnGrey [ \t ] $OnBlue"
@@ -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.
@@ -44,6 +45,7 @@ genpwd()
local occurs=2 # Bug, if set to 1, seems to be ignored local occurs=2 # Bug, if set to 1, seems to be ignored
local symb=1 maj=1 min=1 numb=1 local symb=1 maj=1 min=1 numb=1
local nbpwd=1 local nbpwd=1
local extcar
for opt in $@; do for opt in $@; do
case $opt in case $opt in
@@ -88,7 +90,7 @@ genpwd()
min=0 min=0
;; ;;
"-e"?* | "--extracars"?*) "-e"?* | "--extracars"?*)
local extcar=$(echo "$opt" | cut -f 2- -d '=') 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 '=')
@@ -113,19 +115,18 @@ genpwd()
disp E "Unknow parameter ${opt}." disp E "Unknow parameter ${opt}."
return 1 return 1
else else
local nbpwd=$opt nbpwd=$opt
fi fi
;; ;;
esac esac
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
@@ -184,3 +185,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.
@@ -38,23 +39,87 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
rain() rain()
{ {
show_usage() {
echo -e "Usage: rain [OPTIONS]"
echo -e ""
echo -e "Options:"
echo -e " -s, --speed NUM Set the drop delay in seconds (default: 0.050)."
echo -e " Lower values = faster rain."
echo -e " -c, --color COLOR Set the color theme (default: white)."
echo -e " -h, --help Display this help message and exit."
echo -e ""
echo -e "Available Colors:"
echo -e " \e[32mgreen\e[0m : The classic Matrix digital rain"
echo -e " \e[34mblue\e[0m : Deep ocean blue gradients"
echo -e " \e[31mred\e[0m : Crimson/Blood rain"
echo -e " \e[33myellow\e[0m : Amber and gold tones"
echo -e " \e[36mcyan\e[0m : Electric cyan/turquoise"
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 base_color="white" # default color scheme, can be overridden by --color
# Analyse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
-s|--speed)
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
step_duration="$2"; shift
else
echo -e "\e[31mError: --speed requires a numeric value.\e[0m"
show_usage && return 1
fi
;;
-c|--color)
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
base_color="$2"; shift
else
echo -e "\e[31mError: --color requires a color name.\e[0m"
show_usage && return 1
fi
;;
-h|--help)
show_usage && return 0
;;
*)
echo -e "\e[31mUnknown option: $1\e[0m"
show_usage && return 1
;;
esac
shift
done
# Define colors (256-colors gradients)
local rain_colors=()
case $base_color in
green) # Matrix style green
for i in {22..28} {34..40} {46..48}; do rain_colors+=("\e[38;5;${i}m"); done ;;
blue) # Deep ocean blues
for i in {17..21} {27..33} {39..45}; do rain_colors+=("\e[38;5;${i}m"); done ;;
red) # Crimson / blood red
for i in {52..52} {88..88} {124..124} {160..160} {196..201}; do rain_colors+=("\e[38;5;${i}m"); done ;;
yellow) # Amber / gold
for i in {58..58} {100..100} {142..142} {184..184} {226..229}; do rain_colors+=("\e[38;5;${i}m"); done ;;
cyan) # Electric cyan / turquoise
for i in {30..31} {37..38} {44..45} {50..51}; do rain_colors+=("\e[38;5;${i}m"); done ;;
*) # Greyscale / white (original style)
rain_colors=("\e[37m" "\e[37;1m")
for i in {244..255}; do rain_colors+=("\e[38;5;${i}m"); done ;;
esac
local exit_st=0 local exit_st=0
local rain_cars=("|" "│" "┃" "┆" "┇" "┊" "┋" "╽" "╿") local rain_cars=("|" "│" "┃" "┆" "┇" "┊" "┋" "╽" "╿")
local rain_colors=("\e[37m" "\e[37;1m")
# More from 256 color mode
for i in {244..255}; do
rain_colors=( "${rain_colors[@]}" "\e[38;5;${i}m" )
done
local rain_tab=${#rain_cars[@]} local rain_tab=${#rain_cars[@]}
local rain_color_tab=${#rain_colors[@]} local rain_color_tab=${#rain_colors[@]}
local num_rain_metadata=5 local num_rain_metadata=5
local term_height=$(tput lines) local term_height=$(tput lines)
local term_width=$(tput cols) local term_width=$(tput cols)
local step_duration=0.050
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)
@@ -152,3 +217,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.
@@ -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
@@ -58,11 +59,15 @@ rmhost ()
unset v4 v6 unset v4 v6
if [[ ! $ip && $hst ]]; then if [[ ! $ip && $hst ]]; then
ip=$(host $hst | grep "has address" | awk '{print $NF}') if ! ip=$(host "$hst" 2>/dev/null | awk '/has address/ {print $NF; exit}'); then
[[ ! $? ]] &&
disp E "Impossible to extract IP from hostname." && disp E "Impossible to extract IP from hostname." &&
return 1 return 1
fi fi
[[ -z $ip ]] && {
disp E "Impossible to extract IP from hostname."
return 1;
}
fi
if [[ $hst ]]; then if [[ $hst ]]; then
disp I "Removing host $hst from ssh known_host..." disp I "Removing host $hst from ssh known_host..."
@@ -77,7 +82,6 @@ rmhost ()
} }
export -f rmhost export -f rmhost
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Login root via SSH on the given machine # Login root via SSH on the given machine
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -94,12 +98,19 @@ ssr ()
esac esac
done done
command -v ssh >/dev/null 2>&1 || {
disp E "ssh is not installed."
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

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.
@@ -33,7 +34,9 @@
# * OF SUCH DAMAGE. # * OF SUCH DAMAGE.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
export UPDT_URL="https://git.geoffray-levasseur.org/fatalerrors/profile" export BASE_URL="https://git.geoffray-levasseur.org/fatalerrors/profile"
export UPDT_URL="$BASE_URL/raw/branch/master"
export ARCH_URL="$BASE_URL/archive/master.tar.gz"
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Check for profile updates # Check for profile updates
@@ -44,21 +47,22 @@ check_updates()
# Quiet mode is mostly used internally when profile_upgrade is called # Quiet mode is mostly used internally when profile_upgrade is called
quiet=1 quiet=1
fi fi
disp I "Checking for updates..." [[ -n $quiet ]] && disp I "Checking for updates..."
local vfile="/tmp/version" local vfile="/tmp/version"
wget "$UPDT_URL/version" -O $vfile 2&>1 /dev/null || { 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!"
return 5 return 5
} }
if [[ -s /tmp/version ]]; then
local lastver=$(cat /tmp/version) if [[ -s $vfile ]]; then
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 ]] && disp I "You should upgrade to last version when possible."
result=0
else
disp I "Your version is up-to-date."
result=1 result=1
else
[[ -n $quiet ]] && disp I "Your version is up-to-date."
result=0
fi fi
rm -f $vfile rm -f $vfile
else else
@@ -73,28 +77,57 @@ check_updates()
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
profile_upgrade() profile_upgrade()
{ {
if [[ $(check_updates -q) -eq 0 ]]; then if check_updates -q; then
disp "No update available."
return 0
fi
if [[ -s $MYPATH/profile.sh ]]; then if [[ -s $MYPATH/profile.sh ]]; then
disp E "Installation path detection failed, cannot upgrade automatically." disp E "Installation path detection failed, cannot upgrade automatically."
return 1 return 1
fi fi
if [[ -d $MYPATH/.git ]]; then if [[ -d $MYPATH/.git ]]; then
disp I "Git installation detected, applying git pull." disp I "Git installation detected, applying git pull."
local curdir=$(pwd) local curdir=$(pwd)
cd $MYPATH cd $MYPATH
git pull git pull || {
if [[ $? -ne 0 ]]; then
disp E "Git pull failed, upgrade not applyed." disp E "Git pull failed, upgrade not applyed."
else cd "$curdir"
return 2
}
disp I "Successfully upgraded using git." disp I "Successfully upgraded using git."
disp I "You should now logout and login again to enjoy new profile." cd "$curdir"
cd $curdir
fi
else else
disp I "Applying traditionnal upgrade..." disp I "No Git detected. Downloading and applying upgrade from archive..."
# TODO local tmpdir="/tmp/profile_upg.$$"
fi mkdir -p "$tmpdir" || {
fi disp E "Failed to create temporary directory."
return 4
} }
local archive="$tmpdir/profile.tar.gz"
wget -q "$ARCH_URL" -O "$archive" || {
disp E "Failed to download archive."
rm -rf "$tmpdir"
return 5
}
tar -xzf "$archive" -C "$tmpdir" || {
disp E "Archive extraction failed."
rm -rf "$tmpdir"
return 6
}
disp I "Installing new version..."
cp -r "$tmpdir"/profile/* "$MYPATH"/ || {
disp E "Failed to copy new files to $MYPATH."
rm -rf "$tmpdir"
return 7
}
disp I "Upgrade complete. You should now logout and login again."
rm -rf "$tmpdir"
fi
}
# EOF # EOF

View File

@@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Begin profile # Begin profile
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
@@ -36,7 +36,7 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
if [[ ! $SHELL =~ bash|zsh ]]; then if [[ ! $SHELL =~ bash|zsh ]]; then
echo "That environmet script is designed to be used with bash or zsh being the shell." echo "That environment script is designed to be used with bash or zsh being the shell."
echo "Please consider using bash or zsh instead, or patch me ;)!" echo "Please consider using bash or zsh instead, or patch me ;)!"
return 1 return 1
fi fi
@@ -46,7 +46,7 @@ fi
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
pathremove() pathremove()
{ {
local ifs=':' local IFS=':'
local newpath local newpath
local dir local dir
local pathvar=${2:-PATH} local pathvar=${2:-PATH}
@@ -72,7 +72,6 @@ pathappend ()
export $pathvar="${!pathvar:+${!pathvar}:}$1" export $pathvar="${!pathvar:+${!pathvar}:}$1"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# ********************************** MAIN PROGRAM ****************************** # ********************************** MAIN PROGRAM ******************************
@@ -80,23 +79,23 @@ pathappend ()
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Store script's path (realpath -s resolve symlinks if profile.sh is a symlink) # Store script's path (realpath -s resolve symlinks if profile.sh is a symlink)
if [[ -z $PROFILE_PATH ]]; then if [[ -z "$PROFILE_PATH" ]]; then
export MYPATH=$(dirname $(realpath -s $0)) export MYPATH=$(dirname "$(realpath -s "$0")")
else else
export MYPATH=$PROFILE_PATH export MYPATH="$PROFILE_PATH"
fi fi
if [[ ! -e $MYPATH/profile.sh ]]; then if [[ ! -e "$MYPATH/profile.sh" ]]; then
echo "[ Warning ] Path detection failed, trying to use pwd..." echo "[ Warning ] Path detection failed, trying to use pwd..."
MYPATH=$(pwd) MYPATH=$(pwd)
if [[ ! -e $MYPATH/profile.sh ]]; then if [[ ! -e "$MYPATH/profile.sh" ]]; then
echo "[ Error ] Impossible to determine installation path, pretty much nothing will work." echo "[ Error ] Impossible to determine installation path, pretty much nothing will work."
fi fi
fi fi
if [[ ! -s $MYPATH/version ]]; then if [[ ! -s "$MYPATH/version" ]]; then
echo "[ Warning ] Impossible to determine running version of profile, your installation might be broken." echo "[ Warning ] Impossible to determine running version of profile, your installation might be broken."
fi fi
export PROFVERSION=$(cat $MYPATH/version) export PROFVERSION=$(cat "$MYPATH"/version)
# Build PATH environment variable # Build PATH environment variable
if [[ $EUID -eq 0 ]]; then if [[ $EUID -eq 0 ]]; then
@@ -148,7 +147,7 @@ done
# Interactive shell detection, two methods available each one of those might have different result # Interactive shell detection, two methods available each one of those might have different result
# depending on distribution # depending on distribution
#shopt -q login_shell && INTERACTIVE=1 #shopt -q login_shell && INTERACTIVE=1
[[ $- == *i* ]] && INTERACTIVE=1 [[ $- == *i* ]] && export INTERACTIVE=1
if [[ $INTERACTIVE ]]; then if [[ $INTERACTIVE ]]; then
# For compiling (as we often compile with LFS/0linux...) # For compiling (as we often compile with LFS/0linux...)
@@ -176,6 +175,7 @@ if [[ $INTERACTIVE ]]; then
alias du='du -ch' alias du='du -ch'
alias sdu='du -sk ./* | sort -n' alias sdu='du -sk ./* | sort -n'
alias hdu='du -hs ./* | sort -H'
# Define PS1 # Define PS1
trap 'timer_start' DEBUG trap 'timer_start' DEBUG
@@ -184,6 +184,7 @@ if [[ $INTERACTIVE ]]; then
# Set default language # Set default language
setfr setfr
showinfo showinfo
check_updates -q
disp I "Profile version $PROFVERSION chargé..." disp I "Profile version $PROFVERSION chargé..."
fi fi

View File

@@ -1 +1 @@
3.3.1 3.6.0