7 Commits

Author SHA1 Message Date
Geoffray Levasseur-Brandin
bef205ae84 bugfix, esthetic cleanup, better comments, version bump 2024-06-21 16:19:44 +02:00
Geoffray Levasseur
9e49e3e4d7 fixed url and redirection 2023-10-06 12:52:15 +02:00
94e7e79c76 Merge branch 'master' of https://git.geoffray-levasseur.org/fatalerrors/profile 2023-10-06 11:36:14 +02:00
55e88bd018 partial commit for profile upgrade 2023-10-06 11:35:40 +02:00
Geoffray Levasseur
18f1bc1543 fix bash/zsh test, some cosmetics 2023-10-06 11:22:10 +02:00
fatalerrors
0d7c7e9ab7 minor correction 2023-09-08 20:25:04 +02:00
root
64fecf16fb make profile path configurable as autodetection is too unprecise so far 2023-04-19 21:15:33 +00:00
18 changed files with 665 additions and 550 deletions

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -170,7 +171,7 @@ taz ()
local procopt="" local procopt=""
[[ $2 -gt 1 ]] && [[ $2 -gt 1 ]] &&
disp W "lzip doesn't support multithreading, falling back to 1 thread." && disp W "lzip doesn't support multithreading, falling back to 1 thread." &&
disp W "Consitder installing plzip to obtain multithreading abilities." disp W "Consider installing plzip to obtain multithreading abilities."
} }
[[ $4 ]] && local verb="-vv" [[ $4 ]] && local verb="-vv"
@@ -359,3 +360,6 @@ taz ()
unset QUIET unset QUIET
} }
export -f taz export -f taz
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -63,7 +64,6 @@ function error ()
return $errcode return $errcode
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Activate or deactivate error trapping to display backtrace # Activate or deactivate error trapping to display backtrace
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -105,3 +105,6 @@ settrace ()
unset status unset status
} }
export -f settrace export -f settrace
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -111,7 +112,6 @@ export On_IPurple='\e[0;105m'
export On_ICyan='\e[0;106m' export On_ICyan='\e[0;106m'
export On_IWhite='\e[0;107m' export On_IWhite='\e[0;107m'
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Display a message # Display a message
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -146,3 +146,6 @@ disp()
unset heads unset heads
} }
export -f disp export -f disp
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -47,7 +48,6 @@ expandlist()
echo $result echo $result
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Clean a directory or a tree from temporary or backup files # Clean a directory or a tree from temporary or backup files
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -100,7 +100,7 @@ clean ()
unset recursive force unset recursive force
for dir in $dirlist; do for dir in $dirlist; do
local dellist=$(find $dir $findopt -type f -name "*~" -o -name "#*#" \ local dellist=$(find "$dir" $findopt -type f -name "*~" -o -name "#*#" \
-o -name "*.bak" -o -name ".~*#") -o -name "*.bak" -o -name ".~*#")
for f in $dellist; do for f in $dellist; do
if [[ ! $outshell ]]; then if [[ ! $outshell ]]; then
@@ -114,7 +114,6 @@ clean ()
} }
export -f clean export -f clean
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Create a directory then goes inside # Create a directory then goes inside
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -125,11 +124,10 @@ mcd ()
disp E "Usage: mcd <directory>" disp E "Usage: mcd <directory>"
return 1 return 1
fi fi
mkdir -pv $1 && cd $1 mkdir -pv "$1" && cd "$1" || echo "Failed create or change directory."
} }
export -f mcd export -f mcd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Rename all files in current directory to replace spaces with _ # Rename all files in current directory to replace spaces with _
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -212,3 +210,6 @@ rmspc ()
unset lst substchar verb shell newf command mvopt unset lst substchar verb shell newf command mvopt
} }
export -f rmspc export -f rmspc
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -46,3 +47,6 @@ busy()
cat /dev/urandom | hexdump -C | grep "$pattern" cat /dev/urandom | hexdump -C | grep "$pattern"
unset pattern unset pattern
} }
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -66,3 +67,5 @@ EOF
} }
export -f help export -f help
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -42,7 +43,6 @@ ver ()
} }
export -f ver export -f ver
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Display weather of the given city (or default one) # Display weather of the given city (or default one)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -57,7 +57,6 @@ meteo ()
} }
export -f meteo export -f meteo
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Display system general information # Display system general information
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -88,3 +87,6 @@ showinfo()
fi fi
} }
export -f showinfo export -f showinfo
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -68,3 +69,6 @@ setus ()
export LC_ALL=en_US.UTF-8 export LC_ALL=en_US.UTF-8
} }
export -f setus export -f setus
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -47,8 +48,8 @@ isipv4 ()
IFS="." IFS="."
ip=($ip) ip=($ip)
IFS=$old_ifs IFS=$old_ifs
if [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ if [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 &&
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]; then ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]; then
if [[ -t 1 ]]; then if [[ -t 1 ]]; then
disp "The given IPv4 is valid." disp "The given IPv4 is valid."
fi fi
@@ -62,7 +63,6 @@ isipv4 ()
} }
export -f isipv4 export -f isipv4
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Determine if parameter is a valid IPv4 address # Determine if parameter is a valid IPv4 address
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -82,3 +82,6 @@ isipv6 ()
return 1 return 1
} }
export -f isipv6 export -f isipv6
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -77,3 +78,6 @@ pkgs ()
$cmd | grep $pkg $cmd | grep $pkg
} }
export -f pkgs export -f pkgs
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -38,11 +39,10 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
ppg() ppg()
{ {
ps -edf | grep $@ | grep -v "grep $@" ps -edf | grep "$@" | grep -v "grep $@"
} }
export -f ppg export -f ppg
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Get PID list of the given process name # Get PID list of the given process name
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -62,14 +62,33 @@ gpid ()
} }
export -f gpid export -f gpid
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Kill all processes owned by the given users # Kill all processes owned by the given users
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
ku() ku()
{ {
for u in $@; do for u in $@; do
killall -u $u killall -u "$u"
done done
} }
export -f ku export -f ku
# ------------------------------------------------------------------------------
# Kill all children of a process then the process
# ------------------------------------------------------------------------------
kt()
{
[[ -z $1 ]] && echo -e "Usage:\n\tkt <pid> [kill_options]"
local parent_pid="$1" children_pids
shift
children_pids=$(pgrep -P "$parent_pid")
for pid in $children_pids; do
kill_tree "$pid" "$@"
done
kill "$@" "$parent_pid"
}
# ------------------------------------------------------------------------------
# EOF

