Source Update

This commit is contained in:
Christer Warén 2024-05-01 02:52:21 +03:00
parent cb76cbd190
commit 7765af850a
10 changed files with 37 additions and 206 deletions

View File

@ -14,7 +14,6 @@ wxTurquoise=$(tput setaf 14)
wxPink=$(tput setaf 198) wxPink=$(tput setaf 198)
wxOrange=$(tput setaf 202) wxOrange=$(tput setaf 202)
wxUnderline=$(tput smul) wxUnderline=$(tput smul)
wxItalic=$(tput sitm)
wxBold=$(tput bold) wxBold=$(tput bold)
wxNormal=$(tput sgr0) wxNormal=$(tput sgr0)

View File

@ -1,8 +1,8 @@
wx-help(){ wx-help(){
echo -n "$wxItalic"
echo " >> Help << " echo " >> Help << "
echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
echo -n " echo -n "
Usage: $0 COMMAND [OPTIONS] Usage: $0 COMMAND [OPTIONS]
@ -15,4 +15,5 @@ Common Commands:
Management Commands: Management Commands:
settings Settings settings Settings
"; ";
} }

View File

@ -1,17 +0,0 @@
wx-init(){
wx-login
echo -n "$wxItalic"
echo " >> Init << "
echo -n "$wxNormal";
echo "------------------------------"
mkdir -p ~/.ssh &> /dev/null
apt-get install -y python3-pip python3-venv jq git curl &> /dev/null
python3 -m venv /opt/ansible &> /dev/null
/opt/ansible/bin/pip3 install ansible hvac netaddr jmespath pexpect &> /dev/null
/opt/ansible/bin/ansible-pull -U ssh://git@$GIT_DOMAIN:$GIT_PORT/$GIT_REPOSITORY --vault-password-file ~/.ansible/vault.yml --private-key ~/.ssh/init playbooks/init.yml -t init
}

View File

@ -1,8 +1,6 @@
wx-settings(){ wx-settings(){
wx-login wx-login
echo -n "$wxItalic"
echo " >> Settings << " echo " >> Settings << "
echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
} }

View File

@ -9,9 +9,7 @@ wx-ssh(){
wx-ssh-config wx-ssh-config
;; ;;
*) *)
echo -n "$wxItalic"
echo " >> SSH << " echo " >> SSH << "
echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
wx-stop wx-stop

View File

@ -1,7 +1,5 @@
wx-ssh-config(){ wx-ssh-config(){
echo -n "$wxItalic"
echo " >> SSH << " echo " >> SSH << "
echo " Config " echo " Config "
echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
} }

View File

