11 Commits

6 changed files with 198 additions and 15 deletions

View File

@@ -7,6 +7,17 @@ Current version from Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
------------------------------------------------------------------------------
Version history:
------------------------------------------------------------------------------
# 24/02/2022 v3.3.1
Fixed version detection
Added "busy" function
Fixed use of library functions before it's loaded
# 28/11/2022 v3.3.0
Initial version update support
Changed versioning code
Added installation path detection
# 28/11/2022 v3.2.3
Made proper readme file, to improve

48
profile.d/fun.sh Normal file
View File

@@ -0,0 +1,48 @@
# ------------------------------------------------------------------------------
# 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,
# * with or without modification, are permitted provided
# * that the following conditions are met:
# *
# * Redistributions of source code must retain the above
# * copyright notice, this list of conditions and the
# * following disclaimer.
# *
# * Redistributions in binary form must reproduce the above
# * copyright notice, this list of conditions and the following
# * disclaimer in the documentation and/or other materials
# * provided with the distribution.
# *
# * Neither the name of the copyright holder nor the names
# * of any other contributors may be used to endorse or
# * promote products derived from this software without
# * specific prior written permission.
# *
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# * OF SUCH DAMAGE.
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Make non-IT peoples think you're busy doing something hard
# ------------------------------------------------------------------------------
busy()
{
if [[ -n $1 ]]; then
local pattern="$@"
else
local pattern="ca fe"
fi
cat /dev/urandom | hexdump -C | grep "$pattern"
unset pattern
}

View File

@@ -36,7 +36,7 @@
# ------------------------------------------------------------------------------
# Look for a package within installed one
# ------------------------------------------------------------------------------
dpkgs ()
pkgs ()
{
local count=0
for opt in $@ ; do
@@ -68,13 +68,12 @@ dpkgs ()
disp E "Please specify a package name, without space, eventually partial." &&
return 1
if [[ $(command -v dpkg >/dev/null 2>&1) ]]; then
dpkg -l | grep $pkg
elif [[ $(command -v rpm >/dev/null 2>&1) ]]; then
rpm -qa | grep $pkg
else
command -v dpkg >/dev/null 2>&1 && local cmd="dpkg -l"
command -v rpm >/dev/null 2>&1 && local cmd="rpm -qa"
if [[ -z $cmd ]]; then
disp E "No usable package manager seems unavialable."
return 2
fi
$cmd | grep $pkg
}
export -f dpkgs
export -f pkgs

100
profile.d/updates.sh Normal file
View File

@@ -0,0 +1,100 @@
# ------------------------------------------------------------------------------
# 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,
# * with or without modification, are permitted provided
# * that the following conditions are met:
# *
# * Redistributions of source code must retain the above
# * copyright notice, this list of conditions and the
# * following disclaimer.
# *
# * Redistributions in binary form must reproduce the above
# * copyright notice, this list of conditions and the following
# * disclaimer in the documentation and/or other materials
# * provided with the distribution.
# *
# * Neither the name of the copyright holder nor the names
# * of any other contributors may be used to endorse or
# * promote products derived from this software without
# * specific prior written permission.
# *
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# * OF SUCH DAMAGE.
# ------------------------------------------------------------------------------
export UPDT_URL="https://git.geoffray-levasseur.org/fatalerrors/profile"
# ------------------------------------------------------------------------------
# Check for profile 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..."
local vfile="/tmp/version"
wget "$UPDT_URL/version" -O $vfile 2&>1 /dev/null || {
disp E "Can\'t download version file, impossible to proceed!"
return 5
}
if [[ -s /tmp/version ]]; then
local lastver=$(cat /tmp/version)
if [[ $lastver != $PROFVERSION ]]; then
disp I "You have version $PROFVERSION installed. Version $lastver is available."
[[ $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
rm -f $vfile
else
disp E "Impossible to read temporary file, impossible to proceed."
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,11 +35,7 @@
# * OF SUCH DAMAGE.
# ------------------------------------------------------------------------------
export PROFVERSION="3.2.3"
export DEFAULT_CITY="Toulouse"
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 "Please consider using bash or zsh instead, or patch me ;)!"
return 1
@@ -83,6 +79,25 @@ pathappend ()
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# 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))
else
export MYPATH=$PROFILE_PATH
fi
if [[ ! -e $MYPATH/profile.sh ]]; then
echo "[ Warning ] Path detection failed, trying to use pwd..."
MYPATH=$(pwd)
if [[ ! -e $MYPATH/profile.sh ]]; then
echo "[ Error ] Impossible to determine installation path, pretty much nothing will work."
fi
fi
if [[ ! -s $MYPATH/version ]]; then
echo "[ Warning ] Impossible to determine running version of profile, your installation might be broken."
fi
export PROFVERSION=$(cat $MYPATH/version)
# Build PATH environment variable
if [[ $EUID -eq 0 ]] ; then
pathappend /sbin:/usr/sbin
@@ -91,6 +106,10 @@ fi
[[ -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"
@@ -106,17 +125,22 @@ 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
# Execute optionnal config script if any
for script in ~/profile.d/*.sh ; do
if [ -r $script ] ; then
# Load module scripts
for script in $MYPATH/profile.d/*.sh ; do
if [[ -r $script ]]; then
. $script
fi
done

1
version Normal file
View File

@@ -0,0 +1 @@
3.3.1