View File

@@ -123,3 +123,6 @@ set_prompt ()
# the text color to the default. # the text color to the default.
PS1+="$ICyan\\w \\\$$Default " PS1+="$ICyan\\w \\\$$Default "
} }
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -120,12 +121,11 @@ genpwd()
done done
# Function selecting a random caracter from the list in parameter # Function selecting a random caracter from the list in parameter
pickcar() pickcar() {
{
# When a character is picked we check if it's not appearing already twice # When a character is picked we check if it's not appearing already twice
# elsewhere, we choose an other char, to compensate weak bash randomizer # elsewhere, we choose an other char, to compensate weak bash randomizer
while [[ -z $char ]]; do while [[ -z $char ]]; do
local char=$(echo ${1:RANDOM%${#1}:1} $RANDOM) local char="${1:RANDOM%${#1}:1} $RANDOM"
if [[ $(awk -F"$char" '{print NF-1}' <<<"$picked") -gt $occurs ]]; then if [[ $(awk -F"$char" '{print NF-1}' <<<"$picked") -gt $occurs ]]; then
unset char unset char
fi fi
@@ -184,3 +184,6 @@ genpwd()
done done
} }
export -f genpwd export -f genpwd
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -54,7 +55,6 @@ rain()
local X=0 Y=0 drop_length=0 rain_drop=0 local X=0 Y=0 drop_length=0 rain_drop=0
local max_rain_width=0 new_rain_odd=0 falling_odd=0 local max_rain_width=0 new_rain_odd=0 falling_odd=0
sigwinch() { sigwinch() {
term_width=$(tput cols) term_width=$(tput cols)
term_height=$(tput lines) term_height=$(tput lines)
@@ -152,3 +152,6 @@ rain()
trap - WINCH trap - WINCH
} }
export -f rain export -f rain
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -77,7 +78,6 @@ rmhost ()
} }
export -f rmhost export -f rmhost
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Login root via SSH on the given machine # Login root via SSH on the given machine
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -103,3 +103,6 @@ ssr ()
ssh -Y root@$srv $@ ssh -Y root@$srv $@
} }
export -f ssr export -f ssr
# ------------------------------------------------------------------------------
# EOF

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 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. # Protected by the BSD3 license. Please read bellow for details.
@@ -33,24 +34,69 @@
# * OF SUCH DAMAGE. # * OF SUCH DAMAGE.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
export UPDT_URL="https://git.geoffray-levasseur.org/fatalerrors/profile/raw/branch/master"
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Check for profile updates # Check for profile updates
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
check_updates() check_updates()
{ {
if [[ $1 == "-q" ]]; then
# Quiet mode is mostly used internally when profile_upgrade is called
quiet=1
fi
disp I "Checking for updates..." disp I "Checking for updates..."
local vfile="/tmp/version" local vfile="/tmp/version"
wget "$UPDT_URL/version" -O $vfile 2&>1 /dev/null || { wget "$UPDT_URL/version" -O $vfile >/dev/null 2>&1 || {
disp E "Can\'t download information file, impossible to proceed!" disp E "Can't download version file, impossible to proceed!"
return 1 return 5
} }
if [[ -s /tmp/version ]]; then if [[ -s /tmp/version ]]; then
local lastver=$(cat /tmp/version) local lastver=$(cat /tmp/version)
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."
disp I "You should upgrade to last version when possible." [[ $quiet ]] && disp I "You should upgrade to last version when possible."
result=0
else
disp I "Your version is up-to-date."
result=1
fi fi
rm -f $vfile
else else
disp E "Impossible to read temporary file, impossible to proceed." disp E "Impossible to read temporary file, impossible to proceed."
fi fi
unset lastver vfile
return $result
} }
# ------------------------------------------------------------------------------
# Apply update to profile
# ------------------------------------------------------------------------------
profile_upgrade()
{
if [[ $(check_updates -q) -eq 0 ]]; then
if [[ -s $MYPATH/profile.sh ]]; then
disp E "Installation path detection failed, cannot upgrade automatically."
return 1
fi
if [[ -d $MYPATH/.git ]]; then
disp I "Git installation detected, applying git pull."
local curdir=$(pwd)
cd $MYPATH
git pull
if [[ $? -ne 0 ]]; then
disp E "Git pull failed, upgrade not applyed."
else
disp I "Successfully upgraded using git."
disp I "You should now logout and login again to enjoy new profile."
cd $curdir
fi
else
disp I "Applying traditionnal upgrade..."
# TODO
fi
fi
}
# EOF

