mirror of
https://github.com/vhaudiquet/mymachine.git
synced 2025-12-18 20:16:05 +00:00
Bitwarden fixes, faster script on Ubuntu
This commit is contained in:
29
mymachine.sh
29
mymachine.sh
@@ -248,28 +248,46 @@ fi
|
||||
if ! bitwarden_is_authenticated; then
|
||||
if [ ! -z "${BW_CLIENTID}" ] && [ ! -z "${BW_CLIENTSECRET}" ]; then
|
||||
BW_CLIENTID="${BW_CLIENTID}" BW_CLIENTSECRET="${BW_CLIENTSECRET}" bw login --apikey >/dev/null 2>&1
|
||||
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
|
||||
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
|
||||
if ! bitwarden_is_locked; then
|
||||
echo -n "Authenticating with bitwarden... "
|
||||
|
||||
echo -n "sync"
|
||||
bw sync >/dev/null 2>&1
|
||||
erase_text "sync"
|
||||
|
||||
# Connect github cli using GH_TOKEN special field, if needed
|
||||
gh auth status >/dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
GH_TOKEN=$(bw get item github.com |jq -r '.fields[]|select(.name=="GH_TOKEN")|.value')
|
||||
if [ $? -ne 0 ] && [ ! -z GH_TOKEN ]; then
|
||||
echo -n "github-cli"
|
||||
GH_TOKEN=$(bw get item github.com 2>/dev/null |jq -r '.fields[]|select(.name=="GH_TOKEN")|.value' 2>/dev/null)
|
||||
if [ $? -eq 0 ] && [ ! -z "${GH_TOKEN}" ]; then
|
||||
GH_TOKEN="${GH_TOKEN}" gh auth login -p https -h github.com >/dev/null 2>&1
|
||||
gh auth setup-git --hostname github.com
|
||||
gh auth setup-git --hostname github.com >/dev/null 2>&1
|
||||
erase_text "github-cli"
|
||||
else
|
||||
erase_text "github-cli"
|
||||
echo -ne "${BRed}github-cli${NC} "
|
||||
fi
|
||||
fi
|
||||
|
||||
# Obtain kubectl config
|
||||
if [ ! -f "/home/${USERNAME}/.kube/config" ]; then
|
||||
echo -n "kubectl"
|
||||
KUBE=$(bw get item kube)
|
||||
if [ $? -eq 0 ]; then
|
||||
sudo -u ${USERNAME} mkdir -p "/home/${USERNAME}/.kube/"
|
||||
@@ -277,10 +295,13 @@ if ! bitwarden_is_locked; then
|
||||
ATTACHMENT_ID=$(echo "${KUBE}" |jq -r '.attachments[]|select(.fileName=="config")|.id')
|
||||
bw get attachment "${ATTACHMENT_ID}" --itemid "${OBJECT_ID}" --raw >"/home/${USERNAME}/.kube/config" 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${BRed}Could not get .kube/config attachment from bitwarden. Skipping.${NC}"
|
||||
echo -e "\n${BRed}Could not get .kube/config attachment from bitwarden. Skipping.${NC}"
|
||||
fi
|
||||
fi
|
||||
erase_text "kubectl"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# VPN configuration
|
||||
|
||||
Reference in New Issue
Block a user