Code Update

This commit is contained in:
Christer Warén 2024-06-01 14:47:24 +03:00
parent d6344baf70
commit 9387e15062
12 changed files with 311 additions and 187 deletions

7
build.sh Normal file → Executable file
View File

@ -5,20 +5,21 @@ if [ ! "$BASH_VERSION" ] ; then
exit 1
fi
wiBold=$(tput bold)
wiNormal=$(tput sgr0)
echo ""
echo ""
echo ""
echo "=============================="
echo -n "$wiBold"
echo " Warén Group "
echo " Init.sh "
echo -n "$wiNormal"
echo "=============================="
echo " >> Build << "
echo " >> Init << "
echo "------------------------------"
podman run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp docker.io/library/php:8-cli php generator.php &> /dev/null
chmod +x init.sh &> /dev/null
echo "=============================="
echo " "
echo " "
echo " "

184
init.sh
View File

@ -13,15 +13,60 @@ wiPurple=$(tput setaf 165)
wiTurquoise=$(tput setaf 14)
wiPink=$(tput setaf 198)
wiOrange=$(tput setaf 202)
wiUnderline=$(tput smul)
wiBold=$(tput bold)
wiNormal=$(tput sgr0)
wi-header(){
wx-header $1 $2
}
wi-repeat(){
wx-repeat $1 $2
}
wi-login(){
wx-login $1 $2
}
wx-stop(){
wi-stop
}
wi-delete(){
if [[ -f "init.sh" ]]
then
rm init.sh
fi
}
wx-header(){
if [[ $2 == "h1" ]]
then
echo ""
echo ""
echo ""
echo "=============================="
wx-repeat " " $((30/2-${#1}/2))
echo -n "$wxBold"
echo -n "$1"
echo -n "$wxNormal"
echo ""
echo "=============================="
fi
if [[ $2 == "h2" || -z $2 ]]
then
wx-start
wx-repeat " " $((30/2-6/2-${#1}/2))
echo -n ">> $1 <<"
echo ""
echo "------------------------------"
fi
}
wi-init(){
wi-login $1 $2
echo " >> Init << "
echo "------------------------------"
wi-header "Init"
mkdir -p ~/.ssh &> /dev/null
@ -71,16 +116,14 @@ wi-init(){
unset HVT
}
wi-login(){
wx-login(){
ORG=$1
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]
then
echo " >> Login << "
echo "------------------------------"
wx-header "Login"
echo "Status: Hostname Required"
wi-stop
wx-stop
fi
if [[ ! -z $1 ]]
@ -96,11 +139,9 @@ wi-login(){
then
ORG=cwchristerw
else
echo " >> Login << "
echo "------------------------------"
wx-header "Login"
echo "Status: Organization Required"
wi-stop
wx-stop
fi
if [[ $ORG == "warengroup" ]]
@ -113,11 +154,9 @@ wi-login(){
then
DOMAIN=christerwaren.fi
else
echo " >> Login << "
echo "------------------------------"
wx-header "Login"
echo "Status: Organization Unsupported"
wi-stop
wx-stop
fi
FOLDER=$ORG
@ -132,11 +171,9 @@ wi-login(){
then
HOSTNAME=$(hostname --fqdn)
else
echo " >> Login << "
echo "------------------------------"
wx-header "Login"
echo "Status: Hostname Required"
wi-stop
wx-stop
fi
if [[ -z $USER || $USER == "root" || $USER == "local" ]]
@ -145,38 +182,50 @@ wi-login(){
then
if [[ -z LOGNAME ]]
then
echo " >> Login << "
echo "------------------------------"
wx-header "Login"
echo "Status: Username Required"
wi-stop
wx-stop
else
USER=$LOGNAME
USERNAME=$LOGNAME
fi
else
USER=$SUDO_USER
USERNAME=$SUDO_USER
fi
else
USERNAME=$USER
fi
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health)
if [[ $VAULT_STATUS -eq 200 ]]
then
if [[ $USER != "root" && $USER != "local" && -f "$HOME/.config/warengroup/config.json" ]]
then
TOKEN="$(cat $HOME/.config/warengroup/config.json | jq -r .login.$ORG)"
fi
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')
if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]]
then
config["login",${ORG}]=$VAULT_LOGIN
if [[ $USER != "root" && $USER != "local" ]]
then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json 1> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi
else
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
if [[ $IDM_STATUS -eq 301 ]]
then
echo " >> Login << "
echo "------------------------------"
wx-header "Login"
echo $wxBold$ORG$wxNormal
echo $wiBold$ORG$wiNormal
if [[ -z $USER || $USER == "root" || $USER == "local" ]]
if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" ]]
then
echo -n "Username: "
read USERNAME
else
echo "Username: $USER"
USERNAME=$USER
echo "Username: $USERNAME"
fi
echo -n "Password: "
@ -186,23 +235,26 @@ wi-login(){
if [[ -z $USERNAME || -z $PASSWORD ]]
then
echo "Status: Username & Password Required"
wi-stop
wx-stop
else
VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/ldap/login/$USERNAME -X POST -d '{ "password": "'$PASSWORD'" }' -s | jq -r '.auth.client_token')
if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
then
echo "Status: Login Failed"
wi-stop
wx-stop
fi
config["login",${ORG}]=$VAULT_LOGIN
wi-start
if [[ $USER != "root" && $USER != "local" ]]
then
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
fi
fi
else
echo " >> Login << "
echo "------------------------------"
echo $wiBold$ORG$wiNormal
wx-header "Login"
echo $wxBold$ORG$wxNormal
echo -n "Token: "
read -s TOKEN
@ -211,51 +263,63 @@ wi-login(){
if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]]
then
echo "Status: Vault Token Required"
wi-stop
wx-stop
fi
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')
if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
then
echo "Status: Login Failed"
wi-stop
wx-stop
fi
config["login",${ORG}]=$VAULT_LOGIN
wi-start
if [[ $USER != "root" && $USER != "local" ]]
then
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
fi
fi
fi
else
echo " >> Login << "
echo "------------------------------"
echo $wiBold$ORG$wiNormal
wx-header "Login"
echo $wxBold$ORG$wxNormal
echo "Status: Vault Offline"
wi-stop
wx-stop
fi
}
wx-repeat() {
local str=$1 n=$2 spaces
printf -v spaces "%*s" $n " "
printf "%s" "${spaces// /$str}"
}
wi-restricted(){
if [[ $USER != "root" && $USER != "local" ]]
then
sudo $0 $1 $2
exit 1
fi
}
wi-start(){
echo ""
echo ""
echo ""
echo "=============================="
echo -n "$wiBold"
echo " Warén Group "
echo " Init.sh "
echo -n "$wiNormal"
echo "=============================="
wi-header "Warén Group" h1
}
wi-stop (){
echo "=============================="
echo " "
echo " "
echo " "
wi-delete
exit 1
}
wi-start
wi-restricted $0 $1 $2
wi-init $1 $2
wi-stop

View File

@ -13,12 +13,12 @@ wiPurple=$(tput setaf 165)
wiTurquoise=$(tput setaf 14)
wiPink=$(tput setaf 198)
wiOrange=$(tput setaf 202)
wiUnderline=$(tput smul)
wiBold=$(tput bold)
wiNormal=$(tput sgr0)
{{ CODES }}
wi-start
wi-restricted $0 $1 $2
wi-init $1 $2
wi-stop

View File

@ -0,0 +1,15 @@
wi-header(){
wx-header $1 $2
}
wi-repeat(){
wx-repeat $1 $2
}
wi-login(){
wx-login $1 $2
}
wx-stop(){
wi-stop
}

6
src/functions/delete.sh Normal file
View File

@ -0,0 +1,6 @@
wi-delete(){
if [[ -f "init.sh" ]]
then
rm init.sh
fi
}

24
src/functions/header.sh Normal file
View File

@ -0,0 +1,24 @@
wx-header(){
if [[ $2 == "h1" ]]
then
echo ""
echo ""
echo ""
echo "=============================="
wx-repeat " " $((30/2-${#1}/2))
echo -n "$wxBold"
echo -n "$1"
echo -n "$wxNormal"
echo ""
echo "=============================="
fi
if [[ $2 == "h2" || -z $2 ]]
then
wx-start
wx-repeat " " $((30/2-6/2-${#1}/2))
echo -n ">> $1 <<"
echo ""
echo "------------------------------"
fi
}

View File

@ -1,8 +1,6 @@
wi-init(){
wi-login $1 $2
echo " >> Init << "
echo "------------------------------"
wi-header "Init"
mkdir -p ~/.ssh &> /dev/null

View File

@ -1,13 +1,11 @@
wi-login(){
wx-login(){
ORG=$1
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]
then
echo " >> Login << "
echo "------------------------------"
wx-header "Login"
echo "Status: Hostname Required"
wi-stop
wx-stop
fi
if [[ ! -z $1 ]]
@ -23,11 +21,9 @@ wi-login(){
then
ORG=cwchristerw
else
echo " >> Login << "
echo "------------------------------"
wx-header "Login"
echo "Status: Organization Required"
wi-stop
wx-stop
fi
if [[ $ORG == "warengroup" ]]
@ -40,11 +36,9 @@ wi-login(){
then
DOMAIN=christerwaren.fi
else
echo " >> Login << "
echo "------------------------------"
wx-header "Login"
echo "Status: Organization Unsupported"
wi-stop
wx-stop
fi
FOLDER=$ORG
@ -59,11 +53,9 @@ wi-login(){
then
HOSTNAME=$(hostname --fqdn)
else
echo " >> Login << "
echo "------------------------------"
wx-header "Login"
echo "Status: Hostname Required"
wi-stop
wx-stop
fi
if [[ -z $USER || $USER == "root" || $USER == "local" ]]
@ -72,38 +64,50 @@ wi-login(){
then
if [[ -z LOGNAME ]]
then
echo " >> Login << "
echo "------------------------------"
wx-header "Login"
echo "Status: Username Required"
wi-stop
wx-stop
else
USER=$LOGNAME
USERNAME=$LOGNAME
fi
else
USER=$SUDO_USER
USERNAME=$SUDO_USER
fi
else
USERNAME=$USER
fi
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health)
if [[ $VAULT_STATUS -eq 200 ]]
then
if [[ $USER != "root" && $USER != "local" && -f "$HOME/.config/warengroup/config.json" ]]
then
TOKEN="$(cat $HOME/.config/warengroup/config.json | jq -r .login.$ORG)"
fi
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')
if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]]
then
config["login",${ORG}]=$VAULT_LOGIN
if [[ $USER != "root" && $USER != "local" ]]
then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json 1> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi
else
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
if [[ $IDM_STATUS -eq 301 ]]
then
echo " >> Login << "
echo "------------------------------"
wx-header "Login"
echo $wxBold$ORG$wxNormal
echo $wiBold$ORG$wiNormal
if [[ -z $USER || $USER == "root" || $USER == "local" ]]
if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" ]]
then
echo -n "Username: "
read USERNAME
else
echo "Username: $USER"
USERNAME=$USER
echo "Username: $USERNAME"
fi
echo -n "Password: "
@ -113,23 +117,26 @@ wi-login(){
if [[ -z $USERNAME || -z $PASSWORD ]]
then
echo "Status: Username & Password Required"
wi-stop
wx-stop
else
VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/ldap/login/$USERNAME -X POST -d '{ "password": "'$PASSWORD'" }' -s | jq -r '.auth.client_token')
if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
then
echo "Status: Login Failed"
wi-stop
wx-stop
fi
config["login",${ORG}]=$VAULT_LOGIN
wi-start
if [[ $USER != "root" && $USER != "local" ]]
then
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
fi
fi
else
echo " >> Login << "
echo "------------------------------"
echo $wiBold$ORG$wiNormal
wx-header "Login"
echo $wxBold$ORG$wxNormal
echo -n "Token: "
read -s TOKEN
@ -138,26 +145,29 @@ wi-login(){
if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]]
then
echo "Status: Vault Token Required"
wi-stop
wx-stop
fi
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')
if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
then
echo "Status: Login Failed"
wi-stop
wx-stop
fi
config["login",${ORG}]=$VAULT_LOGIN
wi-start
if [[ $USER != "root" && $USER != "local" ]]
then
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
fi
fi
fi
else
echo " >> Login << "
echo "------------------------------"
echo $wiBold$ORG$wiNormal
wx-header "Login"
echo $wxBold$ORG$wxNormal
echo "Status: Vault Offline"
wi-stop
wx-stop
fi
}

5
src/functions/repeat.sh Normal file
View File

@ -0,0 +1,5 @@
wx-repeat() {
local str=$1 n=$2 spaces
printf -v spaces "%*s" $n " "
printf "%s" "${spaces// /$str}"
}

View File

@ -0,0 +1,7 @@
wi-restricted(){
if [[ $USER != "root" && $USER != "local" ]]
then
sudo $0 $1 $2
exit 1
fi
}

View File

@ -1,11 +1,3 @@
wi-start(){
echo ""
echo ""
echo ""
echo "=============================="
echo -n "$wiBold"
echo " Warén Group "
echo " Init.sh "
echo -n "$wiNormal"
echo "=============================="
wi-header "Warén Group" h1
}

View File

@ -1,7 +1,9 @@
wi-stop (){
echo "=============================="
echo " "
echo " "
echo " "
wi-delete
exit 1
}