Code Update

This commit is contained in:
Christer Warén 2024-06-01 01:53:48 +03:00
parent a614d63d1c
commit e1b05fbc51
6 changed files with 40 additions and 28 deletions

View File

@ -2,7 +2,7 @@ wx-auto(){
wx-login wx-login
wx-header "Auto" wx-header "Auto"
wx-ssh-config-sync wx-ssh-config sync
wx-ssh-keys-sync wx-ssh-keys sync
wx-ssh-sign wx-ssh-sign
} }

View File

@ -73,6 +73,8 @@ wx-login(){
else else
USERNAME=$SUDO_USER USERNAME=$SUDO_USER
fi fi
else
USERNAME=$USER
fi fi
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health) VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health)
@ -90,7 +92,7 @@ wx-login(){
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
if [[ $USER != "root" && $USER != "local" ]] if [[ $USER != "root" && $USER != "local" ]]
then then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json 1> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi fi
else else
@ -131,8 +133,6 @@ wx-login(){
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi fi
wx-start
fi fi
else else
wx-header "Login" wx-header "Login"
@ -162,8 +162,6 @@ wx-login(){
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi fi
wx-start
fi fi
fi fi
else else

View File

@ -1,3 +1,8 @@
wx-logout(){ wx-logout(){
wx-header "Logout" wx-header "Logout"
if [[ $USER != "root" && $USER != "local" ]]
then
jq '.login = {}' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi
} }

View File

@ -1,6 +1,9 @@
wx-header(){ wx-header(){
if [[ $2 == "h1" ]] if [[ $2 == "h1" ]]
then then
echo ""
echo ""
echo ""
echo "==============================" echo "=============================="
wx-repeat " " $((30/2-${#1}/2)) wx-repeat " " $((30/2-${#1}/2))
echo -n "$wxBold" echo -n "$wxBold"

View File

@ -1,13 +1,13 @@
wx-start(){ wx-start(){
echo ""
echo ""
echo ""
wx-header "Warén CLI" h1 wx-header "Warén CLI" h1
if [[ $USER != "root" && $USER != "local" ]]
then
mkdir -p $HOME/.config/warengroup &> /dev/null mkdir -p $HOME/.config/warengroup &> /dev/null
if [[ ! -f "$HOME/.config/warengroup/config.json" ]] if [[ ! -f "$HOME/.config/warengroup/config.json" ]]
then then
echo '{}' | jq > $HOME/.config/warengroup/config.json echo '{}' | jq > $HOME/.config/warengroup/config.json
fi fi
fi
} }

26
wx
View File

@ -22,6 +22,9 @@ declare -Ax config
wx-header(){ wx-header(){
if [[ $2 == "h1" ]] if [[ $2 == "h1" ]]
then then
echo ""
echo ""
echo ""
echo "==============================" echo "=============================="
wx-repeat " " $((30/2-${#1}/2)) wx-repeat " " $((30/2-${#1}/2))
echo -n "$wxBold" echo -n "$wxBold"
@ -59,17 +62,17 @@ wx-restricted(){
} }
wx-start(){ wx-start(){
echo ""
echo ""
echo ""
wx-header "Warén CLI" h1 wx-header "Warén CLI" h1
if [[ $USER != "root" && $USER != "local" ]]
then
mkdir -p $HOME/.config/warengroup &> /dev/null mkdir -p $HOME/.config/warengroup &> /dev/null
if [[ ! -f "$HOME/.config/warengroup/config.json" ]] if [[ ! -f "$HOME/.config/warengroup/config.json" ]]
then then
echo '{}' | jq > $HOME/.config/warengroup/config.json echo '{}' | jq > $HOME/.config/warengroup/config.json
fi fi
fi
} }
wx-stop (){ wx-stop (){
@ -86,8 +89,8 @@ wx-auto(){
wx-login wx-login
wx-header "Auto" wx-header "Auto"
wx-ssh-config-sync wx-ssh-config sync
wx-ssh-keys-sync wx-ssh-keys sync
wx-ssh-sign wx-ssh-sign
} }
@ -258,6 +261,8 @@ wx-login(){
else else
USERNAME=$SUDO_USER USERNAME=$SUDO_USER
fi fi
else
USERNAME=$USER
fi fi
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health) VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health)
@ -275,7 +280,7 @@ wx-login(){
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
if [[ $USER != "root" && $USER != "local" ]] if [[ $USER != "root" && $USER != "local" ]]
then then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json 1> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi fi
else else
@ -316,8 +321,6 @@ wx-login(){
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi fi
wx-start
fi fi
else else
wx-header "Login" wx-header "Login"
@ -347,8 +350,6 @@ wx-login(){
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi fi
wx-start
fi fi
fi fi
else else
@ -361,6 +362,11 @@ wx-login(){
wx-logout(){ wx-logout(){
wx-header "Logout" wx-header "Logout"
if [[ $USER != "root" && $USER != "local" ]]
then
jq '.login = {}' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi
} }
wx-settings(){ wx-settings(){