Compare commits
16 Commits
bef205ae84
...
9b2c764181
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b2c764181 | ||
|
|
3d5a5e7718 | ||
|
|
47e89b3b09 | ||
|
|
f0f80e2924 | ||
|
|
b08e457146 | ||
|
|
56e34bc346 | ||
|
|
e9e9993dfc | ||
|
|
ff4c6702b7 | ||
|
|
87dea45295 | ||
|
|
0abf481cf6 | ||
|
|
a75299f7b4 | ||
|
|
eeb87c5bfc | ||
|
|
4879b418db | ||
|
|
f944271488 | ||
|
|
4be2e5ea87 | ||
|
|
9d528a6491 |
@@ -35,7 +35,7 @@
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Smartly uncompress archives (zip only)
|
# Smartly uncompress archives (zip only for now)
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
utaz()
|
utaz()
|
||||||
{
|
{
|
||||||
@@ -81,28 +81,32 @@ utaz()
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ $createdir && $nodir ]] && disp E "The --create-dir and --no-dir options are mutually exclusive."
|
[[ $createdir && $nodir ]] && \
|
||||||
|
disp E "The --create-dir and --no-dir options are mutually exclusive."
|
||||||
|
|
||||||
[[ ! $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 ]] &&
|
shopt -s nullglob
|
||||||
disp W "$zitem contains no supported archive file, skipping." &&
|
local zips=("$zitem"/*.zip)
|
||||||
|
shopt -u nullglob
|
||||||
|
[[ ${#zips[@]} -eq 0 ]] && \
|
||||||
|
disp W "$zitem contains no supported archive file, skipping." && \
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for f in $zitem/*.zip; do
|
for f in "$zitem"/*.zip; do
|
||||||
disp I "Processing archive $zitem/$f... "
|
disp I "Processing archive $f... "
|
||||||
local dir=${f::-4}
|
local dir=${f::-4}
|
||||||
|
|
||||||
mkdir -p $dir
|
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
|
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."
|
||||||
;;
|
;;
|
||||||
|
|
||||||
1)
|
1)
|
||||||
@@ -110,7 +114,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
|
||||||
@@ -118,7 +122,7 @@ utaz()
|
|||||||
if [[ $createdir ]]; then
|
if [[ $createdir ]]; then
|
||||||
disp I "Archive extracted successfully in subdirectory."
|
disp I "Archive extracted successfully in subdirectory."
|
||||||
elif [[ $nodir ]]; then
|
elif [[ $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)
|
subdirs=$(find $dir -maxdepth 1 | wc -l)
|
||||||
@@ -167,7 +171,7 @@ 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." &&
|
||||||
@@ -195,7 +199,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"
|
||||||
@@ -219,7 +223,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"
|
||||||
@@ -291,7 +295,7 @@ taz()
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
"-q" | "--quiet")
|
"-q" | "--quiet")
|
||||||
QUIET=1
|
local quiet=1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-"*)
|
"-"*)
|
||||||
@@ -312,17 +316,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
|
||||||
@@ -337,7 +341,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."
|
||||||
@@ -349,15 +353,15 @@ 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
|
||||||
|
|
||||||
|
|||||||
@@ -41,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'
|
||||||
@@ -121,31 +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
|
# EOF
|
||||||
|
|||||||
@@ -211,5 +211,133 @@ rmspc()
|
|||||||
}
|
}
|
||||||
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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
}
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# EOF
|
# EOF
|
||||||
|
|||||||
@@ -39,12 +39,30 @@
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
busy()
|
busy()
|
||||||
{
|
{
|
||||||
if [[ -n $1 ]]; then
|
local pattern="ca fe"
|
||||||
local pattern="$@"
|
for arg in "$@"; do
|
||||||
else
|
case "$arg" in
|
||||||
local pattern="ca fe"
|
--delay=*)
|
||||||
fi
|
delay_ms="${arg#*=}"
|
||||||
cat /dev/urandom | hexdump -C | grep "$pattern"
|
if ! [[ $delay_ms =~ ^[0-9]+$ ]]; then
|
||||||
|
disp E "Invalid delay value, must be an integer (milliseconds)."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,9 @@
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
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
|
||||||
@@ -48,11 +51,13 @@ export -f ver
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
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
|
||||||
@@ -67,9 +72,13 @@ 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
|
||||||
|
figlet "$(hostname)"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "$(hostname -f)"
|
hostname -f
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
if command -v neofetch >/dev/null 2>&1; then
|
if command -v neofetch >/dev/null 2>&1; then
|
||||||
@@ -77,12 +86,13 @@ showinfo()
|
|||||||
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,39 +34,67 @@
|
|||||||
# * 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
|
||||||
|
|
||||||
|
|||||||
@@ -41,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
|
||||||
@@ -83,5 +84,24 @@ isipv6()
|
|||||||
}
|
}
|
||||||
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
|
# EOF
|
||||||
|
|||||||
@@ -80,12 +80,12 @@ kt()
|
|||||||
{
|
{
|
||||||
[[ -z $1 ]] && echo -e "Usage:\n\tkt <pid> [kill_options]"
|
[[ -z $1 ]] && echo -e "Usage:\n\tkt <pid> [kill_options]"
|
||||||
|
|
||||||
local parent_pid="$1" children_pids
|
local parent_pid="$1"
|
||||||
shift
|
shift
|
||||||
children_pids=$(pgrep -P "$parent_pid")
|
children_pids=$(pgrep -P "$parent_pid")
|
||||||
|
|
||||||
for pid in $children_pids; do
|
for pid in $children_pids; do
|
||||||
kill_tree "$pid" "$@"
|
kt "$pid" "$@"
|
||||||
done
|
done
|
||||||
kill "$@" "$parent_pid"
|
kill "$@" "$parent_pid"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -45,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
|
||||||
@@ -89,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 '=')
|
||||||
@@ -114,7 +115,7 @@ 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
|
||||||
|
|||||||
@@ -47,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
|
||||||
@@ -59,10 +59,14 @@ 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
|
||||||
|
[[ -z $ip ]] && {
|
||||||
|
disp E "Impossible to extract IP from hostname."
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $hst ]]; then
|
if [[ $hst ]]; then
|
||||||
@@ -94,13 +98,17 @@ 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
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,9 @@
|
|||||||
# * OF SUCH DAMAGE.
|
# * OF SUCH DAMAGE.
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
export UPDT_URL="https://git.geoffray-levasseur.org/fatalerrors/profile/raw/branch/master"
|
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
|
||||||
@@ -52,15 +54,15 @@ check_updates()
|
|||||||
return 5
|
return 5
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ -s /tmp/version ]]; then
|
if [[ -s $vfile ]]; then
|
||||||
local lastver=$(cat /tmp/version)
|
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
|
result=1
|
||||||
else
|
else
|
||||||
disp I "Your version is up-to-date."
|
disp I "Your version is up-to-date."
|
||||||
result=1
|
result=0
|
||||||
fi
|
fi
|
||||||
rm -f $vfile
|
rm -f $vfile
|
||||||
else
|
else
|
||||||
@@ -75,28 +77,59 @@ check_updates()
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
profile_upgrade()
|
profile_upgrade()
|
||||||
{
|
{
|
||||||
if [[ $(check_updates -q) -eq 0 ]]; then
|
check_updates -q
|
||||||
if [[ -s $MYPATH/profile.sh ]]; then
|
local need_update=$?
|
||||||
disp E "Installation path detection failed, cannot upgrade automatically."
|
[[ $need_update -ne 1 ]] && {
|
||||||
return 1
|
disp "No update available."
|
||||||
fi
|
return 0
|
||||||
if [[ -d $MYPATH/.git ]]; then
|
}
|
||||||
disp I "Git installation detected, applying git pull."
|
|
||||||
local curdir=$(pwd)
|
if [[ -s $MYPATH/profile.sh ]]; then
|
||||||
cd $MYPATH
|
disp E "Installation path detection failed, cannot upgrade automatically."
|
||||||
git pull
|
return 1
|
||||||
if [[ $? -ne 0 ]]; then
|
fi
|
||||||
disp E "Git pull failed, upgrade not applyed."
|
|
||||||
else
|
if [[ -d $MYPATH/.git ]]; then
|
||||||
disp I "Successfully upgraded using git."
|
disp I "Git installation detected, applying git pull."
|
||||||
disp I "You should now logout and login again to enjoy new profile."
|
local curdir=$(pwd)
|
||||||
cd $curdir
|
cd $MYPATH
|
||||||
fi
|
git pull || {
|
||||||
else
|
disp E "Git pull failed, upgrade not applyed."
|
||||||
disp I "Applying traditionnal upgrade..."
|
cd "$curdir"
|
||||||
# TODO
|
return 2
|
||||||
fi
|
}
|
||||||
|
disp I "Successfully upgraded using git."
|
||||||
|
cd "$curdir"
|
||||||
|
else
|
||||||
|
disp I "No Git detected. Downloading and applying upgrade from archive..."
|
||||||
|
local tmpdir="/tmp/profile_upg.$$"
|
||||||
|
mkdir -p "$tmpdir" || {
|
||||||
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# EOF
|
# EOF
|
||||||
|
|||||||
19
profile.sh
19
profile.sh
@@ -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}
|
||||||
@@ -79,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
|
||||||
@@ -175,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
|
||||||
|
|||||||
Reference in New Issue
Block a user