Compare commits
4 Commits
2ece711e1a
...
7ca0a6fb88
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ca0a6fb88 | ||
|
|
25df408e37 | ||
|
|
3eab1f98d5 | ||
|
|
6c895b509a |
@@ -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
|
- A bar style prompt with hour, execution time and exit code of the last
|
||||||
command;
|
command;
|
||||||
- clean: erase after confirmation any backup file, possibly recursively;
|
- 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
|
- expandlist: usefull in scripts, it expand any expression using wildcards into
|
||||||
the corresponding list of file and directories;
|
the corresponding list of file and directories;
|
||||||
- genpwd: generate one or more random secure password;
|
- genpwd: generate one or more random secure password;
|
||||||
|
|||||||
50
profile.conf
Executable file
50
profile.conf
Executable 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'
|
||||||
@@ -39,6 +39,27 @@
|
|||||||
# Usage: ver
|
# Usage: ver
|
||||||
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 ]] && \
|
[[ -z $PROFVERSION ]] && \
|
||||||
disp W "No version defined. Profile is probably badly installed." && \
|
disp W "No version defined. Profile is probably badly installed." && \
|
||||||
return 1
|
return 1
|
||||||
@@ -53,7 +74,28 @@ export -f ver
|
|||||||
# Usage: meteo [city1 city2 ...]
|
# Usage: meteo [city1 city2 ...]
|
||||||
meteo()
|
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")
|
[[ $# -eq 0 ]] && cities=("$DEFAULT_CITY")
|
||||||
|
|
||||||
for city in "${cities[@]}"; do
|
for city in "${cities[@]}"; do
|
||||||
@@ -71,7 +113,27 @@ export -f meteo
|
|||||||
# Usage: showinfo
|
# Usage: showinfo
|
||||||
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 command -v figlet >/dev/null 2>&1; then
|
||||||
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"
|
||||||
@@ -94,11 +156,11 @@ showinfo()
|
|||||||
if [[ -s /etc/os-release ]]; then
|
if [[ -s /etc/os-release ]]; then
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
echo "$NAME $VERSION"
|
printf "$NAME $VERSION\n"
|
||||||
else
|
else
|
||||||
cat /proc/version
|
cat /proc/version
|
||||||
fi
|
fi
|
||||||
echo "Uptime: $(uptime -p)"
|
printf "Uptime: $(uptime -p)\n"
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -106,4 +168,5 @@ export -f showinfo
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
load_conf info
|
||||||
# EOF
|
# EOF
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ check_updates()
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ $quiet != 1 ]] && disp I "Checking for updates..."
|
(( $quiet != 1 )) && disp I "Checking for updates..."
|
||||||
local vfile="/tmp/version"
|
local vfile="/tmp/version"
|
||||||
wget "$UPDT_URL/version" -O $vfile >/dev/null 2>&1 || {
|
wget "$UPDT_URL/version" -O $vfile >/dev/null 2>&1 || {
|
||||||
disp E "Can't download version file, impossible to proceed!"
|
disp E "Can't download version file, impossible to proceed!"
|
||||||
@@ -84,10 +84,10 @@ check_updates()
|
|||||||
local lastver=$(cat $vfile)
|
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 != 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
|
result=1
|
||||||
else
|
else
|
||||||
[[ $quiet != 1 ]] && disp I "Your version is up-to-date."
|
(( $quiet != 1 )) && disp I "Your version is up-to-date."
|
||||||
result=0
|
result=0
|
||||||
fi
|
fi
|
||||||
rm -f $vfile
|
rm -f $vfile
|
||||||
|
|||||||
155
profile.sh
155
profile.sh
@@ -43,7 +43,6 @@ fi
|
|||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# path* : private functions for PATH variable management
|
# path* : private functions for PATH variable management
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
pathremove()
|
pathremove()
|
||||||
{
|
{
|
||||||
local IFS=':'
|
local IFS=':'
|
||||||
@@ -71,6 +70,96 @@ pathappend()
|
|||||||
local pathvar=${2:-PATH}
|
local pathvar=${2:-PATH}
|
||||||
export $pathvar="${!pathvar:+${!pathvar}:}$1"
|
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
|
if [[ $EUID -eq 0 ]]; then
|
||||||
pathappend /sbin:/usr/sbin
|
pathappend /sbin:/usr/sbin
|
||||||
fi
|
fi
|
||||||
[[ -d /share/services/gestparc ]] && pathappend /share/services/gestparc
|
|
||||||
[[ -d ~/bin ]] && pathappend ~/bin
|
[[ -d ~/bin ]] && pathappend ~/bin
|
||||||
[[ -d ~/.local/bin ]] && pathappend ~/.local/bin
|
[[ -d ~/.local/bin ]] && pathappend ~/.local/bin
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# Parse and load general configuration
|
||||||
# Default values are set here and will be overloaded with config file if any
|
export PROFILE_CONF="$MYPATH/profile.conf"
|
||||||
# ------------------------------------------------------------------------------
|
parse_conf "$PROFILE_CONF"
|
||||||
|
load_conf system # Load Bash system behavior configuration (history, pager, etc.)
|
||||||
# Set bash history
|
load_conf general # General purpose configuration (compilation flags, etc.)
|
||||||
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
|
|
||||||
|
|
||||||
# Load module scripts
|
# Load module scripts
|
||||||
for script in $MYPATH/profile.d/*.sh; do
|
for script in $MYPATH/profile.d/*.sh; do
|
||||||
@@ -152,30 +214,7 @@ done
|
|||||||
if [[ $INTERACTIVE ]]; then
|
if [[ $INTERACTIVE ]]; then
|
||||||
# For compiling (as we often compile with LFS/0linux...)
|
# For compiling (as we often compile with LFS/0linux...)
|
||||||
#Aliases
|
#Aliases
|
||||||
alias ll='ls -laFh --color=auto'
|
load_alias aliases
|
||||||
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'
|
|
||||||
|
|
||||||
# Define PS1
|
# Define PS1
|
||||||
trap 'timer_start' DEBUG
|
trap 'timer_start' DEBUG
|
||||||
@@ -183,7 +222,7 @@ if [[ $INTERACTIVE ]]; then
|
|||||||
|
|
||||||
# Set default language
|
# Set default language
|
||||||
setfr
|
setfr
|
||||||
showinfo
|
showinfo && printf "\n"
|
||||||
check_updates -q
|
check_updates -q
|
||||||
disp I "Profile version $PROFVERSION chargé..."
|
disp I "Profile version $PROFVERSION chargé..."
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user