mirror of
https://github.com/vhaudiquet/mymachine.git
synced 2025-12-18 12:06:06 +00:00
refactor: move bitwarden functions
This commit is contained in:
23
bitwarden.sh
23
bitwarden.sh
@@ -24,3 +24,26 @@ bitwarden_is_locked() {
|
||||
fi
|
||||
}
|
||||
|
||||
bitwarden_login() {
|
||||
# Login to Bitwarden
|
||||
if ! bitwarden_is_authenticated; then
|
||||
if [ ! -z "${BW_CLIENTID}" ] && [ ! -z "${BW_CLIENTSECRET}" ]; then
|
||||
echo "Login in to Bitwarden..."
|
||||
BW_CLIENTID="${BW_CLIENTID}" BW_CLIENTSECRET="${BW_CLIENTSECRET}" BW login --apikey >/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${BRed}Could not login to Bitwarden. Skipping.${NC}"
|
||||
fi
|
||||
else
|
||||
echo "Skipping Bitwarden authentication, no credentials provided."
|
||||
fi
|
||||
fi
|
||||
if bitwarden_is_authenticated && bitwarden_is_locked; then
|
||||
if [ ! -z "${BW_PASSWORD}" ]; then
|
||||
echo "Unlocking Bitwarden vault..."
|
||||
export BW_SESSION=$(BW unlock --raw ${BW_PASSWORD})
|
||||
if [ -z "${BW_SESSION}" ]; then
|
||||
echo -e "${BRed}Could not unlock Bitwarden vault. Skipping.${NC}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
22
mymachine.sh
22
mymachine.sh
@@ -244,27 +244,7 @@ if [ $? -ne 0 ]; then
|
||||
echo -e "${BRed}Failed to generate grub configuration. Skipping. Be careful !${NC}"
|
||||
fi
|
||||
|
||||
# Login to Bitwarden
|
||||
if ! bitwarden_is_authenticated; then
|
||||
if [ ! -z "${BW_CLIENTID}" ] && [ ! -z "${BW_CLIENTSECRET}" ]; then
|
||||
echo "Login in to Bitwarden..."
|
||||
BW_CLIENTID="${BW_CLIENTID}" BW_CLIENTSECRET="${BW_CLIENTSECRET}" BW login --apikey >/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${BRed}Could not login to Bitwarden. Skipping.${NC}"
|
||||
fi
|
||||
else
|
||||
echo "Skipping Bitwarden authentication, no credentials provided."
|
||||
fi
|
||||
fi
|
||||
if bitwarden_is_authenticated && bitwarden_is_locked; then
|
||||
if [ ! -z "${BW_PASSWORD}" ]; then
|
||||
echo "Unlocking Bitwarden vault..."
|
||||
export BW_SESSION=$(BW unlock --raw ${BW_PASSWORD})
|
||||
if [ -z "${BW_SESSION}" ]; then
|
||||
echo -e "${BRed}Could not unlock Bitwarden vault. Skipping.${NC}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
bitwarden_login
|
||||
if ! bitwarden_is_locked; then
|
||||
echo -n "Authenticating with bitwarden... "
|
||||
|
||||
|
||||
Reference in New Issue
Block a user