Code Update

This commit is contained in:
Christer Warén 2024-05-18 00:09:58 +03:00
parent d9c370ad91
commit e1a31d2497
2 changed files with 80 additions and 44 deletions

62
init.sh
View File

@ -65,31 +65,34 @@ wi-init(){
} }
wi-login(){ wi-login(){
echo -n "$wiItalic"
echo " >> Login << "
echo -n "$wiNormal";
echo "------------------------------"
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"
wi-stop wi-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 -n "Status: Organization Required" echo "------------------------------"
echo -n "Status: Organization Required"
wi-stop wi-stop
fi fi
@ -103,26 +106,28 @@ wi-login(){
then then
DOMAIN=christerwaren.fi DOMAIN=christerwaren.fi
else else
echo -n "Status: Organization Unsupported" echo " >> Login << "
echo "------------------------------"
echo -n "Status: Organization Unsupported"
wi-stop wi-stop
fi fi
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"
GIT_PORT=2222
GIT_REPOSITORY="warengroup-private/infra-plus"
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 "------------------------------"
echo -n "Status: Hostname Required" echo -n "Status: Hostname Required"
wi-stop wi-stop
fi fi
@ -133,6 +138,9 @@ wi-login(){
then then
if [[ -z LOGNAME ]] if [[ -z LOGNAME ]]
then then
echo " >> Login << "
echo "------------------------------"
echo -n "Status: Username Required" echo -n "Status: Username Required"
wi-stop wi-stop
else else
@ -146,9 +154,13 @@ wi-login(){
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)
if [[ $VAULT_STATUS -eq 200 ]] if [[ $VAULT_STATUS -eq 200 ]]
then 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) IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
if [[ $IDM_STATUS -eq 301 ]] if [[ $IDM_STATUS -eq 301 ]]
then then
echo " >> Login << "
echo "------------------------------"
echo $wiBold$ORG$wiNormal echo $wiBold$ORG$wiNormal
if [[ -z $USER || $USER == "root" || $USER == "local" ]] if [[ -z $USER || $USER == "root" || $USER == "local" ]]
@ -176,10 +188,13 @@ wi-login(){
wi-stop wi-stop
fi fi
HVT=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
wi-start wi-start
fi fi
else else
echo " >> Login << "
echo "------------------------------"
echo $wiBold$ORG$wiNormal echo $wiBold$ORG$wiNormal
echo -n "Token: " echo -n "Token: "
@ -199,10 +214,13 @@ wi-login(){
wi-stop wi-stop
fi fi
HVT=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
wi-start wi-start
fi fi
else else
echo " >> Login << "
echo "------------------------------"
echo $wiBold$ORG$wiNormal echo $wiBold$ORG$wiNormal
echo -n "Status: Vault Offline" echo -n "Status: Vault Offline"

View File

@ -1,29 +1,32 @@
wi-login(){ wi-login(){
echo -n "$wiItalic"
echo " >> Login << "
echo -n "$wiNormal";
echo "------------------------------"
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"
wi-stop wi-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 -n "Status: Organization Required" echo "------------------------------"
echo -n "Status: Organization Required"
wi-stop wi-stop
fi fi
@ -37,26 +40,28 @@ wi-login(){
then then
DOMAIN=christerwaren.fi DOMAIN=christerwaren.fi
else else
echo -n "Status: Organization Unsupported" echo " >> Login << "
echo "------------------------------"
echo -n "Status: Organization Unsupported"
wi-stop wi-stop
fi fi
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"
GIT_PORT=2222
GIT_REPOSITORY="warengroup-private/infra-plus"
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 "------------------------------"
echo -n "Status: Hostname Required" echo -n "Status: Hostname Required"
wi-stop wi-stop
fi fi
@ -67,6 +72,9 @@ wi-login(){
then then
if [[ -z LOGNAME ]] if [[ -z LOGNAME ]]
then then
echo " >> Login << "
echo "------------------------------"
echo -n "Status: Username Required" echo -n "Status: Username Required"
wi-stop wi-stop
else else
@ -80,9 +88,13 @@ wi-login(){
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)
if [[ $VAULT_STATUS -eq 200 ]] if [[ $VAULT_STATUS -eq 200 ]]
then 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) IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
if [[ $IDM_STATUS -eq 301 ]] if [[ $IDM_STATUS -eq 301 ]]
then then
echo " >> Login << "
echo "------------------------------"
echo $wiBold$ORG$wiNormal echo $wiBold$ORG$wiNormal
if [[ -z $USER || $USER == "root" || $USER == "local" ]] if [[ -z $USER || $USER == "root" || $USER == "local" ]]
@ -110,10 +122,13 @@ wi-login(){
wi-stop wi-stop
fi fi
HVT=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
wi-start wi-start
fi fi
else else
echo " >> Login << "
echo "------------------------------"
echo $wiBold$ORG$wiNormal echo $wiBold$ORG$wiNormal
echo -n "Token: " echo -n "Token: "
@ -133,10 +148,13 @@ wi-login(){
wi-stop wi-stop
fi fi
HVT=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
wi-start wi-start
fi fi
else else
echo " >> Login << "
echo "------------------------------"
echo $wiBold$ORG$wiNormal echo $wiBold$ORG$wiNormal
echo -n "Status: Vault Offline" echo -n "Status: Vault Offline"