From b2d3908d6f8e14bca08602ba1f9a99f00be8d485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sat, 27 Apr 2024 23:32:06 +0300 Subject: [PATCH] Source Update --- src/base.sh | 15 +++++++- src/commands/help.sh | 8 +++- src/commands/init.sh | 14 +++++++ src/commands/settings.sh | 7 +++- src/commands/ssh.sh | 7 +++- src/commands/ssh/config.sh | 5 ++- src/commands/ssh/sign.sh | 5 ++- src/commands/welcome.sh | 5 ++- src/functions/login.sh | 7 +++- src/functions/start.sh | 4 +- wx | 78 ++++++++++++++++++++++++++++++++------ 11 files changed, 133 insertions(+), 22 deletions(-) create mode 100644 src/commands/init.sh diff --git a/src/base.sh b/src/base.sh index 529c857..789cbc0 100644 --- a/src/base.sh +++ b/src/base.sh @@ -5,14 +5,25 @@ if [ ! "$BASH_VERSION" ] ; then exit 1 fi +wxRed=$(tput setaf 196) +wxGreen=$(tput setaf 46) +wxYellow=$(tput setaf 226) +wxBlue=$(tput setaf 21) +wxPurple=$(tput setaf 165) +wxTurquoise=$(tput setaf 14) +wxPink=$(tput setaf 198) +wxOrange=$(tput setaf 202) +wxUnderline=$(tput smul) +wxItalic=$(tput sitm) +wxBold=$(tput bold) +wxNormal=$(tput sgr0) + {{ FUNCTIONS }} {{ COMMANDS }} wx-start if [[ ! -z $1 ]] && [[ $(type -t wx-$1) == function ]] then - wx-login - wx-start wx-$1 $2 $3 $4 $5 $6 $7 $8 $9 else wx-welcome diff --git a/src/commands/help.sh b/src/commands/help.sh index d1cd81f..ad29cfc 100644 --- a/src/commands/help.sh +++ b/src/commands/help.sh @@ -1,9 +1,13 @@ wx-help() { -echo -n ">>> Help <<<"; -echo " +echo -n "$wxItalic" +echo " >> Help << " +echo -n "$wxNormal"; +echo "------------------------------" +echo -n " Usage: $0 COMMAND [OPTIONS] Common Commands: + init Init ssh SSH config Config sign Certificates diff --git a/src/commands/init.sh b/src/commands/init.sh new file mode 100644 index 0000000..127f379 --- /dev/null +++ b/src/commands/init.sh @@ -0,0 +1,14 @@ +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 +} diff --git a/src/commands/settings.sh b/src/commands/settings.sh index c151072..b66abb6 100644 --- a/src/commands/settings.sh +++ b/src/commands/settings.sh @@ -1,3 +1,8 @@ wx-settings() { - echo -n ">>> 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 6e869b9..dedf765 100644 --- a/src/commands/ssh.sh +++ b/src/commands/ssh.sh @@ -1,3 +1,8 @@ wx-ssh() { - echo -n ">>> SSH <<<"; + wx-login + + echo -n "$wxItalic" + echo " >> SSH << " + echo -n "$wxNormal"; + echo "------------------------------" } diff --git a/src/commands/ssh/config.sh b/src/commands/ssh/config.sh index 7af28cc..2d39ef6 100644 --- a/src/commands/ssh/config.sh +++ b/src/commands/ssh/config.sh @@ -1,3 +1,6 @@ wx-ssh-config(){ - echo -n ">>> SSH: Config <<<" + echo -n "$wxItalic" + echo " >> SSH : Config << " + echo -n "$wxNormal" + echo "------------------------------" } diff --git a/src/commands/ssh/sign.sh b/src/commands/ssh/sign.sh index a055ccf..e32f6fd 100644 --- a/src/commands/ssh/sign.sh +++ b/src/commands/ssh/sign.sh @@ -1,3 +1,6 @@ wx-ssh-sign(){ - echo -n ">>> SSH: Certificates <<<" + echo -n "$wxItalic" + echo " >> SSH : Certificates << " + echo -n "$wxNormal" + echo "------------------------------" } diff --git a/src/commands/welcome.sh b/src/commands/welcome.sh index bf1b277..019bc1e 100644 --- a/src/commands/welcome.sh +++ b/src/commands/welcome.sh @@ -1,3 +1,6 @@ wx-welcome() { - echo -n ">>> Welcome <<<" + echo -n "$wxItalic" + echo " >> Welcome << " + echo -n "$wxNormal" + echo "------------------------------" } diff --git a/src/functions/login.sh b/src/functions/login.sh index 722ac61..9079cff 100644 --- a/src/functions/login.sh +++ b/src/functions/login.sh @@ -1,5 +1,9 @@ wx-login() { - echo ">>> Login <<<" + echo -n "$wxItalic" + echo " >> Login << " + echo -n "$wxNormal"; + echo "------------------------------" + ORG=$2 if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]; then @@ -93,6 +97,7 @@ wx-login() { wx-stop fi echo "" + wx-start else echo "Organization: $ORG" echo "Status: IDM Offline" diff --git a/src/functions/start.sh b/src/functions/start.sh index 1138b75..3187d88 100644 --- a/src/functions/start.sh +++ b/src/functions/start.sh @@ -3,6 +3,8 @@ wx-start() { echo "" echo "" echo "==============================" - echo "Warén CLI" + echo -n "$wxBold" + echo " Warén CLI " + echo -n "$wxNormal" echo "==============================" } diff --git a/wx b/wx index 0aac0da..3050079 100755 --- a/wx +++ b/wx @@ -5,8 +5,25 @@ if [ ! "$BASH_VERSION" ] ; then exit 1 fi +wxRed=$(tput setaf 196) +wxGreen=$(tput setaf 46) +wxYellow=$(tput setaf 226) +wxBlue=$(tput setaf 21) +wxPurple=$(tput setaf 165) +wxTurquoise=$(tput setaf 14) +wxPink=$(tput setaf 198) +wxOrange=$(tput setaf 202) +wxUnderline=$(tput smul) +wxItalic=$(tput sitm) +wxBold=$(tput bold) +wxNormal=$(tput sgr0) + wx-login() { - echo ">>> Login <<<" + echo -n "$wxItalic" + echo " >> Login << " + echo -n "$wxNormal"; + echo "------------------------------" + ORG=$2 if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]; then @@ -100,6 +117,7 @@ wx-login() { wx-stop fi echo "" + wx-start else echo "Organization: $ORG" echo "Status: IDM Offline" @@ -154,7 +172,9 @@ wx-start() { echo "" echo "" echo "==============================" - echo "Warén CLI" + echo -n "$wxBold" + echo " Warén CLI " + echo -n "$wxNormal" echo "==============================" } @@ -179,11 +199,15 @@ wx-stop () { } wx-help() { -echo -n ">>> Help <<<"; -echo " +echo -n "$wxItalic" +echo " >> Help << " +echo -n "$wxNormal"; +echo "------------------------------" +echo -n " Usage: $0 COMMAND [OPTIONS] Common Commands: + init Init ssh SSH config Config sign Certificates @@ -193,32 +217,64 @@ Management Commands: "; } +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 +} + wx-settings() { - echo -n ">>> Settings <<<"; + wx-login + + echo -n "$wxItalic" + echo " >> Settings << " + echo -n "$wxNormal"; + echo "------------------------------" } wx-ssh() { - echo -n ">>> SSH <<<"; + wx-login + + echo -n "$wxItalic" + echo " >> SSH << " + echo -n "$wxNormal"; + echo "------------------------------" } wx-welcome() { - echo -n ">>> Welcome <<<" + echo -n "$wxItalic" + echo " >> Welcome << " + echo -n "$wxNormal" + echo "------------------------------" } wx-ssh-config(){ - echo -n ">>> SSH: Config <<<" + echo -n "$wxItalic" + echo " >> SSH : Config << " + echo -n "$wxNormal" + echo "------------------------------" } wx-ssh-sign(){ - echo -n ">>> SSH: Certificates <<<" + echo -n "$wxItalic" + echo " >> SSH : Certificates << " + echo -n "$wxNormal" + echo "------------------------------" } wx-start if [[ ! -z $1 ]] && [[ $(type -t wx-$1) == function ]] then - wx-login - wx-start wx-$1 $2 $3 $4 $5 $6 $7 $8 $9 else wx-welcome