From 7765af850aa5331067af678be23bc33933b06c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Wed, 1 May 2024 02:52:21 +0300 Subject: [PATCH] Source Update --- src/base.sh | 1 - src/commands/help.sh | 5 +- src/commands/init.sh | 17 ------ src/commands/settings.sh | 2 - src/commands/ssh.sh | 2 - src/commands/ssh/config.sh | 2 - src/commands/ssh/sign.sh | 2 - src/commands/welcome.sh | 2 - src/functions/login.sh | 89 +++++---------------------- wx | 121 ++++++------------------------------- 10 files changed, 37 insertions(+), 206 deletions(-) delete mode 100644 src/commands/init.sh diff --git a/src/base.sh b/src/base.sh index d7e3055..f52fccc 100644 --- a/src/base.sh +++ b/src/base.sh @@ -14,7 +14,6 @@ wxTurquoise=$(tput setaf 14) wxPink=$(tput setaf 198) wxOrange=$(tput setaf 202) wxUnderline=$(tput smul) -wxItalic=$(tput sitm) wxBold=$(tput bold) wxNormal=$(tput sgr0) diff --git a/src/commands/help.sh b/src/commands/help.sh index f2c923f..0534329 100644 --- a/src/commands/help.sh +++ b/src/commands/help.sh @@ -1,8 +1,8 @@ wx-help(){ -echo -n "$wxItalic" + echo " >> Help << " -echo -n "$wxNormal"; echo "------------------------------" + echo -n " Usage: $0 COMMAND [OPTIONS] @@ -15,4 +15,5 @@ Common Commands: Management Commands: settings Settings "; + } diff --git a/src/commands/init.sh b/src/commands/init.sh deleted file mode 100644 index e2aae59..0000000 --- a/src/commands/init.sh +++ /dev/null @@ -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 - -} diff --git a/src/commands/settings.sh b/src/commands/settings.sh index fae60c7..e1e08c7 100644 --- a/src/commands/settings.sh +++ b/src/commands/settings.sh @@ -1,8 +1,6 @@ wx-settings(){ wx-login - echo -n "$wxItalic" echo " >> Settings << " - echo -n "$wxNormal"; echo "------------------------------" } diff --git a/src/commands/ssh.sh b/src/commands/ssh.sh index f001b9e..39691e2 100644 --- a/src/commands/ssh.sh +++ b/src/commands/ssh.sh @@ -9,9 +9,7 @@ wx-ssh(){ wx-ssh-config ;; *) - echo -n "$wxItalic" echo " >> SSH << " - echo -n "$wxNormal"; echo "------------------------------" wx-stop diff --git a/src/commands/ssh/config.sh b/src/commands/ssh/config.sh index 8e790a8..0500a83 100644 --- a/src/commands/ssh/config.sh +++ b/src/commands/ssh/config.sh @@ -1,7 +1,5 @@ wx-ssh-config(){ - echo -n "$wxItalic" echo " >> SSH << " echo " Config " - echo -n "$wxNormal"; echo "------------------------------" } diff --git a/src/commands/ssh/sign.sh b/src/commands/ssh/sign.sh index 81cce9c..6b0cb8d 100644 --- a/src/commands/ssh/sign.sh +++ b/src/commands/ssh/sign.sh @@ -1,8 +1,6 @@ wx-ssh-sign(){ - echo -n "$wxItalic" echo " >> SSH << " echo " Sign " - echo -n "$wxNormal" echo "------------------------------" if [[ $ORG == "warengroup" ]] diff --git a/src/commands/welcome.sh b/src/commands/welcome.sh index 9dbc653..1b1c77f 100644 --- a/src/commands/welcome.sh +++ b/src/commands/welcome.sh @@ -1,6 +1,4 @@ wx-welcome(){ - echo -n "$wxItalic" echo " >> Welcome << " - echo -n "$wxNormal" echo "------------------------------" } diff --git a/src/functions/login.sh b/src/functions/login.sh index af871de..f3cf174 100644 --- a/src/functions/login.sh +++ b/src/functions/login.sh @@ -1,7 +1,5 @@ wx-login(){ - echo -n "$wxItalic" echo " >> Login << " - echo -n "$wxNormal"; echo "------------------------------" ORG=$1 @@ -22,11 +20,7 @@ wx-login(){ ORG=cwchristerw elif [[ -z $ORG ]] then - echo -n "Status: " - echo -n $wxItalic - echo -n "Organization Required" - echo -n $wxNormal - + echo -n "Status: Organization Required" wx-stop fi @@ -40,11 +34,7 @@ wx-login(){ then DOMAIN=christerwaren.fi else - echo -n "Status: " - echo -n $wxItalic - echo -n "Organization Unsupported" - echo -n $wxNormal - + echo -n "Status: Organization Unsupported" wx-stop fi @@ -61,11 +51,7 @@ wx-login(){ then HOSTNAME="$2.$DEVICE_DOMAIN" else - echo -n "Status: " - echo -n $wxItalic - echo -n "Hostname Required" - echo -n $wxNormal - + echo -n "Status: Hostname Required" wx-stop fi @@ -75,11 +61,7 @@ wx-login(){ then if [[ -z LOGNAME ]] then - echo -n "Status: " - echo -n $wxItalic - echo -n "Username Required" - echo -n $wxNormal - + echo -n "Status: Username Required" wx-stop else 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') if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]] then - echo -n $wxBold - echo -n $ORG - echo $wxNormal + echo $wxBold$ORG$wxNormal 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 $wxNormal echo -n "Token: " - echo -n $wxItalic - echo -n "****************" - echo $wxNormal + echo "****************" config[${ORG}]=$VAULT_LOGIN 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) if [[ $IDM_STATUS -eq 301 ]] then - echo -n $wxBold - echo -n $ORG - echo $wxNormal + echo $wxBold$ORG$wxNormal if [[ -z $USER || $USER == "root" || $USER == "local" ]] then echo -n "Username: " - echo -n $wxItalic read USERNAME - echo -n $wxNormal else - echo -n "Username: " - echo -n $wxItalic - echo -n $USER - echo $wxNormal + echo "Username: $USER" USERNAME=$USER fi echo -n "Password: " - echo -n $wxItalic read -s PASSWORD - echo -n "****************" - echo $wxNormal + echo "****************" if [[ -z $USERNAME || -z $PASSWORD ]] then - echo -n "Status: " - echo -n $wxItalic - echo -n "Username & Password Required" - echo -n $wxNormal - + echo -n "Status: Username & Password Required" 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 -n "Status: " - echo -n $wxItalic - echo -n "Login Failed" - echo -n $wxNormal - + echo -n "Status: Login Failed" wx-stop fi @@ -176,9 +135,7 @@ wx-login(){ wx-start fi else - echo -n $wxBold - echo -n $ORG - echo $wxNormal + echo $wxBold$ORG$wxNormal echo -n "Token: " read -s TOKEN @@ -186,22 +143,14 @@ wx-login(){ if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]] then - echo -n "Status: " - echo -n $wxItalic - echo -n "Vault Token Required" - echo -n $wxNormal - + echo -n "Status: Vault Token Required" 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 -n "Status: " - echo -n $wxItalic - echo -n "Login Failed" - echo -n $wxNormal - + echo -n "Status: Login Failed" wx-stop fi @@ -216,15 +165,9 @@ wx-login(){ fi fi else - echo -n $wxBold - echo -n $ORG - echo $wxNormal - - echo -n "Status: " - echo -n $wxItalic - echo -n "Vault Offline" - echo -n $wxNormal + echo $wxBold$ORG$wxNormal + echo -n "Status: Vault Offline" wx-stop fi } diff --git a/wx b/wx index 61ab6c7..00a610b 100755 --- a/wx +++ b/wx @@ -14,16 +14,13 @@ wxTurquoise=$(tput setaf 14) wxPink=$(tput setaf 198) wxOrange=$(tput setaf 202) wxUnderline=$(tput smul) -wxItalic=$(tput sitm) wxBold=$(tput bold) wxNormal=$(tput sgr0) declare -Ax config wx-login(){ - echo -n "$wxItalic" echo " >> Login << " - echo -n "$wxNormal"; echo "------------------------------" ORG=$1 @@ -44,11 +41,7 @@ wx-login(){ ORG=cwchristerw elif [[ -z $ORG ]] then - echo -n "Status: " - echo -n $wxItalic - echo -n "Organization Required" - echo -n $wxNormal - + echo -n "Status: Organization Required" wx-stop fi @@ -62,11 +55,7 @@ wx-login(){ then DOMAIN=christerwaren.fi else - echo -n "Status: " - echo -n $wxItalic - echo -n "Organization Unsupported" - echo -n $wxNormal - + echo -n "Status: Organization Unsupported" wx-stop fi @@ -83,11 +72,7 @@ wx-login(){ then HOSTNAME="$2.$DEVICE_DOMAIN" else - echo -n "Status: " - echo -n $wxItalic - echo -n "Hostname Required" - echo -n $wxNormal - + echo -n "Status: Hostname Required" wx-stop fi @@ -97,11 +82,7 @@ wx-login(){ then if [[ -z LOGNAME ]] then - echo -n "Status: " - echo -n $wxItalic - echo -n "Username Required" - echo -n $wxNormal - + echo -n "Status: Username Required" wx-stop else 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') if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]] then - echo -n $wxBold - echo -n $ORG - echo $wxNormal + echo $wxBold$ORG$wxNormal 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 $wxNormal echo -n "Token: " - echo -n $wxItalic - echo -n "****************" - echo $wxNormal + echo "****************" config[${ORG}]=$VAULT_LOGIN 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) if [[ $IDM_STATUS -eq 301 ]] then - echo -n $wxBold - echo -n $ORG - echo $wxNormal + echo $wxBold$ORG$wxNormal if [[ -z $USER || $USER == "root" || $USER == "local" ]] then echo -n "Username: " - echo -n $wxItalic read USERNAME - echo -n $wxNormal else - echo -n "Username: " - echo -n $wxItalic - echo -n $USER - echo $wxNormal + echo "Username: $USER" USERNAME=$USER fi echo -n "Password: " - echo -n $wxItalic read -s PASSWORD - echo -n "****************" - echo $wxNormal + echo "****************" if [[ -z $USERNAME || -z $PASSWORD ]] then - echo -n "Status: " - echo -n $wxItalic - echo -n "Username & Password Required" - echo -n $wxNormal - + echo -n "Status: Username & Password Required" 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 -n "Status: " - echo -n $wxItalic - echo -n "Login Failed" - echo -n $wxNormal - + echo -n "Status: Login Failed" wx-stop fi @@ -198,9 +156,7 @@ wx-login(){ wx-start fi else - echo -n $wxBold - echo -n $ORG - echo $wxNormal + echo $wxBold$ORG$wxNormal echo -n "Token: " read -s TOKEN @@ -208,22 +164,14 @@ wx-login(){ if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]] then - echo -n "Status: " - echo -n $wxItalic - echo -n "Vault Token Required" - echo -n $wxNormal - + echo -n "Status: Vault Token Required" 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 -n "Status: " - echo -n $wxItalic - echo -n "Login Failed" - echo -n $wxNormal - + echo -n "Status: Login Failed" wx-stop fi @@ -238,15 +186,9 @@ wx-login(){ fi fi else - echo -n $wxBold - echo -n $ORG - echo $wxNormal - - echo -n "Status: " - echo -n $wxItalic - echo -n "Vault Offline" - echo -n $wxNormal + echo $wxBold$ORG$wxNormal + echo -n "Status: Vault Offline" wx-stop fi } @@ -281,10 +223,10 @@ wx-stop (){ } wx-help(){ -echo -n "$wxItalic" + echo " >> Help << " -echo -n "$wxNormal"; echo "------------------------------" + echo -n " Usage: $0 COMMAND [OPTIONS] @@ -297,32 +239,13 @@ Common Commands: Management Commands: 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-login - echo -n "$wxItalic" echo " >> Settings << " - echo -n "$wxNormal"; echo "------------------------------" } @@ -337,9 +260,7 @@ wx-ssh(){ wx-ssh-config ;; *) - echo -n "$wxItalic" echo " >> SSH << " - echo -n "$wxNormal"; echo "------------------------------" wx-stop @@ -348,25 +269,19 @@ wx-ssh(){ } wx-welcome(){ - echo -n "$wxItalic" echo " >> Welcome << " - echo -n "$wxNormal" echo "------------------------------" } wx-ssh-config(){ - echo -n "$wxItalic" echo " >> SSH << " echo " Config " - echo -n "$wxNormal"; echo "------------------------------" } wx-ssh-sign(){ - echo -n "$wxItalic" echo " >> SSH << " echo " Sign " - echo -n "$wxNormal" echo "------------------------------" if [[ $ORG == "warengroup" ]]