mirror of
https://github.com/vhaudiquet/mymachine.git
synced 2025-12-18 12:06:06 +00:00
Multiple Bitwarden fixes, small changes
This commit is contained in:
15
bitwarden.sh
15
bitwarden.sh
@@ -1,19 +1,24 @@
|
|||||||
#!/usr/bin/env bash
|
#!/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() {
|
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
|
if [ -z "${status}" ]; then
|
||||||
return false
|
false
|
||||||
else
|
else
|
||||||
[[ ! ${status} == "unauthenticated" ]]
|
[[ ! ${status} == "unauthenticated" ]]
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
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
|
||||||
return true
|
true
|
||||||
else
|
else
|
||||||
[[ ${status} == "locked" ]] || ! bitwarden_is_authenticated
|
[[ ${status} == "locked" ]] || ! bitwarden_is_authenticated
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -37,3 +37,5 @@ WHEEL_GROUP="wheel"
|
|||||||
|
|
||||||
configure_pacman
|
configure_pacman
|
||||||
create_user
|
create_user
|
||||||
|
|
||||||
|
export BITWARDENCLI_APPDATA_DIR="/home/${USERNAME}/.config/Bitwarden CLI"
|
||||||
|
|||||||
@@ -5,3 +5,5 @@ WHEEL_GROUP="sudo"
|
|||||||
# Enable docker IPv4 forwarding, to allow LXD to work along it :)
|
# Enable docker IPv4 forwarding, to allow LXD to work along it :)
|
||||||
echo "net.ipv4.conf.all.forwarding=1" > /etc/sysctl.d/99-forwarding.conf
|
echo "net.ipv4.conf.all.forwarding=1" > /etc/sysctl.d/99-forwarding.conf
|
||||||
sysctl net.ipv4.conf.all.forwarding=1 >/dev/null 2>&1
|
sysctl net.ipv4.conf.all.forwarding=1 >/dev/null 2>&1
|
||||||
|
|
||||||
|
export BITWARDENCLI_APPDATA_DIR="/home/${USERNAME}/snap/bw/current/Bitwarden CLI"
|
||||||
|
|||||||
@@ -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/517/caffeine/
|
||||||
https://extensions.gnome.org/extension/3843/just-perfection/
|
https://extensions.gnome.org/extension/3843/just-perfection/
|
||||||
https://extensions.gnome.org/extension/4099/no-overview/
|
https://extensions.gnome.org/extension/4099/no-overview/
|
||||||
|
https://extensions.gnome.org/extension/1460/vitals/
|
||||||
|
|||||||
1
gnome.sh
1
gnome.sh
@@ -169,7 +169,6 @@ fi
|
|||||||
|
|
||||||
# Enable needed default extensions
|
# Enable needed default extensions
|
||||||
${DBUS_LAUNCH} gnome-extensions enable user-theme@gnome-shell-extensions.gcampax.github.com
|
${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..."
|
echo "Setting up Gnome settings..."
|
||||||
|
|
||||||
|
|||||||
27
mymachine.sh
27
mymachine.sh
@@ -247,7 +247,8 @@ fi
|
|||||||
# Login to Bitwarden
|
# Login to Bitwarden
|
||||||
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
|
echo "Login in to Bitwarden..."
|
||||||
|
BW_CLIENTID="${BW_CLIENTID}" BW_CLIENTSECRET="${BW_CLIENTSECRET}" BW login --apikey >/dev/null
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo -e "${BRed}Could not login to Bitwarden. Skipping.${NC}"
|
echo -e "${BRed}Could not login to Bitwarden. Skipping.${NC}"
|
||||||
fi
|
fi
|
||||||
@@ -257,7 +258,8 @@ if ! bitwarden_is_authenticated; then
|
|||||||
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})
|
echo "Unlocking Bitwarden vault..."
|
||||||
|
export BW_SESSION=$(BW unlock --raw ${BW_PASSWORD})
|
||||||
if [ -z "${BW_SESSION}" ]; then
|
if [ -z "${BW_SESSION}" ]; then
|
||||||
echo -e "${BRed}Could not unlock Bitwarden vault. Skipping.${NC}"
|
echo -e "${BRed}Could not unlock Bitwarden vault. Skipping.${NC}"
|
||||||
fi
|
fi
|
||||||
@@ -267,18 +269,23 @@ if ! bitwarden_is_locked; then
|
|||||||
echo -n "Authenticating with bitwarden... "
|
echo -n "Authenticating with bitwarden... "
|
||||||
|
|
||||||
echo -n "sync"
|
echo -n "sync"
|
||||||
bw sync >/dev/null 2>&1
|
BW sync >/dev/null 2>&1
|
||||||
erase_text "sync"
|
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
|
sudo -u ${USERNAME} gh auth status >/dev/null 2>&1
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo -n "github-cli"
|
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
|
if [ $? -eq 0 ] && [ ! -z "${GH_TOKEN}" ]; then
|
||||||
GH_TOKEN="${GH_TOKEN}" gh auth login -p https -h github.com >/dev/null 2>&1
|
echo "${GH_TOKEN}" |sudo -u ${USERNAME} gh auth login -p https -h github.com --with-token 2>/dev/null
|
||||||
gh auth setup-git --hostname github.com >/dev/null 2>&1
|
if [ $? -ne 0 ]; then
|
||||||
erase_text "github-cli"
|
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
|
else
|
||||||
erase_text "github-cli"
|
erase_text "github-cli"
|
||||||
echo -ne "${BRed}github-cli${NC} "
|
echo -ne "${BRed}github-cli${NC} "
|
||||||
@@ -288,12 +295,12 @@ if ! bitwarden_is_locked; then
|
|||||||
# Obtain kubectl config
|
# Obtain kubectl config
|
||||||
if [ ! -f "/home/${USERNAME}/.kube/config" ]; then
|
if [ ! -f "/home/${USERNAME}/.kube/config" ]; then
|
||||||
echo -n "kubectl"
|
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/"
|
||||||
OBJECT_ID=$(echo "${KUBE}" |jq -r '.id')
|
OBJECT_ID=$(echo "${KUBE}" |jq -r '.id')
|
||||||
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 "\n${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
|
||||||
|
|||||||
Reference in New Issue
Block a user