This commit is contained in:
kyodev 2017-08-17 12:12:05 +02:00
parent 484d2c8174
commit a566fa4c69
2 changed files with 34 additions and 35 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash
version=1.0.0
version=1.0.1
date="17/08/2017"
projet="simpledeb"
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues"
@ -88,48 +88,47 @@ f__log(){ # v08/2017
# si $2=debOnly et si paquets manquants: return 1 et $debOnlyPackages ( $1=liste paquets )
# si $2=debOnly et si paquets présent: return 0 et $debOnlyPresents ( $1=liste paquets )
# attention priorité $debOnlyPackages sur $debOnlyPresents
f__requis(){ # v16/08/2017-3
local dependsMissing packagesMissing
unset debOnlyPackages debOnlyPresents
for i in $1; do
local command=$(cut -d '>' -f 1 <<< $i)
local package=$(cut -d '>' -f 2 <<< $i)
if [ "$2" == "debOnly" ]; then
if [ "$(which dpkg)" ]; then # package only et debian
LC_ALL=C dpkg --get-selections | grep -qE "^$package[[:space:]]+install" \
&& debOnlyPresents+="$package " || debOnlyPackages+="$package "
else f__error "dpkg n'est pas disponible sur ce système"; fi
elif [ -z "$(which $command)" ]; then
dependsMissing+="$command "
packagesMissing+="$package "
f__requis(){ # v17/08/2017-3
local dependsMissing packagesMissing
unset debOnlyPackages debOnlyPresents
for i in $1; do
local command="$(cut -d '>' -f 1 <<< $i)"
local package="$(cut -d '>' -f 2 <<< $i)"
if [ "$2" == "debOnly" ]; then
if [ "$(which dpkg)" ]; then # package only et debian
LC_ALL=C dpkg --get-selections | grep -qE "^$package[[:space:]]+install" \
&& debOnlyPresents+="$package " || debOnlyPackages+="$package "
else f__error "dpkg n'est pas disponible sur ce système"; fi
elif [ -z "$(which $command)" ]; then
dependsMissing+="$command "
packagesMissing+="$package "
fi
done
[ "$debOnlyPackages" ] && debOnlyPackages="$(xargs <<< $debOnlyPackages)" # trim début & fin
[ "$debOnlyPresents" ] && debOnlyPresents="$(xargs <<< $debOnlyPresents)" # trim début & fin
[ "$debOnlyPackages" ] && return 1
[ "$debOnlyPresents" ] && return 0
if [ "$dependsMissing" ]; then
if [ -e /etc/debian_version ]; then f__error "paquet(s) manquant(s): " " $dependsMissing" \
" vous devriez exécuter:$GREEN apt install $packagesMissing"
else f__error "commandes(s) manquante(s): " "$dependsMissing"; fi
fi
done
[ "$debOnlyPackages" ] && debOnlyPackages=$(xargs <<< $debOnlyPackages) # trim début & fin
[ "$debOnlyPresents" ] && debOnlyPresents=$(xargs <<< $debOnlyPresents) # trim début & fin
[ "$debOnlyPackages" ] && return 1
[ "$debOnlyPresents" ] && return 0
if [ "$dependsMissing" ]; then
if [ -e /etc/debian_version ]; then f__error "paquet(s) manquant(s): " " $dependsMissing" \
" vous devriez exécuter:$GREEN apt install $packagesMissing"
else f__error "commandes(s) manquante(s): " "$dependsMissing"; fi
fi
}
}
# user ayant initié la session graphique, assigne $user_, testé avec mate, gnome, xfce. manque KDE
# return 1 sur echec ident user, return 2 sur absence home
# gestion variable environnement user avec: USER_INSTALL=user script
f__user(){ # v15/08/2017-4
f__user(){ # v17/08/2017-4
local user_id
if [ "$USER_INSTALL" ]; then user_="$USER_INSTALL"; fi # user_ via variable environnement
if [ -z "$user_" ]; then # priorité à $USER_INSTALL
if [ "$SUDO_UID" ]; then user_id="$SUDO_UID"; fi # sudo
user_id=$(grep -qEo '[0-9]+' <<< "$XAUTHORITY") || user_id=$(grep -qEo '[0-9]+' <<< $XDG_RUNTIME_DIR)
if [ "$user_id" ]; then user_=$(grep $user_id /etc/passwd | cut -d ":" -f 1 )
else user_=$(echo $XAUTHORITY | cut -d "/" -f 3); fi
if [ -z "$user_" ] && [ "$LOGNAME" ] ; then user_=$(grep -v 'root' <<< $LOGNAME)
elif [ -z "$user_" ] && [ $(grep -v 'root' <<< $HOME) ]; then user_=$(cut -sd / -f 3 <<< $HOME)
elif [ -z "$user_" ]; then user_=$(grep -v 'root' <<< $(who | head -n1 | cut -d " " -f1))
elif [ -z "$user_" ] && [ $(grep -v 'not') <<< $(LC_ALL=C tty) ]; then user_=$(stat -c %U $(tty)); fi
user_id="$(grep -qEo '[0-9]+' <<< "$XAUTHORITY")" || user_id="$(grep -qEo '[0-9]+' <<< $XDG_RUNTIME_DIR)"
if [ "$user_id" ]; then user_="$(grep $user_id /etc/passwd | cut -d ":" -f 1 )"
else user_="$(echo $XAUTHORITY | cut -d "/" -f 3)"; fi
if [ -z "$user_" ] && [ "$LOGNAME" ] ; then user_="$(grep -v 'root' <<< $LOGNAME)"
elif [ -z "$user_" ] && [ "$(grep -v 'root' <<< $HOME)" ]; then user_="$(cut -sd / -f 3 <<< $HOME)"
elif [ -z "$user_" ]; then user_="$(grep -v 'root' <<< $(who | head -n1 | cut -d ' ' -f1))"; fi
fi
if [ -z "$user_" ]; then
echo -e "user indéterminé, pour contourner, lancer le script avec:\n USER_INSTALL=user $0 n" \

View File

@ -1,6 +1,6 @@
# changelog getInfo
## 1.0.0 17/08/2017
## 1.0.1 17/08/2017
* version publique