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)
wxOrange=$(tput setaf 202)
wxUnderline=$(tput smul)
wxItalic=$(tput sitm)
wxBold=$(tput bold)
wxNormal=$(tput sgr0)

View File

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

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-login
echo -n "$wxItalic"
echo " >> Settings << "
echo -n "$wxNormal";
echo "------------------------------"
}

View File

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

View File

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

View File

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

View File

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

View File

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

121
wx
View File

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