4 Commits

Author SHA1 Message Date
fatalerrors
7ca0a6fb88 fixed README, version bump 2026-03-10 10:55:02 +01:00
fatalerrors
25df408e37 implemented ini style parsed configuration file 2026-03-10 10:53:31 +01:00
fatalerrors
3eab1f98d5 fix parameter detection 2026-03-10 10:52:45 +01:00
fatalerrors
6c895b509a pursue --help implementation 2026-03-10 10:52:17 +01:00
6 changed files with 219 additions and 67 deletions

View File

@@ -20,7 +20,7 @@ prompt. Here is a non-exhaustive list of what we have:
- A bar style prompt with hour, execution time and exit code of the last
command;
- clean: erase after confirmation any backup file, possibly recursively;
- dpkgs: search for the given pattern in the installed packages name;
- pkgs: search for the given pattern in the installed packages name;
- expandlist: usefull in scripts, it expand any expression using wildcards into
the corresponding list of file and directories;
- genpwd: generate one or more random secure password;

50
profile.conf Executable file
View File

@@ -0,0 +1,50 @@
[system]
# System section is used to set system-wide variables, such as PATH, environment variables, and other
# settings that affect the entire system. It is also a good place to set some global variables that can be used by the profile or its functions, such as the default editor and pager.
# Set bash history
HISTSIZE=50000
HISTIGNORE="&:[bf]g:exit"
# Set default pager
PAGER=less
# More colors
TERM=xterm-256color
[info]
# Default city for weather forcast
DEFAULT_CITY="Toulouse"
[general]
# General section allow to set any variable that can be used by the profile or its functions. It is
# also a good place to set some global variables that can be used by the profile or its functions, such as
# the compilation flags and make options.
# Set some compiling values
CFLAGS="-O2 -pipe -march=native"
MAKEFLAGS='-j12'
PKGSOURCES='/share/src/archives'
[aliases]
ll='ls -laFh --color=auto'
la='ls -Ah --color=auto'
l='ls -CF --color=auto'
ls='ls --color=auto'
grep='grep --color=auto'
egrep='egrep --color=auto'
fgrep='fgrep --color=auto'
qfind="find . -name "
mkck='make check'
mkin='make install'
mkdin='make DESTDIR=$PWD/dest-install install'
ssh='ssh -Y'
wget='wget -c' # resume mode by default
myip='curl ip.appspot.com'
# Human readable by default
df='df -H'
du='du -ch'
sdu='du -sk ./* | sort -n'
hdu='du -hs ./* | sort -H'

View File

@@ -39,6 +39,27 @@
# Usage: ver
ver()
{
local PARSED=$(getopt -o h --long help -n 'ver' -- "$@")
if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"ver --help\" to display usage."
return 1
fi
eval set -- "$PARSED"
case "$1" in
-h|--help)
printf "ver: Display the current profile version.\nUsage: ver\n"
return 0
;;
--)
shift
break
;;
*)
disp E "Invalid options, use \"ver --help\" to display usage."
return 1
;;
esac
[[ -z $PROFVERSION ]] && \
disp W "No version defined. Profile is probably badly installed." && \
return 1
@@ -53,7 +74,28 @@ export -f ver
# Usage: meteo [city1 city2 ...]
meteo()
{
local encoded cities=("$@")
local PARSED=$(getopt -o h --long help -n 'meteo' -- "$@")
if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"meteo --help\" to display usage."
return 1
fi
eval set -- "$PARSED"
case "$1" in
-h|--help)
printf "meteo: Fetch weather data.\nUsage: meteo [city1 city2 ...]\n"
return 0
;;
--)
shift
break
;;
*)
disp E "Invalid options, use \"meteo --help\" to display usage."
return 1
;;
esac
local cities=("$@")
[[ $# -eq 0 ]] && cities=("$DEFAULT_CITY")
for city in "${cities[@]}"; do
@@ -71,7 +113,27 @@ export -f meteo
# Usage: showinfo
showinfo()
{
echo -e "\n"
local PARSED=$(getopt -o h --long help -n 'showinfo' -- "$@")
if [[ $? -ne 0 ]]; then
disp E "Invalid options, use \"showinfo --help\" to display usage."
return 1
fi
eval set -- "$PARSED"
case "$1" in
-h|--help)
printf "showinfo: Display system information (hostname, kernel, uptime).\nUsage: showinfo\n"
return 0
;;
--)
shift
break
;;
*)
disp E "Invalid options, use \"showinfo --help\" to display usage."
return 1
;;
esac
printf "\n"
if command -v figlet >/dev/null 2>&1; then
if [[ -s /usr/share/figlet/ansi_shadow.flf ]]; then
local figopt="-f ansi_shadow"
@@ -94,11 +156,11 @@ showinfo()
if [[ -s /etc/os-release ]]; then
# shellcheck disable=SC1091
. /etc/os-release
echo "$NAME $VERSION"
printf "$NAME $VERSION\n"
else
cat /proc/version
fi
echo "Uptime: $(uptime -p)"
printf "Uptime: $(uptime -p)\n"
)
fi
}
@@ -106,4 +168,5 @@ export -f showinfo
# ------------------------------------------------------------------------------
load_conf info
# EOF

View File

