mirror of https://framagit.org/kyodev/kyopages.git
maj
This commit is contained in:
parent
6b42539f4e
commit
468a3b6a73
|
@ -1,95 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
version=27/08/2017
|
||||
|
||||
# user ayant initié la session graphique, assigne $user_
|
||||
# return 1 sur échec identification user, return 2 sur absence home/
|
||||
# gestion variable environnement user avec: USER_INSTALL=user script
|
||||
f__user(){ # v21/08/2017-4
|
||||
if [ "$USER_INSTALL" ]; then # user_ via variable environnement, moyen d'injecter root
|
||||
user_="$USER_INSTALL";
|
||||
sortie="variable environnement USER_INSTALL"
|
||||
return 0
|
||||
fi
|
||||
local user_id test
|
||||
local root_login="$(grep ':0:' /etc/passwd | cut -d':' -f1)" || local root_login="root"
|
||||
if [ "$SUDO_UID" ]; then
|
||||
user_id="$SUDO_UID";
|
||||
elif grep -qEo '[0-9]+' <<< "$XDG_RUNTIME_DIR" ; then
|
||||
user_id="$(grep -Eo '[0-9]+' <<< $XDG_RUNTIME_DIR | cut -d'/' -f4)"
|
||||
elif grep -qEo '[0-9]+' <<< "$XAUTHORITY" ; then
|
||||
user_id="$(grep -Eo '[0-9]+' <<< $XAUTHORITY | cut -d'/' -f4)"
|
||||
fi
|
||||
[ "$user_id" ] && user_="$(grep $user_id /etc/passwd | cut -d ":" -f 1 )"
|
||||
if [ "$user_" ] && [ "$user_" != "$root_login" ]; then
|
||||
sortie="sortie user_id"
|
||||
return 0
|
||||
else
|
||||
if [ "$SUDO_USER" ] && [ "$SUDO_USER" != "$root_login" ]; then
|
||||
user_="$SUDO_USER";
|
||||
elif grep -qv 'root' <<< "$(who)"; then
|
||||
user_="$(grep -v 'root' <<< $(who) | head -n1 | cut -d ' ' -f1)";
|
||||
elif grep -q 'hourly.*get[A-Z].*\.anacrontab.*\.config/anacron/spool' /etc/crontab; then
|
||||
user_="$(grep 'hourly.*get[A-Z].*\.anacrontab.*\.config/anacron/spool' /etc/crontab | head -n1 | cut -d' ' -f2)";
|
||||
fi
|
||||
fi
|
||||
sortie="sortie user final"
|
||||
if [ -z "$user_" ]; then return 1; fi
|
||||
if [ ! -d "/home/$user_" ]; then return 2; fi
|
||||
return 0
|
||||
}
|
||||
|
||||
f__type(){
|
||||
if [ "$SSH_TTY" ]; then type="SSH"
|
||||
elif [ "$SUDO_UID" ] ; then type="SUDO"
|
||||
elif [ "$XDG_CURRENT_DESKTOP" ]; then type="$XDG_CURRENT_DESKTOP"; fi
|
||||
if [ -n "$DISPLAY" ] && [ -z "$type" ]; then type="$(xprop -root | awk '/KDE_SESSION_VERSION|^_MUFFIN|xfce4|xfce5/')"; fi
|
||||
type+="$(tty -s && echo ' terminal' || echo $(LC_ALL=C tty))"
|
||||
}
|
||||
|
||||
echo -e "\ndétection user ayant acquit les droits root\n"
|
||||
[ $EUID -eq 0 ] || echo -e "merci tester aussi le script en ROOT\n"
|
||||
|
||||
f__user && retourFUser=0 || retourFUser="$?"
|
||||
[ "$retourFUser" -gt 0 ] && echo "houla :("
|
||||
[ "$retourFUser" -eq 1 ] && echo -e "user indéterminé, pour contourner, lancer le script avec:\n USER_INSTALL=user $0 \n"
|
||||
[ "$retourFUser" -eq 2 ] && echo -e "user détecté, mais pas de home: /home/$user_"
|
||||
|
||||
echo -e "\tuser détecté: $user_"
|
||||
echo -e "\tsortie: $sortie"
|
||||
echo -e "\tEUID: $EUID"
|
||||
f__type
|
||||
echo -e "\ttype: $type\n"
|
||||
|
||||
f__user_debug(){ # v20/08/2017-4
|
||||
|
||||
local user_id
|
||||
|
||||
debug+="user_id01:$SUDO_UID (SUDO_UID) \n";
|
||||
debug+="user_id02:$(grep -Eo '[0-9]+' <<< $XDG_RUNTIME_DIR | cut -d'/' -f4) (XDG_RUNTIME_DIR) \n"
|
||||
debug+="user_id03:$(grep -Eo '[0-9]+' <<< $XAUTHORITY | cut -d'/' -f4) (XAUTHORITY) \n\n"
|
||||
if [ "$SUDO_UID" ]; then
|
||||
user_id="$SUDO_UID"
|
||||
elif [ "$(grep -Eo '[0-9]+' <<< $XDG_RUNTIME_DIR | cut -d'/' -f4)" ];then
|
||||
user_id="$(grep -Eo '[0-9]+' <<< $XDG_RUNTIME_DIR | cut -d'/' -f4)"
|
||||
elif [ "$(grep -Eo '[0-9]+' <<< $XAUTHORITY | cut -d'/' -f4)" ];then
|
||||
user_id="$(grep -Eo '[0-9]+' <<< $XAUTHORITY | cut -d'/' -f4) (XAUTHORITY)"
|
||||
fi
|
||||
debug+="user00:$USER_INSTALL (USER_INSTALL) \n";
|
||||
debug+="user01:$(grep $user_id /etc/passwd | cut -d ":" -f 1 ) (user_id) \n"
|
||||
debug+="user02:$SUDO_USER (SUDO_USER) \n"
|
||||
debug+="user03:$(grep -v 'root' <<< $(who) | head -n1 | cut -d ' ' -f1) (who) \n"
|
||||
debug+="user04:$(grep 'hourly.*get[A-Z].*\.anacrontab.*\.config/anacron/spool' /etc/crontab | head -n1 | cut -d' ' -f2) (anacrontab) \n"
|
||||
|
||||
}
|
||||
|
||||
f__user_debug
|
||||
|
||||
echo -e "\tdebug:"
|
||||
echo -e "$debug"
|
||||
exit 0
|
||||
|
||||
# test crontab
|
||||
#*/5 * * * * kyodev /home/<user>/test_user > /home/<user>/cronTestuserUser
|
||||
#*/5 * * * * root /home/<user>/test_user > /home/<user>/cronTestuserUser
|
||||
|
|
@ -1,36 +1,19 @@
|
|||
#!/bin/bash
|
||||
|
||||
# choisit su ou sudo, assigne $sudo
|
||||
f__sudo_0(){ # 06/10/2017
|
||||
if sudo -v &>/dev/null && [ $EUID -ne 0 ]; then
|
||||
sudo=
|
||||
else
|
||||
sudo="su -c"
|
||||
fi
|
||||
}
|
||||
|
||||
# $1=cmd si $2: nb de tentatives pour s'identifier, sinon 2 tentatives par défaut
|
||||
f__sudo_1(){ # 23/09/2017
|
||||
local nb
|
||||
[ "$2" ] && nb="$2" || nb="2"
|
||||
for (( i=1 ; i<="$nb" ; i++ )); do
|
||||
su -c "$1"
|
||||
[ "$?" == 0 ] && break
|
||||
[ "$i" == "$nb" ] && echo " $nb échec d'authentification, recommencer"
|
||||
done
|
||||
unset i
|
||||
}
|
||||
|
||||
# $1=cmd si $2: nb de tentatives pour s'identifier, sinon 2 tentatives par défaut
|
||||
f__sudo(){ # 06/10/2017
|
||||
local nb="2" sudo i
|
||||
# $1=cmd si $2: nb de tentatives pour s'identifier, sinon 1 tentative par défaut
|
||||
f__sudo(){ # 11/10/2017
|
||||
local nb=1 sudo isudo
|
||||
# sudo --shell bash équivalent su ?
|
||||
sudo -v &>/dev/null && [ $EUID -ne 0 ] && sudo="sudo --shell bash" || sudo="su -c"
|
||||
if sudo -v &>/dev/null && [ $EUID -ne 0 ] ; then
|
||||
sudo="sudo su --shell $(which bash) --preserve-environment -c "
|
||||
else
|
||||
sudo="su --shell $(which bash) --preserve-environment -c "
|
||||
fi
|
||||
[ "$2" ] && nb="$2"
|
||||
for (( i=1 ; i<="$nb" ; i++ )); do
|
||||
for (( isudo=1 ; isudo<="$nb" ; isudo++ )); do
|
||||
$sudo " $1"
|
||||
[ "$?" == 0 ] && break
|
||||
[ "$i" == "$nb" ] && return 1
|
||||
[ "$isudo" == "$nb" ] && return 1
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -44,14 +27,20 @@ echo $$
|
|||
|
||||
exit 0
|
||||
|
||||
f__sudo_0
|
||||
$sudo "dmesg -l crit"
|
||||
tester:
|
||||
sudo -i eq su -
|
||||
-> /root
|
||||
|
||||
et sudo -sudo -s eq su
|
||||
-> ./ pas de changement de répertoire courant
|
||||
|
||||
|
||||
f__sudo_1 "dmesg -l crit"
|
||||
|
||||
#f__sudo "echo je suis $(whoami)"3
|
||||
|
||||
if ! dmesg --nopager &> /dev/null; then
|
||||
echo "la commande \`dmesg\` n'est pas disponible (droits root requis?)"
|
||||
else
|
||||
echo "all is ok"
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue