diff --git a/bitwarden.sh b/bitwarden.sh index 9ba7c17..5545648 100644 --- a/bitwarden.sh +++ b/bitwarden.sh @@ -1,19 +1,24 @@ #!/usr/bin/env bash -alias bw="sudo -u ${USERNAME} bw" +BW() { + sudo -u ${USERNAME} \ + BW_CLIENTID="${BW_CLIENTID}" BW_CLIENTSECRET="${BW_CLIENTSECRET}" \ + BW_PASSWORD="${BW_PASSWORD}" BW_SESSION=${BW_SESSION} BITWARDENCLI_APPDATA_DIR="${BITWARDENCLI_APPDATA_DIR}" \ + bw $@ 2>/dev/null +} bitwarden_is_authenticated() { - status=$(bw status 2>/dev/null |jq -r ".status" 2>/dev/null) + status=$(BW status |jq -r ".status" 2>/dev/null) if [ -z "${status}" ]; then - return false + false else [[ ! ${status} == "unauthenticated" ]] fi } 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 - return true + true else [[ ${status} == "locked" ]] || ! bitwarden_is_authenticated fi diff --git a/distribution/arch/initial_config.sh b/distribution/arch/initial_config.sh index 3d8e7c1..28d520a 100644 --- a/distribution/arch/initial_config.sh +++ b/distribution/arch/initial_config.sh @@ -37,3 +37,5 @@ WHEEL_GROUP="wheel" configure_pacman create_user + +export BITWARDENCLI_APPDATA_DIR="/home/${USERNAME}/.config/Bitwarden CLI" diff --git a/distribution/ubuntu/initial_config.sh b/distribution/ubuntu/initial_config.sh index 7ea1a8f..d2120fe 100644 --- a/distribution/ubuntu/initial_config.sh +++ b/distribution/ubuntu/initial_config.sh @@ -5,3 +5,5 @@ WHEEL_GROUP="sudo" # Enable docker IPv4 forwarding, to allow LXD to work along it :) echo "net.ipv4.conf.all.forwarding=1" > /etc/sysctl.d/99-forwarding.conf sysctl net.ipv4.conf.all.forwarding=1 >/dev/null 2>&1 + +export BITWARDENCLI_APPDATA_DIR="/home/${USERNAME}/snap/bw/current/Bitwarden CLI" diff --git a/gnome-extensions.txt b/gnome-extensions.txt index ca512fa..8402e8c 100644 --- a/gnome-extensions.txt +++ b/gnome-extensions.txt @@ -4,3 +4,4 @@ https://extensions.gnome.org/extension/2645/brightness-control-using-ddcutil/ https://extensions.gnome.org/extension/517/caffeine/ https://extensions.gnome.org/extension/3843/just-perfection/ https://extensions.gnome.org/extension/4099/no-overview/ +https://extensions.gnome.org/extension/1460/vitals/ diff --git a/gnome.sh b/gnome.sh index d4c86c6..14c5347 100644 --- a/gnome.sh +++ b/gnome.sh @@ -169,7 +169,6 @@ fi # Enable needed default extensions ${DBUS_LAUNCH} gnome-extensions enable user-theme@gnome-shell-extensions.gcampax.github.com -${DBUS_LAUNCH} gnome-extensions enable system-monitor@gnome-shell-extensions.gcampax.github.com echo "Setting up Gnome settings..." diff --git a/mymachine.sh b/mymachine.sh index b5afe14..b5ab68d 100755 --- a/mymachine.sh +++ b/mymachine.sh @@ -247,7 +247,8 @@ fi # Login to Bitwarden 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 + 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 @@ -257,7 +258,8 @@ if ! bitwarden_is_authenticated; then fi if bitwarden_is_authenticated && bitwarden_is_locked; then if [ ! -z "${BW_PASSWORD}" ]; then - export BW_SESSION=$(bw unlock --raw ${BW_PASSWORD}) + 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 @@ -267,18 +269,23 @@ 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 - gh auth status >/dev/null 2>&1 + sudo -u ${USERNAME} gh auth status >/dev/null 2>&1 if [ $? -ne 0 ]; 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) + GH_TOKEN=$(BW get item github.com |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 >/dev/null 2>&1 - erase_text "github-cli" + echo "${GH_TOKEN}" |sudo -u ${USERNAME} gh auth login -p https -h github.com --with-token 2>/dev/null + if [ $? -ne 0 ]; then + erase_text "github-cli" + echo -ne "${BRed}github-cli${NC} " + else + sudo -u ${USERNAME} gh auth setup-git --hostname github.com >/dev/null 2>&1 + erase_text "github-cli" + fi else erase_text "github-cli" echo -ne "${BRed}github-cli${NC} " @@ -288,12 +295,12 @@ if ! bitwarden_is_locked; then # Obtain kubectl config if [ ! -f "/home/${USERNAME}/.kube/config" ]; then echo -n "kubectl" - KUBE=$(bw get item kube) + KUBE=$(BW get item kube) if [ $? -eq 0 ]; then sudo -u ${USERNAME} mkdir -p "/home/${USERNAME}/.kube/" OBJECT_ID=$(echo "${KUBE}" |jq -r '.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 echo -e "\n${BRed}Could not get .kube/config attachment from bitwarden. Skipping.${NC}" fi