Correction changement cassant introduit dans la version précédente
Correction d'un problème introduit dans le correctif précédent. Les terminaux SH et ZSH déclenchaient la fonction de nettoyage "identities_destroy" dès la sortie de la fonction "identities_create". Auparavant, la commande trap était éxecutée en dehors des fonctions et donc la sortie de la fonction n'équivalait pas à un EXIT. Ce comportement n'affectait pas les utilisateurs sous Bash, dont la gestion des subshells est différente. Cette correction revoit l'intégralité du script et supprime la fonction devenue obsolète "identities_create" au profit d'un code exécuté directement. Cela permet également de mieux réarrager le code et de définir la fonction "identities_destroy" dès le lancement du script.
This commit is contained in:
parent
a17b0ba7c1
commit
6d286dce46
@ -1,14 +1,35 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
identities_create() {
|
# Variables à définir par l'utilisateur.
|
||||||
# IDENTITES
|
|
||||||
Bitwarden_Email="<EMAIL_DE_CONNEXION_A_BITWARDEN>"
|
Bitwarden_Email="<EMAIL_DE_CONNEXION_A_BITWARDEN>"
|
||||||
Bitwarden_Server="<URL_DE_L_INSTANCE_BITWARDEN>"
|
Bitwarden_Server="<URL_DE_L_INSTANCE_BITWARDEN>"
|
||||||
Inception_Detect=0
|
|
||||||
|
|
||||||
|
# Variables internes au script
|
||||||
|
Inception_Detect=0 # Détection de terminaux parents/enfants
|
||||||
|
Local_Version="2.2.7"
|
||||||
|
|
||||||
|
# Fonction de suppression et nettoyage des identités
|
||||||
|
identities_destroy() {
|
||||||
|
tput setaf 4
|
||||||
|
echo "Déconnexion des identités en cours..."
|
||||||
|
|
||||||
|
bw logout
|
||||||
|
ssh-add -D
|
||||||
|
pkill ssh-agent
|
||||||
|
echo "Suppression des fichiers générés..."
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
grep -in "printf.*\"\%s\".*\"\$BW_List\"" "${HOME}"/.identities-loaded.sh | grep ">" | cut -d ">" -f 2 | sed -e "s,\~,${HOME},g ; s,\"\$HOME\",${HOME},g ; s,^\ ,,g" | while IFS= read -r each; do
|
||||||
|
rm -rf "${each}"
|
||||||
|
done
|
||||||
|
unset BW_Session
|
||||||
|
|
||||||
|
echo "Déconnexion des identités terminée"
|
||||||
|
tput sgr0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Processus de création des identités
|
||||||
if [ -z "${BW_Session}" ] || [ "${#BW_Session}" -lt 10 ]; then
|
if [ -z "${BW_Session}" ] || [ "${#BW_Session}" -lt 10 ]; then
|
||||||
trap identities_destroy EXIT
|
trap identities_destroy EXIT
|
||||||
Local_Version="2.2.6"
|
|
||||||
Latest_Version=$(curl -s "https://gitea.cloudyfy.fr/Siphonight/bw-cli_autologger/src/branch/main/bw_cli_autolog.sh" | grep -m1 "Local_Version" | cut -d ';' -f 2 | cut -d '&' -f 1)
|
Latest_Version=$(curl -s "https://gitea.cloudyfy.fr/Siphonight/bw-cli_autologger/src/branch/main/bw_cli_autolog.sh" | grep -m1 "Local_Version" | cut -d ';' -f 2 | cut -d '&' -f 1)
|
||||||
if [ "${Local_Version}" != "${Latest_Version}" ]; then
|
if [ "${Local_Version}" != "${Latest_Version}" ]; then
|
||||||
tput setaf 1
|
tput setaf 1
|
||||||
@ -63,24 +84,3 @@ identities_create() {
|
|||||||
echo "Bitwarden non connecté, les identités n'ont pas été mises en place."
|
echo "Bitwarden non connecté, les identités n'ont pas été mises en place."
|
||||||
tput sgr0
|
tput sgr0
|
||||||
fi
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
identities_destroy() {
|
|
||||||
tput setaf 4
|
|
||||||
echo "Déconnexion des identités en cours..."
|
|
||||||
|
|
||||||
bw logout
|
|
||||||
ssh-add -D
|
|
||||||
pkill ssh-agent
|
|
||||||
echo "Suppression des fichiers générés..."
|
|
||||||
# shellcheck disable=SC2016
|
|
||||||
grep -in "printf.*\"\%s\".*\"\$BW_List\"" "${HOME}"/.identities-loaded.sh | grep ">" | cut -d ">" -f 2 | sed -e "s,\~,${HOME},g ; s,\"\$HOME\",${HOME},g ; s,^\ ,,g" | while IFS= read -r each; do
|
|
||||||
rm -rf "${each}"
|
|
||||||
done
|
|
||||||
unset BW_Session
|
|
||||||
|
|
||||||
echo "Déconnexion des identités terminée"
|
|
||||||
tput sgr0
|
|
||||||
}
|
|
||||||
|
|
||||||
identities_create
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user