bw-cli_autologger/bw_cli_autolog.sh
Siphonight bc4627a762 Correction du script de base pour compatibilità ©H
Modification du script de base pour la compatibilità avec SH.
En Bash, les tests dans les conditions if son plus surs et sÃcurisÃs en
utilisant les "[[ condition ]]".

Cependant ces derniers sont une spÃcificità supportÃe uniquement dans
Bash et non SH.

SH ayant une plus grande compatibilitéavec le reste des shells, il faut
de ce fait que cet utilitaire y soit adaptÃ.
2025-02-13 07:30:12 +01:00

68 lines
1.7 KiB
Bash

identities_create() {
# IDENTITES
Inception_Detect=0
if [ -z "${BW_Session}" ] || [ $(echo "${BW_Session}" | wc -c) -lt 10 ]; then
tput setaf 4
echo -e "Lancement du autologin (ne prenez pas en compte les tokens, ils sont gérés automatiquement)."
tput sgr0
identities_destroy
local Bitwarden_Email="<EMAIL_DE_CONNEXION_A_BITWARDEN>"
local Bitwarden_Server="<URL_DE_L_INSTANCE_BITWARDEN>"
bw config server "${Bitwarden_Server}"
export BW_Session="$(bw login "${Bitwarden_Email}" | tee /dev/tty | grep -m1 '==' | cut -d '"' -f 2)"
Inception_Detect=1
fi
local BW_List
BW_List=$(bw list items --session "$BW_Session")
if [ "$BW_List" != "" ]; then
if [ "${Inception_Detect}" != "1" ]; then
unset BW_Session
fi
# shellcheck disable=SC2009
if [ "$(ps -aux | grep 'sh -c while true; do sleep 10; bw sync -f; done' | grep -cv 'grep')" == "0" ]; then
nohup sh -c 'while true; do sleep 10; bw sync -f; done' >/dev/null 2>&1 &
fi
tput setaf 4
echo -e "\nBitwarden connecté, mise en place des identités..."
tput sgr0
eval "$(ssh-agent)"
trap 'kill $SSH_AGENT_PID' EXIT
echo "$BW_List" | jq -r '.[] | select(.name=="identities - configs") | .notes' >"$HOME"/.identities-loaded.sh
chmod 700 "$HOME"/.identities-loaded.sh
source "${HOME}"/.identities-loaded.sh
unset BW_List
else
tput setaf 4
echo "Bitwarden non connecté, les identités n'ont pas été mises en place."
tput sgr0
fi
}
identities_destroy() {
tput setaf 4
echo "Déconnexion des identités en cours..."
tput sgr0
bw logout
ssh-add -D
pkill ssh-agent
unset BW_Session
tput setaf 4
echo "Déconnexion des identités terminée"
tput sgr0
}
identities_create