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
{{ FUNCTIONS }}
{{ COMMANDS }}

View File

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

View File

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