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(){
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"

View File

@ -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"