@ -1,8 +1,6 @@
wx-ssh-sign(){ wx-ssh-sign(){
echo -n "$wxItalic"
echo " >> SSH << " echo " >> SSH << "
echo " Sign " echo " Sign "
echo -n "$wxNormal"
echo "------------------------------" echo "------------------------------"
if [[ $ORG == "warengroup" ]] if [[ $ORG == "warengroup" ]]

View File

@ -1,6 +1,4 @@
wx-welcome(){ wx-welcome(){
echo -n "$wxItalic"
echo " >> Welcome << " echo " >> Welcome << "
echo -n "$wxNormal"
echo "------------------------------" echo "------------------------------"
} }

View File

@ -1,7 +1,5 @@
wx-login(){ wx-login(){
echo -n "$wxItalic"
echo " >> Login << " echo " >> Login << "
echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
ORG=$1 ORG=$1
@ -22,11 +20,7 @@ wx-login(){
ORG=cwchristerw ORG=cwchristerw
elif [[ -z $ORG ]] elif [[ -z $ORG ]]
then then
echo -n "Status: " echo -n "Status: Organization Required"
echo -n $wxItalic
echo -n "Organization Required"
echo -n $wxNormal
wx-stop wx-stop
fi fi
@ -40,11 +34,7 @@ wx-login(){
then then
DOMAIN=christerwaren.fi DOMAIN=christerwaren.fi
else else
echo -n "Status: " echo -n "Status: Organization Unsupported"
echo -n $wxItalic
echo -n "Organization Unsupported"
echo -n $wxNormal
wx-stop wx-stop
fi fi
@ -61,11 +51,7 @@ wx-login(){
then then
HOSTNAME="$2.$DEVICE_DOMAIN" HOSTNAME="$2.$DEVICE_DOMAIN"
else else
echo -n "Status: " echo -n "Status: Hostname Required"
echo -n $wxItalic
echo -n "Hostname Required"
echo -n $wxNormal
wx-stop wx-stop
fi fi
@ -75,11 +61,7 @@ wx-login(){
then then
if [[ -z LOGNAME ]] if [[ -z LOGNAME ]]
then then
echo -n "Status: " echo -n "Status: Username Required"
echo -n $wxItalic
echo -n "Username Required"
echo -n $wxNormal
wx-stop wx-stop
else else
USER=$LOGNAME USER=$LOGNAME
@ -100,19 +82,13 @@ wx-login(){
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') 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 ]] if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]]
then then
echo -n $wxBold echo $wxBold$ORG$wxNormal
echo -n $ORG
echo $wxNormal
echo -n "Username: " echo -n "Username: "
echo -n $wxItalic
echo -n $(curl https://$VAULT_DOMAIN/v1/auth/token/lookup-self -X GET --header "X-Vault-Token: $VAULT_LOGIN" -s | jq -r '.data.meta.username') echo -n $(curl https://$VAULT_DOMAIN/v1/auth/token/lookup-self -X GET --header "X-Vault-Token: $VAULT_LOGIN" -s | jq -r '.data.meta.username')
echo $wxNormal
echo -n "Token: " echo -n "Token: "
echo -n $wxItalic echo "****************"
echo -n "****************"
echo $wxNormal
config[${ORG}]=$VAULT_LOGIN config[${ORG}]=$VAULT_LOGIN
echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json
@ -122,47 +98,30 @@ wx-login(){
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 -n $wxBold echo $wxBold$ORG$wxNormal
echo -n $ORG
echo $wxNormal
if [[ -z $USER || $USER == "root" || $USER == "local" ]] if [[ -z $USER || $USER == "root" || $USER == "local" ]]
then then
echo -n "Username: " echo -n "Username: "
echo -n $wxItalic
read USERNAME read USERNAME
echo -n $wxNormal
else else
echo -n "Username: " echo "Username: $USER"
echo -n $wxItalic
echo -n $USER
echo $wxNormal
USERNAME=$USER USERNAME=$USER
fi fi
echo -n "Password: " echo -n "Password: "
echo -n $wxItalic
read -s PASSWORD read -s PASSWORD
echo -n "****************" echo "****************"
echo $wxNormal
if [[ -z $USERNAME || -z $PASSWORD ]] if [[ -z $USERNAME || -z $PASSWORD ]]
then then
echo -n "Status: " echo -n "Status: Username & Password Required"
echo -n $wxItalic
echo -n "Username & Password Required"
echo -n $wxNormal
wx-stop wx-stop
else else
VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/ldap/login/$USERNAME -X POST -d '{ "password": "'$PASSWORD'" }' -s | jq -r '.auth.client_token') 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 ]] if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
then then
echo -n "Status: " echo -n "Status: Login Failed"
echo -n $wxItalic
echo -n "Login Failed"
echo -n $wxNormal
wx-stop wx-stop
fi fi
@ -176,9 +135,7 @@ wx-login(){
wx-start wx-start
fi fi
else else
echo -n $wxBold echo $wxBold$ORG$wxNormal
echo -n $ORG
echo $wxNormal
echo -n "Token: " echo -n "Token: "
read -s TOKEN read -s TOKEN
@ -186,22 +143,14 @@ wx-login(){
if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]] if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]]
then then
echo -n "Status: " echo -n "Status: Vault Token Required"
echo -n $wxItalic
echo -n "Vault Token Required"
echo -n $wxNormal
wx-stop wx-stop
fi 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') 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 ]] if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
then then
echo -n "Status: " echo -n "Status: Login Failed"
echo -n $wxItalic
echo -n "Login Failed"
echo -n $wxNormal
wx-stop wx-stop
fi fi
@ -216,15 +165,9 @@ wx-login(){
fi fi
fi fi
else else
echo -n $wxBold echo $wxBold$ORG$wxNormal
echo -n $ORG
echo $wxNormal
echo -n "Status: "
echo -n $wxItalic
echo -n "Vault Offline"
echo -n $wxNormal
echo -n "Status: Vault Offline"
wx-stop wx-stop
fi fi
} }

121
wx
View File

@ -14,16 +14,13 @@ wxTurquoise=$(tput setaf 14)
wxPink=$(tput setaf 198) wxPink=$(tput setaf 198)
wxOrange=$(tput setaf 202) wxOrange=$(tput setaf 202)
wxUnderline=$(tput smul) wxUnderline=$(tput smul)
wxItalic=$(tput sitm)
wxBold=$(tput bold) wxBold=$(tput bold)
wxNormal=$(tput sgr0) wxNormal=$(tput sgr0)
declare -Ax config declare -Ax config
wx-login(){ wx-login(){
echo -n "$wxItalic"
echo " >> Login << " echo " >> Login << "
echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
ORG=$1 ORG=$1
@ -44,11 +41,7 @@ wx-login(){
ORG=cwchristerw ORG=cwchristerw
elif [[ -z $ORG ]] elif [[ -z $ORG ]]
then then
echo -n "Status: " echo -n "Status: Organization Required"
echo -n $wxItalic
echo -n "Organization Required"
echo -n $wxNormal
wx-stop wx-stop
fi fi
@ -62,11 +55,7 @@ wx-login(){
then then
DOMAIN=christerwaren.fi DOMAIN=christerwaren.fi
else else
echo -n "Status: " echo -n "Status: Organization Unsupported"
echo -n $wxItalic
echo -n "Organization Unsupported"
echo -n $wxNormal
wx-stop wx-stop
fi fi
@ -83,11 +72,7 @@ wx-login(){
then then
HOSTNAME="$2.$DEVICE_DOMAIN" HOSTNAME="$2.$DEVICE_DOMAIN"
else else
echo -n "Status: " echo -n "Status: Hostname Required"
echo -n $wxItalic
echo -n "Hostname Required"
echo -n $wxNormal
wx-stop wx-stop
fi fi
@ -97,11 +82,7 @@ wx-login(){
then then
if [[ -z LOGNAME ]] if [[ -z LOGNAME ]]
then then
echo -n "Status: " echo -n "Status: Username Required"
echo -n $wxItalic
echo -n "Username Required"
echo -n $wxNormal
wx-stop wx-stop
else else
USER=$LOGNAME USER=$LOGNAME
@ -122,19 +103,13 @@ wx-login(){
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') 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 ]] if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]]
then then
echo -n $wxBold echo $wxBold$ORG$wxNormal
echo -n $ORG
echo $wxNormal
echo -n "Username: " echo -n "Username: "
echo -n $wxItalic
echo -n $(curl https://$VAULT_DOMAIN/v1/auth/token/lookup-self -X GET --header "X-Vault-Token: $VAULT_LOGIN" -s | jq -r '.data.meta.username') echo -n $(curl https://$VAULT_DOMAIN/v1/auth/token/lookup-self -X GET --header "X-Vault-Token: $VAULT_LOGIN" -s | jq -r '.data.meta.username')
echo $wxNormal
echo -n "Token: " echo -n "Token: "
echo -n $wxItalic echo "****************"
echo -n "****************"
echo $wxNormal
config[${ORG}]=$VAULT_LOGIN config[${ORG}]=$VAULT_LOGIN
echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json
@ -144,47 +119,30 @@ wx-login(){
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 -n $wxBold echo $wxBold$ORG$wxNormal
echo -n $ORG
echo $wxNormal
if [[ -z $USER || $USER == "root" || $USER == "local" ]] if [[ -z $USER || $USER == "root" || $USER == "local" ]]
then then
echo -n "Username: " echo -n "Username: "
echo -n $wxItalic
read USERNAME read USERNAME
echo -n $wxNormal
else else
echo -n "Username: " echo "Username: $USER"
echo -n $wxItalic
echo -n $USER
echo $wxNormal
USERNAME=$USER USERNAME=$USER
fi fi
echo -n "Password: " echo -n "Password: "
echo -n $wxItalic
read -s PASSWORD read -s PASSWORD
echo -n "****************" echo "****************"
echo $wxNormal
if [[ -z $USERNAME || -z $PASSWORD ]] if [[ -z $USERNAME || -z $PASSWORD ]]
then then
echo -n "Status: " echo -n "Status: Username & Password Required"
echo -n $wxItalic
echo -n "Username & Password Required"
echo -n $wxNormal
wx-stop wx-stop
else else
VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/ldap/login/$USERNAME -X POST -d '{ "password": "'$PASSWORD'" }' -s | jq -r '.auth.client_token') 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 ]] if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
then then
echo -n "Status: " echo -n "Status: Login Failed"
echo -n $wxItalic
echo -n "Login Failed"
echo -n $wxNormal
wx-stop wx-stop
fi fi
@ -198,9 +156,7 @@ wx-login(){
wx-start wx-start
fi fi
else else
echo -n $wxBold echo $wxBold$ORG$wxNormal
echo -n $ORG
echo $wxNormal
echo -n "Token: " echo -n "Token: "
read -s TOKEN read -s TOKEN
@ -208,22 +164,14 @@ wx-login(){
if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]] if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]]
then then
echo -n "Status: " echo -n "Status: Vault Token Required"
echo -n $wxItalic
echo -n "Vault Token Required"
echo -n $wxNormal
wx-stop wx-stop
fi 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') 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 ]] if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
then then
echo -n "Status: " echo -n "Status: Login Failed"
echo -n $wxItalic
echo -n "Login Failed"
echo -n $wxNormal
wx-stop wx-stop
fi fi
@ -238,15 +186,9 @@ wx-login(){
fi fi
fi fi
else else
echo -n $wxBold echo $wxBold$ORG$wxNormal
echo -n $ORG
echo $wxNormal
echo -n "Status: "
echo -n $wxItalic
echo -n "Vault Offline"
echo -n $wxNormal
echo -n "Status: Vault Offline"
wx-stop wx-stop
fi fi
} }
@ -281,10 +223,10 @@ wx-stop (){
} }
wx-help(){ wx-help(){
echo -n "$wxItalic"
echo " >> Help << " echo " >> Help << "
echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
echo -n " echo -n "
Usage: $0 COMMAND [OPTIONS] Usage: $0 COMMAND [OPTIONS]
@ -297,32 +239,13 @@ Common Commands:
Management Commands: Management Commands:
settings Settings settings Settings
"; ";
}
wx-init(){
wx-login
echo -n "$wxItalic"
echo " >> Init << "
echo -n "$wxNormal";
echo "------------------------------"
mkdir -p ~/.ssh &> /dev/null
apt-get install -y python3-pip python3-venv jq git curl &> /dev/null
python3 -m venv /opt/ansible &> /dev/null
/opt/ansible/bin/pip3 install ansible hvac netaddr jmespath pexpect &> /dev/null
/opt/ansible/bin/ansible-pull -U ssh://git@$GIT_DOMAIN:$GIT_PORT/$GIT_REPOSITORY --vault-password-file ~/.ansible/vault.yml --private-key ~/.ssh/init playbooks/init.yml -t init
} }
wx-settings(){ wx-settings(){
wx-login wx-login
echo -n "$wxItalic"
echo " >> Settings << " echo " >> Settings << "
echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
} }
@ -337,9 +260,7 @@ wx-ssh(){
wx-ssh-config wx-ssh-config
;; ;;
*) *)
echo -n "$wxItalic"
echo " >> SSH << " echo " >> SSH << "
echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
wx-stop wx-stop
@ -348,25 +269,19 @@ wx-ssh(){
} }
wx-welcome(){ wx-welcome(){
echo -n "$wxItalic"
echo " >> Welcome << " echo " >> Welcome << "
echo -n "$wxNormal"
echo "------------------------------" echo "------------------------------"
} }
wx-ssh-config(){ wx-ssh-config(){
echo -n "$wxItalic"
echo " >> SSH << " echo " >> SSH << "
echo " Config " echo " Config "
echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
} }
wx-ssh-sign(){ wx-ssh-sign(){
echo -n "$wxItalic"
echo " >> SSH << " echo " >> SSH << "
echo " Sign " echo " Sign "
echo -n "$wxNormal"
echo "------------------------------" echo "------------------------------"
if [[ $ORG == "warengroup" ]] if [[ $ORG == "warengroup" ]]