hardening
This commit is contained in:
47
profile.sh
47
profile.sh
@@ -52,30 +52,42 @@ fi
|
|||||||
# path* : private functions for PATH variable management
|
# path* : private functions for PATH variable management
|
||||||
pathremove()
|
pathremove()
|
||||||
{
|
{
|
||||||
|
[[ -z "$1" ]] && return 0
|
||||||
local IFS=':'
|
local IFS=':'
|
||||||
local newpath
|
local newpath dir
|
||||||
local dir
|
local pathvar="${2:-PATH}"
|
||||||
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
|
for dir in ${!pathvar}; do
|
||||||
if [ "$dir" != "$1" ]; then
|
[[ "$dir" != "$1" ]] && newpath="${newpath:+$newpath:}$dir"
|
||||||
newpath=${newpath:+$newpath:}$dir
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
export $pathvar="$newpath"
|
export "$pathvar=$newpath"
|
||||||
}
|
}
|
||||||
|
|
||||||
pathprepend()
|
pathprepend()
|
||||||
{
|
{
|
||||||
pathremove $1 $2
|
[[ -z "$1" ]] && return 0
|
||||||
local pathvar=${2:-PATH}
|
local pathvar="${2:-PATH}"
|
||||||
export $pathvar="$1${!pathvar:+:${!pathvar}}"
|
[[ "$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()
|
pathappend()
|
||||||
{
|
{
|
||||||
pathremove $1 $2
|
[[ -z "$1" ]] && return 0
|
||||||
local pathvar=${2:-PATH}
|
local pathvar="${2:-PATH}"
|
||||||
export $pathvar="${!pathvar:+${!pathvar}:}$1"
|
[[ "$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_conf general # General purpose configuration (compilation flags, etc.)
|
||||||
|
|
||||||
# Load module scripts
|
# Load module scripts
|
||||||
for script in $MYPATH/profile.d/*.sh; do
|
shopt -s nullglob
|
||||||
if [[ -r $script ]]; then
|
for script in "$MYPATH/profile.d/"*.sh; do
|
||||||
. $script
|
if [[ -f "$script" && -r "$script" ]]; then
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$script" || printf "[ Warning ] Failed to source module: %s\n" "$script" >&2
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
shopt -u nullglob
|
||||||
|
|
||||||
# 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
|
||||||
|
|||||||
Reference in New Issue
Block a user