4 Commits

Author SHA1 Message Date
fatalerrors
b79103a0a6 bugfix 2026-04-15 08:13:52 +02:00
fatalerrors
e5bafe1721 increased reliability 2026-04-15 08:13:17 +02:00
fatalerrors
322d03ed4c hardening 2026-04-15 08:11:58 +02:00
fatalerrors
60a159c3ea code quality 2026-04-08 18:46:30 +02:00
4 changed files with 104 additions and 34 deletions

View File

@@ -93,7 +93,7 @@ utaz()
unarj e "$1" "$2/" >/dev/null 2>&1
}
_unlza()
_unlha()
{
# lha typically extracts into the current directory
# We ensure it hits the target directory
@@ -546,7 +546,7 @@ taz()
;;
-[1-9])
compression="${1#-}"
complevel="${1#-}"
shift
;;
--)

View File

@@ -148,7 +148,8 @@ export -f isipv6
# ------------------------------------------------------------------------------
# Encode a string so it can be used as a URL parameter
# Usage: urlencode <string>
urlencode() {
urlencode()
{
local LANG=C
local str="$*"
local length="${#str}"
@@ -177,7 +178,8 @@ export -f urlencode
# -c, --coord Display only the coordinates (latitude, longitude)
# -a, --as Display only the Autonomous System (AS) information
# -R, --raw Display raw JSON response
myextip() {
myextip()
{
local show_ip=false show_isp=false show_loc=false
local show_coord=false show_as=false show_raw=false
local all=true
@@ -236,7 +238,7 @@ myextip() {
# Fetch data. Allow overriding endpoint via env var MYEXTIP_URL
local MYEXTIP_URL
MYEXTIP_URL=${MYEXTIP_URL:-http://ip-api.com/json/}
MYEXTIP_URL=${MYEXTIP_URL:-https://ip-api.com/json/}
local response
if ! response=$(dwl "$MYEXTIP_URL"); then

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------
# Copyright (c) 2013-2026 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.
#
# * Redistribution and use in source and binary forms,
@@ -50,7 +50,27 @@ ppg()
disp E "Usage: ppg <string>"
return 1
fi
ps -edf | grep "$@" | grep -v "grep $@"
local pattern="$*"
if command -v pgrep >/dev/null 2>&1; then
pgrep -af -- "$pattern"
return $?
fi
ps -ef | awk -v pattern="$pattern" '
NR == 1 {
print
next
}
index($0, pattern) {
print
matched = 1
}
END {
exit matched ? 0 : 1
}
'
}
export -f ppg
# ------------------------------------------------------------------------------
@@ -123,17 +143,42 @@ gpid()
disp E "Usage: gpid <process_name [process_name2 ...]>"
return 1
fi
[[ $UID -eq 0 ]] && local psopt="-A"
[[ $# -eq 1 ]] && local single=1
for pid in $@; do
local result=$(ps $psopt | grep $pid | awk '{print $1}' | sed "s/\n/ /")
if [[ $single ]]; then
[[ $result ]] && echo "${result//$'\n'/ }"
local single=0
local found=0
local proc_name result
[[ $# -eq 1 ]] && single=1
for proc_name in "$@"; do
result=""
if command -v pgrep >/dev/null 2>&1; then
result=$(pgrep -d ' ' -x -- "$proc_name")
else
[[ $result ]] && echo "$pid: ${result//$'\n'/ }"
result=$(ps -eo pid=,comm= | awk -v proc="$proc_name" '
$2 == proc {
if (out != "") {
out = out " "
}
out = out $1
}
END {
print out
}
')
fi
[[ -z "$result" ]] && continue
found=1
if (( single )); then
echo "$result"
else
echo "$proc_name: $result"
fi
done
[[ $result ]] || return 1
(( found )) || return 1
}
export -f gpid
# ------------------------------------------------------------------------------
@@ -155,8 +200,14 @@ ku()
disp E "Usage: ku <username1 [username2 ...]>"
return 1
fi
for u in $@; do
killall -u "$u"
local users="$@"
for u in $users; do
if ! id "$u" >/dev/null 2>&1; then
disp E "User '$u' does not exist."
return 1
else
killall -u "$u"
fi
done
}
export -f ku
@@ -187,14 +238,16 @@ kt()
return 1
fi
children_pids=$(pgrep -P "$parent_pid")
local children_pids=$(pgrep -P "$parent_pid")
for pid in $children_pids; do
kt "$pid" "$@" || break
done
kill "$@" "$parent_pid"
}
export -f kt
# ------------------------------------------------------------------------------
# EOF

View File

@@ -52,30 +52,42 @@ fi
# path* : private functions for PATH variable management
pathremove()
{
[[ -z "$1" ]] && return 0
local IFS=':'
local newpath
local dir
local pathvar=${2:-PATH}
local newpath dir
local pathvar="${2:-PATH}"
[[ "$pathvar" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] || {
printf "pathremove: unsafe variable name '%s'\n" "$pathvar" >&2
return 1
}
for dir in ${!pathvar}; do
if [ "$dir" != "$1" ]; then
newpath=${newpath:+$newpath:}$dir
fi
[[ "$dir" != "$1" ]] && newpath="${newpath:+$newpath:}$dir"
done
export $pathvar="$newpath"
export "$pathvar=$newpath"
}
pathprepend()
{
pathremove $1 $2
local pathvar=${2:-PATH}
export $pathvar="$1${!pathvar:+:${!pathvar}}"
[[ -z "$1" ]] && return 0
local pathvar="${2:-PATH}"
[[ "$pathvar" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] || {
printf "pathprepend: unsafe variable name '%s'\n" "$pathvar" >&2
return 1
}
pathremove "$1" "$pathvar"
export "$pathvar=$1${!pathvar:+:${!pathvar}}"
}
pathappend()
{
pathremove $1 $2
local pathvar=${2:-PATH}
export $pathvar="${!pathvar:+${!pathvar}:}$1"
[[ -z "$1" ]] && return 0
local pathvar="${2:-PATH}"
[[ "$pathvar" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] || {
printf "pathappend: unsafe variable name '%s'\n" "$pathvar" >&2
return 1
}
pathremove "$1" "$pathvar"
export "$pathvar=${!pathvar:+${!pathvar}:}$1"
}
# ------------------------------------------------------------------------------
@@ -223,11 +235,14 @@ load_conf system # Load Bash system behavior configuration (history, pager, etc
load_conf general # General purpose configuration (compilation flags, etc.)
# Load module scripts
for script in $MYPATH/profile.d/*.sh; do
if [[ -r $script ]]; then
. $script
shopt -s nullglob
for script in "$MYPATH/profile.d/"*.sh; do
if [[ -f "$script" && -r "$script" ]]; then
# shellcheck source=/dev/null
. "$script" || printf "[ Warning ] Failed to source module: %s\n" "$script" >&2
fi
done
shopt -u nullglob
# Interactive shell detection, two methods available each one of those might have different result
# depending on distribution