Code Update

This commit is contained in:
Christer Warén 2024-05-09 13:26:22 +03:00
parent a6cb4ae626
commit 3618a34c41
4 changed files with 58 additions and 46 deletions

View File

@ -19,7 +19,6 @@ wxNormal=$(tput sgr0)
declare -Ax config declare -Ax config
{{ FUNCTIONS }} {{ FUNCTIONS }}
{{ COMMANDS }} {{ COMMANDS }}

View File

@ -3,20 +3,26 @@ wx-login(){
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]] if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]
then then
echo " >> Login << "
echo "------------------------------"
echo -n "Status: Hostname Required"
wx-stop wx-stop
fi fi
if [[ $(hostname -d) == "devices.waren.io" ]] if [[ ! -z $1 ]]
then
ORG=$1
elif [[ $(hostname -d) = *"devices.waren.io" ]]
then then
ORG=warengroup ORG=warengroup
elif [[ $(hostname -d) == "devices.cwinfo.net" || $(hostname -d) == "fr1.servers.devices.cwinfo.net" ]] elif [[ $(hostname -d) = *"devices.cwinfo.net" ]]
then then
ORG=cwinfo ORG=cwinfo
elif [[ $(hostname -d) == "devices.christerwaren.fi" ]] elif [[ $(hostname -d) = *"devices.christerwaren.fi" ]]
then then
ORG=cwchristerw ORG=cwchristerw
elif [[ -z $ORG ]] else
then
echo " >> Login << " echo " >> Login << "
echo "------------------------------" echo "------------------------------"
@ -43,16 +49,15 @@ wx-login(){
FOLDER=$ORG FOLDER=$ORG
DEVICE_DOMAIN="devices.$DOMAIN" DEVICE_DOMAIN="devices.$DOMAIN"
IDM_DOMAIN="idm.cwinfo.net" IDM_DOMAIN="idm.$DOMAIN"
VAULT_DOMAIN="vault.cwinfo.net" VAULT_DOMAIN="vault.cwinfo.net"
GIT_DOMAIN="git.cwinfo.net"
if [[ $(hostname -d) ]] if [[ ! -z $2 ]]
then
HOSTNAME=$(hostname --fqdn)
elif [[ -z $(hostname -d) ]] && [[ ! -z $2 ]]
then then
HOSTNAME="$2.$DEVICE_DOMAIN" HOSTNAME="$2.$DEVICE_DOMAIN"
elif [[ $(hostname -d) ]]
then
HOSTNAME=$(hostname --fqdn)
else else
echo " >> Login << " echo " >> Login << "
echo "------------------------------" echo "------------------------------"
@ -92,7 +97,8 @@ wx-login(){
if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]] if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]]
then then
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
echo '{ "login": { "'$ORG'": "'$VAULT_LOGIN'" } }' | jq > $HOME/.config/warengroup/config.json 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
else else
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN) IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
if [[ $IDM_STATUS -eq 301 ]] if [[ $IDM_STATUS -eq 301 ]]
@ -128,11 +134,8 @@ wx-login(){
fi fi
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mkdir -p $HOME/.config/warengroup &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
touch $HOME/.config/warengroup/config.json &> /dev/null
echo '{ "login": { "'$ORG'": "'$VAULT_LOGIN'" } }' | jq > $HOME/.config/warengroup/config.json
wx-start wx-start
fi fi
@ -160,11 +163,8 @@ wx-login(){
fi fi
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mkdir -p $HOME/.config/warengroup &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
touch $HOME/.config/warengroup/config.json &> /dev/null
echo '{ "login": { "'$ORG'": "'$VAULT_LOGIN'" } }' | jq > $HOME/.config/warengroup/config.json
wx-start wx-start
fi fi

View File

@ -7,4 +7,11 @@ wx-start(){
echo " Warén CLI " echo " Warén CLI "
echo -n "$wxNormal" echo -n "$wxNormal"
echo "==============================" echo "=============================="
mkdir -p $HOME/.config/warengroup &> /dev/null
if [[ ! -f "$HOME/.config/warengroup/config.json" ]]
then
echo '{}' | jq > $HOME/.config/warengroup/config.json
fi
} }

52
wx
View File

@ -19,26 +19,31 @@ wxNormal=$(tput sgr0)
declare -Ax config declare -Ax config
wx-login(){ wx-login(){
ORG=$1 ORG=$1
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]] if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]
then then
echo " >> Login << "
echo "------------------------------"
echo -n "Status: Hostname Required"
wx-stop wx-stop
fi fi
if [[ $(hostname -d) == "devices.waren.io" ]] if [[ ! -z $1 ]]
then
ORG=$1
elif [[ $(hostname -d) = *"devices.waren.io" ]]
then then
ORG=warengroup ORG=warengroup
elif [[ $(hostname -d) == "devices.cwinfo.net" || $(hostname -d) == "fr1.servers.devices.cwinfo.net" ]] elif [[ $(hostname -d) = *"devices.cwinfo.net" ]]
then then
ORG=cwinfo ORG=cwinfo
elif [[ $(hostname -d) == "devices.christerwaren.fi" ]] elif [[ $(hostname -d) = *"devices.christerwaren.fi" ]]
then then
ORG=cwchristerw ORG=cwchristerw
elif [[ -z $ORG ]] else
then
echo " >> Login << " echo " >> Login << "
echo "------------------------------" echo "------------------------------"
@ -65,16 +70,15 @@ wx-login(){
FOLDER=$ORG FOLDER=$ORG
DEVICE_DOMAIN="devices.$DOMAIN" DEVICE_DOMAIN="devices.$DOMAIN"
IDM_DOMAIN="idm.cwinfo.net" IDM_DOMAIN="idm.$DOMAIN"
VAULT_DOMAIN="vault.cwinfo.net" VAULT_DOMAIN="vault.cwinfo.net"
GIT_DOMAIN="git.cwinfo.net"
if [[ $(hostname -d) ]] if [[ ! -z $2 ]]
then
HOSTNAME=$(hostname --fqdn)
elif [[ -z $(hostname -d) ]] && [[ ! -z $2 ]]
then then
HOSTNAME="$2.$DEVICE_DOMAIN" HOSTNAME="$2.$DEVICE_DOMAIN"
elif [[ $(hostname -d) ]]
then
HOSTNAME=$(hostname --fqdn)
else else
echo " >> Login << " echo " >> Login << "
echo "------------------------------" echo "------------------------------"
@ -114,7 +118,8 @@ wx-login(){
if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]] if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]]
then then
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
echo '{ "login": { "'$ORG'": "'$VAULT_LOGIN'" } }' | jq > $HOME/.config/warengroup/config.json 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
else else
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN) IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
if [[ $IDM_STATUS -eq 301 ]] if [[ $IDM_STATUS -eq 301 ]]
@ -150,11 +155,8 @@ wx-login(){
fi fi
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mkdir -p $HOME/.config/warengroup &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
touch $HOME/.config/warengroup/config.json &> /dev/null
echo '{ "login": { "'$ORG'": "'$VAULT_LOGIN'" } }' | jq > $HOME/.config/warengroup/config.json
wx-start wx-start
fi fi
@ -182,11 +184,8 @@ wx-login(){
fi fi
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mkdir -p $HOME/.config/warengroup &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
touch $HOME/.config/warengroup/config.json &> /dev/null
echo '{ "login": { "'$ORG'": "'$VAULT_LOGIN'" } }' | jq > $HOME/.config/warengroup/config.json
wx-start wx-start
fi fi
@ -211,6 +210,13 @@ wx-start(){
echo " Warén CLI " echo " Warén CLI "
echo -n "$wxNormal" echo -n "$wxNormal"
echo "==============================" echo "=============================="
mkdir -p $HOME/.config/warengroup &> /dev/null
if [[ ! -f "$HOME/.config/warengroup/config.json" ]]
then
echo '{}' | jq > $HOME/.config/warengroup/config.json
fi
} }
wx-stop (){ wx-stop (){