From e1a31d24971257d5e01514f61a5f526242a19d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sat, 18 May 2024 00:09:58 +0300 Subject: [PATCH] Code Update --- init.sh | 62 +++++++++++++++++++++++++++--------------- src/functions/login.sh | 62 +++++++++++++++++++++++++++--------------- 2 files changed, 80 insertions(+), 44 deletions(-) diff --git a/init.sh b/init.sh index 1656e93..82ec661 100755 --- a/init.sh +++ b/init.sh @@ -65,31 +65,34 @@ wi-init(){ } wi-login(){ - echo -n "$wiItalic" - echo " >> Login << " - echo -n "$wiNormal"; - echo "------------------------------" - ORG=$1 if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]] then + echo " >> Login << " + echo "------------------------------" + + echo -n "Status: Hostname Required" wi-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 - echo -n "Status: Organization Required" + else + echo " >> Login << " + echo "------------------------------" + echo -n "Status: Organization Required" wi-stop fi @@ -103,26 +106,28 @@ wi-login(){ then DOMAIN=christerwaren.fi else - echo -n "Status: Organization Unsupported" + echo " >> Login << " + echo "------------------------------" + echo -n "Status: Organization Unsupported" wi-stop fi 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" - GIT_PORT=2222 - GIT_REPOSITORY="warengroup-private/infra-plus" - 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 "------------------------------" + echo -n "Status: Hostname Required" wi-stop fi @@ -133,6 +138,9 @@ wi-login(){ then if [[ -z LOGNAME ]] then + echo " >> Login << " + echo "------------------------------" + echo -n "Status: Username Required" wi-stop else @@ -146,9 +154,13 @@ wi-login(){ VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health) if [[ $VAULT_STATUS -eq 200 ]] then + VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/token/renew -X POST --header "X-Vault-Token: $TOKEN" -d '{ "token": "'$TOKEN'" }' -s | jq -r '.auth.client_token') IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN) if [[ $IDM_STATUS -eq 301 ]] then + echo " >> Login << " + echo "------------------------------" + echo $wiBold$ORG$wiNormal if [[ -z $USER || $USER == "root" || $USER == "local" ]] @@ -176,10 +188,13 @@ wi-login(){ wi-stop fi - HVT=$VAULT_LOGIN + config["login",${ORG}]=$VAULT_LOGIN wi-start fi else + echo " >> Login << " + echo "------------------------------" + echo $wiBold$ORG$wiNormal echo -n "Token: " @@ -199,10 +214,13 @@ wi-login(){ wi-stop fi - HVT=$VAULT_LOGIN + config["login",${ORG}]=$VAULT_LOGIN wi-start fi else + echo " >> Login << " + echo "------------------------------" + echo $wiBold$ORG$wiNormal echo -n "Status: Vault Offline" diff --git a/src/functions/login.sh b/src/functions/login.sh index 6414640..13c1a5c 100644 --- a/src/functions/login.sh +++ b/src/functions/login.sh @@ -1,29 +1,32 @@ wi-login(){ - echo -n "$wiItalic" - echo " >> Login << " - echo -n "$wiNormal"; - echo "------------------------------" - ORG=$1 if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]] then + echo " >> Login << " + echo "------------------------------" + + echo -n "Status: Hostname Required" wi-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 - echo -n "Status: Organization Required" + else + echo " >> Login << " + echo "------------------------------" + echo -n "Status: Organization Required" wi-stop fi @@ -37,26 +40,28 @@ wi-login(){ then DOMAIN=christerwaren.fi else - echo -n "Status: Organization Unsupported" + echo " >> Login << " + echo "------------------------------" + echo -n "Status: Organization Unsupported" wi-stop fi 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" - GIT_PORT=2222 - GIT_REPOSITORY="warengroup-private/infra-plus" - 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 "------------------------------" + echo -n "Status: Hostname Required" wi-stop fi @@ -67,6 +72,9 @@ wi-login(){ then if [[ -z LOGNAME ]] then + echo " >> Login << " + echo "------------------------------" + echo -n "Status: Username Required" wi-stop else @@ -80,9 +88,13 @@ wi-login(){ VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health) if [[ $VAULT_STATUS -eq 200 ]] then + VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/token/renew -X POST --header "X-Vault-Token: $TOKEN" -d '{ "token": "'$TOKEN'" }' -s | jq -r '.auth.client_token') IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN) if [[ $IDM_STATUS -eq 301 ]] then + echo " >> Login << " + echo "------------------------------" + echo $wiBold$ORG$wiNormal if [[ -z $USER || $USER == "root" || $USER == "local" ]] @@ -110,10 +122,13 @@ wi-login(){ wi-stop fi - HVT=$VAULT_LOGIN + config["login",${ORG}]=$VAULT_LOGIN wi-start fi else + echo " >> Login << " + echo "------------------------------" + echo $wiBold$ORG$wiNormal echo -n "Token: " @@ -133,10 +148,13 @@ wi-login(){ wi-stop fi - HVT=$VAULT_LOGIN + config["login",${ORG}]=$VAULT_LOGIN wi-start fi else + echo " >> Login << " + echo "------------------------------" + echo $wiBold$ORG$wiNormal echo -n "Status: Vault Offline"