Compare commits
4 Commits
f5d59ec194
...
75e047d70e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75e047d70e | ||
|
|
742ec484a7 | ||
|
|
1b7262c0cd | ||
|
|
e387209c10 |
@@ -88,19 +88,23 @@ busy()
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# If a pattern was provided as a positional argument (e.g., 'busy "ff 00"'),
|
|
||||||
# it is captured here.
|
|
||||||
[[ -n "$1" ]] && pattern="$1"
|
|
||||||
|
|
||||||
# Convert milliseconds to seconds for 'sleep'
|
# Convert milliseconds to seconds for 'sleep'
|
||||||
local delay_s=$(awk "BEGIN { printf \"%.3f\", $delay_ms / 1000 }")
|
local delay_s=$(awk "BEGIN{
|
||||||
|
printf \"%.3f\", $delay_ms / 1000 }")
|
||||||
|
|
||||||
# Monitor /dev/urandom
|
# Monitor /dev/urandom
|
||||||
cat /dev/urandom | hexdump -C | grep --line-buffered "$pattern" | \
|
(
|
||||||
while read -r line; do
|
hexdump -C < /dev/urandom | grep -iF --line-buffered "$pattern" | \
|
||||||
echo "$line"
|
while read -r line; do
|
||||||
[[ $delay_ms -gt 0 ]] && sleep "$delay_s"
|
echo "$line"
|
||||||
done
|
[[ $delay_ms -gt 0 ]] && sleep "$delay_s"
|
||||||
|
done
|
||||||
|
) & local sub_pid=$!
|
||||||
|
|
||||||
|
IFS= read -r -n 1 -s _ </dev/tty
|
||||||
|
kill -- -"$sub_pid" 2>/dev/null || kill "$sub_pid" 2>/dev/null
|
||||||
|
wait "$sub_pid" 2>/dev/null
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -39,34 +39,40 @@
|
|||||||
# Usage: help
|
# Usage: help
|
||||||
help()
|
help()
|
||||||
{
|
{
|
||||||
printf "check_updates\tCheck for profile updates\n"
|
|
||||||
printf "clean\t\tErase backup files\n"
|
printf "clean\t\tErase backup files\n"
|
||||||
printf "dpkgs\t\tSearch for the given package in the installed ones\n"
|
printf "disp\t\tDisplay formatted info/warning/error/debug messages\n"
|
||||||
printf "findbig\t\tFind big files in the given (or current) directory\n"
|
printf "dwl\t\tDownload a URL to a local file\n"
|
||||||
printf "findempty\tFind empty files and directories in the given (or current) directory\n"
|
printf "expandlist\tExpand and quote item lists\n"
|
||||||
|
printf "file_stats\tDisplay file size statistics for a path\n"
|
||||||
|
printf "findbig\t\tFind biggest files in the given (or current) directory\n"
|
||||||
printf "finddead\tFind dead symbolic links in the given (or current) directory\n"
|
printf "finddead\tFind dead symbolic links in the given (or current) directory\n"
|
||||||
|
printf "findzero\tFind empty files in the given (or current) directory\n"
|
||||||
|
printf "genpwd\t\tGenerate secure passwords\n"
|
||||||
printf "gpid\t\tGive the list of PIDs for the given process name\n"
|
printf "gpid\t\tGive the list of PIDs for the given process name\n"
|
||||||
printf "isipv4\t\tTell if the given IPv4 is valid\n"
|
printf "isipv4\t\tTell if the given IPv4 is valid\n"
|
||||||
printf "isipv6\t\tTell if the given IPv6 is valid\n"
|
printf "isipv6\t\tTell if the given IPv6 is valid\n"
|
||||||
printf "ku\t\tKill process owned by users in parameter\n"
|
printf "ku\t\tKill process owned by users in parameter\n"
|
||||||
|
printf "matrix\t\tDisplay matrix-style digital rain\n"
|
||||||
printf "mcd\t\tCreate a directory and go inside\n"
|
printf "mcd\t\tCreate a directory and go inside\n"
|
||||||
printf "meteo\t\tDisplay curent weather forecast for the configured city\n"
|
printf "meteo\t\tDisplay current weather forecast for the configured city\n"
|
||||||
|
printf "myextip\tDisplay current external/public IP\n"
|
||||||
|
printf "pkgs\t\tSearch for the given package in installed ones\n"
|
||||||
printf "ppg\t\tDisplay process matching the given parameter\n"
|
printf "ppg\t\tDisplay process matching the given parameter\n"
|
||||||
printf "ppn\t\tDisplay process matching the exact process name given in parameter\n"
|
printf "ppn\t\tDisplay process matching the exact process name given in parameter\n"
|
||||||
printf "ppu\t\tDisplay processes owned by the given user\n"
|
printf "ppu\t\tDisplay processes owned by the given user\n"
|
||||||
printf "profile_update\tUpdate profile to the latest version\n"
|
|
||||||
printf "rain\t\tLet the rain fall\n"
|
printf "rain\t\tLet the rain fall\n"
|
||||||
printf "rmhost\t\tRemove host (IP and/or DNS name) for current known_host\n"
|
printf "rmhost\t\tRemove host (IP and/or DNS name) from current known_hosts\n"
|
||||||
printf "rmspc\t\tRemove spaces from all the files in working directory\n"
|
printf "rmspc\t\tRemove spaces from file and directory names\n"
|
||||||
printf "setlocale\tSet console language to the current locale\n"
|
printf "setlocale\tSet console language to the current locale\n"
|
||||||
printf " * setc\tSet console language to C\n"
|
printf " * setc\tSet console language to C\n"
|
||||||
printf " * setfr\tSet console language to French\n"
|
printf " * setfr\tSet console language to French\n"
|
||||||
printf " * setus\tSet console language to US English\n"
|
printf " * setus\tSet console language to US English\n"
|
||||||
printf "settrace\tActivate/deactivate call trace for script debugging\n"
|
printf "settrace\tActivate/deactivate call trace for script debugging\n"
|
||||||
printf "showinfo\tShow the welcoming baner with basic system information\n"
|
printf "showinfo\tShow welcome banner with basic system information\n"
|
||||||
printf "ssr\t\tDo a root login to the given address\n"
|
printf "ssr\t\tDo a root login to the given address\n"
|
||||||
printf "taz\t\tCompress smartly the given files or directory\n"
|
printf "taz\t\tCompress smartly the given files or directory\n"
|
||||||
printf "utaz\t\tUncompress all zip files in the given (or current) directory\n"
|
printf "urlencode\tURL-encode the given text\n"
|
||||||
|
printf "utaz\t\tUncompress archives in the given (or current) directory\n"
|
||||||
printf "ver\t\tDisplay version of your copy of profile\n\n"
|
printf "ver\t\tDisplay version of your copy of profile\n\n"
|
||||||
|
|
||||||
printf "\nPlease use <command> --help to obtain usage details.\n"
|
printf "\nPlease use <command> --help to obtain usage details.\n"
|
||||||
|
|||||||
@@ -109,27 +109,73 @@ export -f setc
|
|||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Change locale to French
|
# Build dynamic locale shortcuts from SET_LOCALE
|
||||||
# Usage: setfr
|
# Expected format:
|
||||||
setfr()
|
# SET_LOCALE="fr:fr_FR.UTF-8,us:en_US.UTF-8,es:es_ES.UTF-8"
|
||||||
|
# This creates functions:
|
||||||
|
# setfr, setus, setes, ...
|
||||||
|
build_locale_shortcuts()
|
||||||
{
|
{
|
||||||
# Set fr locale definitions
|
local cfg="${SET_LOCALE:-}"
|
||||||
setlocale "fr_FR.UTF-8"
|
local item="" alias="" loc="" fname=""
|
||||||
|
local -a locale_items=()
|
||||||
|
|
||||||
|
[[ -z "$cfg" ]] && return 0
|
||||||
|
|
||||||
|
IFS=',' read -r -a locale_items <<< "$cfg"
|
||||||
|
for item in "${locale_items[@]}"; do
|
||||||
|
# Trim surrounding spaces
|
||||||
|
item="${item#"${item%%[![:space:]]*}"}"
|
||||||
|
item="${item%"${item##*[![:space:]]}"}"
|
||||||
|
|
||||||
|
[[ -z "$item" ]] && continue
|
||||||
|
|
||||||
|
if [[ "$item" != *:* ]]; then
|
||||||
|
disp W "Ignoring invalid SET_LOCALE entry: '$item' (expected alias:locale)."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
alias="${item%%:*}"
|
||||||
|
loc="${item#*:}"
|
||||||
|
|
||||||
|
# Trim alias/locale spaces
|
||||||
|
alias="${alias#"${alias%%[![:space:]]*}"}"
|
||||||
|
alias="${alias%"${alias##*[![:space:]]}"}"
|
||||||
|
loc="${loc#"${loc%%[![:space:]]*}"}"
|
||||||
|
loc="${loc%"${loc##*[![:space:]]}"}"
|
||||||
|
|
||||||
|
# Validate alias for safe function names
|
||||||
|
if [[ ! "$alias" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then
|
||||||
|
disp W "Ignoring unsafe locale alias '$alias' in SET_LOCALE."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -z "$loc" ]] && {
|
||||||
|
disp W "Ignoring empty locale for alias '$alias' in SET_LOCALE."
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fname="set${alias}"
|
||||||
|
|
||||||
|
# Optional collision warning
|
||||||
|
if declare -F "$fname" >/dev/null 2>&1; then
|
||||||
|
disp W "Overriding existing function '$fname'."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build function dynamically
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
eval "${fname}() { setlocale \"$loc\"; }"
|
||||||
|
# shellcheck disable=SC2163
|
||||||
|
export -f "$fname"
|
||||||
|
done
|
||||||
|
|
||||||
|
unset cfg item alias loc fname locale_items
|
||||||
}
|
}
|
||||||
export -f setfr
|
export -f build_locale_shortcuts
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# Change locale to US (needed by Steam)
|
|
||||||
# Usage: setus
|
|
||||||
setus()
|
|
||||||
{
|
|
||||||
setlocale "en_US.UTF-8"
|
|
||||||
}
|
|
||||||
export -f setus
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
load_conf lang
|
||||||
|
build_locale_shortcut
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# EOF
|
# EOF
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ check_updates()
|
|||||||
unset lastver vfile
|
unset lastver vfile
|
||||||
return $result
|
return $result
|
||||||
}
|
}
|
||||||
|
export -f check_updates
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
@@ -141,15 +142,17 @@ profile_upgrade()
|
|||||||
|
|
||||||
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)
|
pushd "$MYPATH" || {
|
||||||
cd $MYPATH
|
disp E "Failed to change directory to $MYPATH."
|
||||||
|
return 3
|
||||||
|
}
|
||||||
git pull || {
|
git pull || {
|
||||||
disp E "Git pull failed, upgrade not applyed."
|
disp E "Git pull failed, upgrade not applyed."
|
||||||
cd "$curdir"
|
popd
|
||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
disp I "Successfully upgraded using git."
|
disp I "Successfully upgraded using git."
|
||||||
cd "$curdir"
|
popd
|
||||||
else
|
else
|
||||||
disp I "No Git detected. Downloading and applying upgrade from archive..."
|
disp I "No Git detected. Downloading and applying upgrade from archive..."
|
||||||
local tmpdir="/tmp/profile_upg.$$"
|
local tmpdir="/tmp/profile_upg.$$"
|
||||||
@@ -182,6 +185,7 @@ profile_upgrade()
|
|||||||
rm -rf "$tmpdir"
|
rm -rf "$tmpdir"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
export -f profile_upgrade
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user