View File

@@ -35,7 +35,7 @@
# * OF SUCH DAMAGE. # * OF SUCH DAMAGE.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
if [[ ! $(echo $SHELL | grep bash) ]]; then if [[ ! $SHELL =~ bash|zsh ]]; then
echo "That environmet script is designed to be used with bash or zsh being the shell." echo "That environmet script is designed to be used with bash or zsh being the shell."
echo "Please consider using bash or zsh instead, or patch me ;)!" echo "Please consider using bash or zsh instead, or patch me ;)!"
return 1 return 1
@@ -72,7 +72,6 @@ pathappend ()
export $pathvar="${!pathvar:+${!pathvar}:}$1" export $pathvar="${!pathvar:+${!pathvar}:}$1"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# ********************************** MAIN PROGRAM ****************************** # ********************************** MAIN PROGRAM ******************************
@@ -80,9 +79,13 @@ pathappend ()
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Store script's path (realpath -s resolve symlinks if profile.sh is a symlink) # Store script's path (realpath -s resolve symlinks if profile.sh is a symlink)
if [[ -z $PROFILE_PATH ]]; then
export MYPATH=$(dirname $(realpath -s $0)) export MYPATH=$(dirname $(realpath -s $0))
else
export MYPATH=$PROFILE_PATH
fi
if [[ ! -e $MYPATH/profile.sh ]]; then if [[ ! -e $MYPATH/profile.sh ]]; then
echo "[ Warning ] Path detection failed, using pwd..." echo "[ Warning ] Path detection failed, trying to use pwd..."
MYPATH=$(pwd) MYPATH=$(pwd)
if [[ ! -e $MYPATH/profile.sh ]]; then if [[ ! -e $MYPATH/profile.sh ]]; then
echo "[ Error ] Impossible to determine installation path, pretty much nothing will work." echo "[ Error ] Impossible to determine installation path, pretty much nothing will work."
@@ -102,6 +105,10 @@ fi
[[ -d ~/bin ]] && pathappend ~/bin [[ -d ~/bin ]] && pathappend ~/bin
[[ -d ~/.local/bin ]] && pathappend ~/.local/bin [[ -d ~/.local/bin ]] && pathappend ~/.local/bin
# ------------------------------------------------------------------------------
# Default values are set here and will be overloaded with config file if any
# ------------------------------------------------------------------------------
# Set bash history # Set bash history
export HISTSIZE=50000 export HISTSIZE=50000
export HISTIGNORE="&:[bf]g:exit" export HISTIGNORE="&:[bf]g:exit"
@@ -125,14 +132,14 @@ export DEFAULT_CITY="Toulouse"
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Load global configuration # Load global configuration
[[ -f $MYPATH/etc/profile.conf ]] && . ~/.profile.conf [[ -f $MYPATH/etc/profile.conf ]] && . $MYPATH/etc/profile.conf
# Load personal configuration # Load personal configuration
[[ -f ~/.profile.conf ]] && . ~/.profile.conf [[ -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
if [ -r $script ] ; then if [[ -r $script ]]; then
. $script . $script
fi fi
done done

View File

@@ -1 +1 @@
3.3.1 3.3.2