@@ -73,7 +73,7 @@ check_updates()
esac
done
[[ $quiet != 1 ]] && disp I "Checking for updates..."
(( $quiet != 1 )) && disp I "Checking for updates..."
local vfile="/tmp/version"
wget "$UPDT_URL/version" -O $vfile >/dev/null 2>&1 || {
disp E "Can't download version file, impossible to proceed!"
@@ -84,10 +84,10 @@ check_updates()
local lastver=$(cat $vfile)
if [[ $lastver != $PROFVERSION ]]; then
disp I "You have version $PROFVERSION installed. Version $lastver is available."
[[ $quiet != 1 ]] && disp I "You should upgrade to last version when possible."
(( $quiet != 1 )) && disp I "You should upgrade to last version when possible."
result=1
else
[[ $quiet != 1 ]] && disp I "Your version is up-to-date."
(( $quiet != 1 )) && disp I "Your version is up-to-date."
result=0
fi
rm -f $vfile

View File

@@ -43,7 +43,6 @@ fi
# ------------------------------------------------------------------------------
# path* : private functions for PATH variable management
# ------------------------------------------------------------------------------
pathremove()
{
local IFS=':'
@@ -71,6 +70,96 @@ pathappend()
local pathvar=${2:-PATH}
export $pathvar="${!pathvar:+${!pathvar}:}$1"
}
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Configuration file parser
parse_conf()
{
local config_file="$1"
local current_section=""
[[ ! -f "$config_file" ]] && return 1
while IFS='=' read -r key value || [[ -n "$key" ]]; do
# Clean key and value (strip CR and whitespace)
key=$(printf '%s' "$key" | tr -d '\r' | xargs 2>/dev/null)
value=$(printf '%s' "$value" | tr -d '\r' | xargs 2>/dev/null)
# Skip comments and empty lines
[[ -z "$key" || "$key" =~ ^[#\;] ]] && continue
# Section Detection: [section_name]
if [[ "$key" =~ ^\[(.*)\]$ ]]; then
current_section="${BASH_REMATCH[1]}"
# Dynamically declare the associative array for this section
declare -g -A "CONF_$current_section"
continue
fi
# If we have a key/value pair and are inside a section
if [[ -n "$current_section" && -n "$value" ]]; then
# Strip quotes from value
value="${value%\"}"; value="${value#\"}"
value="${value%\'}"; value="${value#\'}"
# Store in the dynamic array: CONF_sectionname[key]=value
eval "CONF_${current_section}['$key']='$value'"
fi
done < "$config_file"
}
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Load command aliases from configuration
load_alias()
{
local section_name="CONF_$1"
# Check if the associative array for this section exists
if [[ "$(declare -p "$section_name" 2>/dev/null)" != "declare -A"* ]]; then
return 1
fi
# Reference the array keys
eval "local keys=\"\${!$section_name[@]}\""
for key in $keys; do
# Fetch the value for this specific key
eval "local cmd=\"\${$section_name[$key]}\""
# Portability check: only alias if the command exists
local base_cmd=$(echo "$cmd" | awk '{print $1}')
if command -v "$base_cmd" >/dev/null 2>&1; then
alias "$key"="$cmd"
fi
done
}
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Load configuration values as environment variables
load_conf()
{
local section_name="CONF_$1"
if [[ "$(declare -p "$section_name" 2>/dev/null)" != "declare -A"* ]]; then
return 1
fi
eval "local keys=\"\${!$section_name[@]}\""
for key in $keys; do
eval "local val=\"\${$section_name[$key]}\""
# Export as a standard shell variable
export "$key"="$val"
done
}
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
@@ -101,41 +190,14 @@ export PROFVERSION=$(cat "$MYPATH"/version)
if [[ $EUID -eq 0 ]]; then
pathappend /sbin:/usr/sbin
fi
[[ -d /share/services/gestparc ]] && pathappend /share/services/gestparc
[[ -d ~/bin ]] && pathappend ~/bin
[[ -d ~/.local/bin ]] && pathappend ~/.local/bin
# ------------------------------------------------------------------------------
# Default values are set here and will be overloaded with config file if any
# ------------------------------------------------------------------------------
# Set bash history
export HISTSIZE=50000
export HISTIGNORE="&:[bf]g:exit"
# Set default pager
export PAGER=less
# More colors
export TERM=xterm-256color
# Set some compiling values
export CFLAGS="-O2 -pipe -march=native"
export MAKEFLAGS='-j12'
export PKGSOURCES='/share/src/archives'
# Default city for weather forcast
export DEFAULT_CITY="Toulouse"
# ------------------------------------------------------------------------------
# Default values could be altered after this line
# ------------------------------------------------------------------------------
# Load global configuration
[[ -f $MYPATH/etc/profile.conf ]] && . $MYPATH/etc/profile.conf
# Load personal configuration
[[ -f ~/.profile.conf ]] && . ~/.profile.conf
# Parse and load general configuration
export PROFILE_CONF="$MYPATH/profile.conf"
parse_conf "$PROFILE_CONF"
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
@@ -152,30 +214,7 @@ done
if [[ $INTERACTIVE ]]; then
# For compiling (as we often compile with LFS/0linux...)
#Aliases
alias ll='ls -laFh --color=auto'
alias la='ls -Ah --color=auto'
alias l='ls -CF --color=auto'
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias qfind="find . -name "
alias mkck='make check'
alias mkin='make install'
alias mkdin='make DESTDIR=$PWD/dest-install install'
alias ssh='ssh -Y'
alias wget='wget -c' # resume mode by default
alias myip='curl ip.appspot.com'
# Human readable by default
alias df='df -H'
alias du='du -ch'
alias sdu='du -sk ./* | sort -n'
alias hdu='du -hs ./* | sort -H'
load_alias aliases
# Define PS1
trap 'timer_start' DEBUG
@@ -183,7 +222,7 @@ if [[ $INTERACTIVE ]]; then
# Set default language
setfr
showinfo
showinfo && printf "\n"
check_updates -q
disp I "Profile version $PROFVERSION chargé..."
fi

View File

@@ -1 +1 @@
3.90.1-4_alpha_1
3.95.1-4_beta_1