Bitwarden fixes, faster script on Ubuntu

This commit is contained in:
2025-08-27 15:27:26 +02:00
parent 366896a13e
commit 4cf146c6c1
3 changed files with 84 additions and 45 deletions

View File

@@ -5,7 +5,7 @@ alias bw="sudo -u ${USERNAME} bw"
bitwarden_is_authenticated() { bitwarden_is_authenticated() {
status=$(bw status 2>/dev/null |jq -r ".status" 2>/dev/null) status=$(bw status 2>/dev/null |jq -r ".status" 2>/dev/null)
if [ -z "${status}" ]; then if [ -z "${status}" ]; then
false return false
else else
[[ ! ${status} == "unauthenticated" ]] [[ ! ${status} == "unauthenticated" ]]
fi fi
@@ -13,7 +13,7 @@ bitwarden_is_authenticated() {
bitwarden_is_locked() { bitwarden_is_locked() {
status=$(bw status 2>/dev/null |jq -r ".status" 2>/dev/null) status=$(bw status 2>/dev/null |jq -r ".status" 2>/dev/null)
if [ -z "${status}" ]; then if [ -z "${status}" ]; then
true return true
else else
[[ ${status} == "locked" ]] || ! bitwarden_is_authenticated [[ ${status} == "locked" ]] || ! bitwarden_is_authenticated
fi fi

View File

@@ -113,7 +113,7 @@ install_kubectl() {
install_ligconsolata() { install_ligconsolata() {
curl -L -O https://github.com/googlefonts/Inconsolata/archive/refs/tags/v3.000.zip && unzip v3.000.zip \ curl -L -O https://github.com/googlefonts/Inconsolata/archive/refs/tags/v3.000.zip && unzip v3.000.zip \
&& cp Inconsolata-3.000/fonts/otf/*.otf "/usr/local/share/fonts/" && rm -rf Inconsolata-3.000 v3.000.zip && cp Inconsolata-3.000/fonts/ttf/*.ttf "/usr/local/share/fonts/" && rm -rf Inconsolata-3.000 v3.000.zip
} }
install_sops() { install_sops() {
@@ -124,6 +124,8 @@ install_sops() {
export EXTRA_INSTALL_MESSAGE="Installing snap packages" export EXTRA_INSTALL_MESSAGE="Installing snap packages"
extra_init() { extra_init() {
# Install ghostty # Install ghostty
ghostty=$(which ghostty >/dev/null 2>&1)
if [ $? -ne 0 ]; then
echo -ne "ghostty" echo -ne "ghostty"
# TODO: use a ppa / something updatable # TODO: use a ppa / something updatable
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/mkasberg/ghostty-ubuntu/HEAD/install.sh)" >/dev/null 2>&1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/mkasberg/ghostty-ubuntu/HEAD/install.sh)" >/dev/null 2>&1
@@ -131,6 +133,7 @@ extra_init() {
echo -e "${BRed}Could not install ghostty. Skipping.${NC}" echo -e "${BRed}Could not install ghostty. Skipping.${NC}"
fi fi
erase_text "ghostty" erase_text "ghostty"
fi
# Install 'ligconsolata' font # Install 'ligconsolata' font
install_ligconsolata >/dev/null 2>&1 install_ligconsolata >/dev/null 2>&1
@@ -157,6 +160,8 @@ extra_init() {
fi fi
# TODO: Install zen browser using official :) snap # TODO: Install zen browser using official :) snap
zen_browser=$(which zen-browser >/dev/null 2>&1)
if [ $? -ne 0 ]; then
echo -ne "zen-browser" echo -ne "zen-browser"
curl -L -O https://git.vhaudiquet.fr/vhaudiquet/zen-browser-snap/releases/download/testing/zen-browser_1.14.11b_amd64.snap >/dev/null 2>&1 curl -L -O https://git.vhaudiquet.fr/vhaudiquet/zen-browser-snap/releases/download/testing/zen-browser_1.14.11b_amd64.snap >/dev/null 2>&1
snap install ./zen-browser_1.14.11b_amd64.snap --dangerous >/dev/null 2>&1 snap install ./zen-browser_1.14.11b_amd64.snap --dangerous >/dev/null 2>&1
@@ -167,7 +172,10 @@ extra_init() {
erase_text "zen-browser" erase_text "zen-browser"
fi fi
rm -f ./zen-browser_1.14.11b_amd64.snap rm -f ./zen-browser_1.14.11b_amd64.snap
fi
github_cli=$(which gh >/dev/null 2>&1)
if [ $? -ne 0 ]; then
echo -ne "github-cli" echo -ne "github-cli"
install_github_cli >/dev/null 2>&1 install_github_cli >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@@ -176,8 +184,11 @@ extra_init() {
else else
erase_text "github-cli" erase_text "github-cli"
fi fi
fi
# Docker, Kubectl # Docker, Kubectl
docker=$(which docker >/dev/null 2>&1)
if [ $? -ne 0 ]; then
echo -ne "docker" echo -ne "docker"
install_docker >/dev/null 2>&1 install_docker >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@@ -186,7 +197,10 @@ extra_init() {
else else
erase_text "docker" erase_text "docker"
fi fi
fi
kubectl=$(which kubectl >/dev/null 2>&1)
if [ $? -ne 0 ]; then
echo -ne "kubectl" echo -ne "kubectl"
install_kubectl >/dev/null 2>&1 install_kubectl >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@@ -195,8 +209,11 @@ extra_init() {
else else
erase_text "kubectl" erase_text "kubectl"
fi fi
fi
# SOPS # SOPS
sops=$(which sops >/dev/null 2>&1)
if [ $? -ne 0 ]; then
echo -ne "sops" echo -ne "sops"
install_sops >/dev/null 2>&1 install_sops >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@@ -205,6 +222,7 @@ extra_init() {
else else
erase_text "sops" erase_text "sops"
fi fi
fi
} }
disable_unwanted_extensions() { disable_unwanted_extensions() {

View File

@@ -248,28 +248,46 @@ fi
if ! bitwarden_is_authenticated; then if ! bitwarden_is_authenticated; then
if [ ! -z "${BW_CLIENTID}" ] && [ ! -z "${BW_CLIENTSECRET}" ]; then if [ ! -z "${BW_CLIENTID}" ] && [ ! -z "${BW_CLIENTSECRET}" ]; then
BW_CLIENTID="${BW_CLIENTID}" BW_CLIENTSECRET="${BW_CLIENTSECRET}" bw login --apikey >/dev/null 2>&1 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
fi fi
if bitwarden_is_authenticated && bitwarden_is_locked; then if bitwarden_is_authenticated && bitwarden_is_locked; then
if [ ! -z "${BW_PASSWORD}" ]; then if [ ! -z "${BW_PASSWORD}" ]; then
export BW_SESSION=$(bw unlock --raw ${BW_PASSWORD}) 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
fi fi
if ! bitwarden_is_locked; then if ! bitwarden_is_locked; then
echo -n "Authenticating with bitwarden... "
echo -n "sync"
bw sync >/dev/null 2>&1 bw sync >/dev/null 2>&1
erase_text "sync"
# Connect github cli using GH_TOKEN special field, if needed # Connect github cli using GH_TOKEN special field, if needed
gh auth status >/dev/null 2>&1 gh auth status >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
GH_TOKEN=$(bw get item github.com |jq -r '.fields[]|select(.name=="GH_TOKEN")|.value') echo -n "github-cli"
if [ $? -ne 0 ] && [ ! -z GH_TOKEN ]; then 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_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
fi fi
# Obtain kubectl config # Obtain kubectl config
if [ ! -f "/home/${USERNAME}/.kube/config" ]; then if [ ! -f "/home/${USERNAME}/.kube/config" ]; then
echo -n "kubectl"
KUBE=$(bw get item kube) KUBE=$(bw get item kube)
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
sudo -u ${USERNAME} mkdir -p "/home/${USERNAME}/.kube/" 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') 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 bw get attachment "${ATTACHMENT_ID}" --itemid "${OBJECT_ID}" --raw >"/home/${USERNAME}/.kube/config" 2>/dev/null
if [ $? -ne 0 ]; then 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
fi fi
erase_text "kubectl"
fi fi
echo ""
fi fi
# VPN configuration # VPN configuration