#!/usr/bin/env bash

#source ~/.bw-agent

#BW_STATUS="`bw status`"

#if [ "`echo $BW_STATUS | grep unauthenticated`" != "" ]
#then
#	bw config server https://bw.sebeka.k12.mn.us
#	bw login
#fi

source ~/.rcs/bash_prompt/bw/bw-unlock.sh

BW_STATUS="`bw status`"
if [ "`echo $BW_STATUS | grep unlocked`" = "" ]
then
	echo "Bitwarden vault is locked, enter master password"
	`bw unlock | grep export | cut -d "$" -f2 | tr -s " "` && bw sync
else
	#echo "Bitwarden sync"
	bw sync
fi
HOSTNAME=`hostname`
ROOT_PW=`bw get password root@${HOSTNAME}`
if [ "$ROOT_PW" != "Not found." ] && [ "$ROOT_PW" != "" ]
then
	echo "Found su record"
	export BW_PWD="${ROOT_PW}"
	~/.rcs/bash_prompt/bw/expect_su_script
else
	echo "No reound found for root@${HOSTNAME}"
fi
