From 963770b9749497f5220a2d44558316c19bb20042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 29 Apr 2024 06:00:07 +0300 Subject: [PATCH] Source Update --- src/commands/help.sh | 2 +- src/commands/init.sh | 2 +- src/commands/settings.sh | 2 +- src/commands/ssh.sh | 2 +- src/commands/ssh/sign.sh | 42 ++++++++++++++--------------- src/commands/welcome.sh | 2 +- src/functions/login.sh | 2 +- src/functions/start.sh | 2 +- src/functions/stop.sh | 2 +- wx | 58 +++++++++++++++++++--------------------- 10 files changed, 56 insertions(+), 60 deletions(-) diff --git a/src/commands/help.sh b/src/commands/help.sh index ad29cfc..f2c923f 100644 --- a/src/commands/help.sh +++ b/src/commands/help.sh @@ -1,4 +1,4 @@ -wx-help() { +wx-help(){ echo -n "$wxItalic" echo " >> Help << " echo -n "$wxNormal"; diff --git a/src/commands/init.sh b/src/commands/init.sh index 88afa02..e2aae59 100644 --- a/src/commands/init.sh +++ b/src/commands/init.sh @@ -1,4 +1,4 @@ -wx-init () { +wx-init(){ wx-login echo -n "$wxItalic" diff --git a/src/commands/settings.sh b/src/commands/settings.sh index b66abb6..fae60c7 100644 --- a/src/commands/settings.sh +++ b/src/commands/settings.sh @@ -1,4 +1,4 @@ -wx-settings() { +wx-settings(){ wx-login echo -n "$wxItalic" diff --git a/src/commands/ssh.sh b/src/commands/ssh.sh index 2a75318..f001b9e 100644 --- a/src/commands/ssh.sh +++ b/src/commands/ssh.sh @@ -1,4 +1,4 @@ -wx-ssh() { +wx-ssh(){ wx-login case $1 in diff --git a/src/commands/ssh/sign.sh b/src/commands/ssh/sign.sh index 53e7e51..4a365c0 100644 --- a/src/commands/ssh/sign.sh +++ b/src/commands/ssh/sign.sh @@ -5,32 +5,30 @@ wx-ssh-sign(){ echo -n "$wxNormal" echo "------------------------------" - NAME=warengroup - ROLE=sysadmin - PRINCIPALS=sysadmin - TTL=3600 - - if [[ -f "$HOME/.ssh/keys/$NAME-ed25519" ]] + if [[ $ORG == "warengroup" ]] then - echo "$NAME/$ROLE" - echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config[$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME-ed25519.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME-ed25519.sig 2>&1 - fi - - NAME=cwinfo - ROLE=sysadmin - PRINCIPALS=sysadmin - TTL=3600 - - if [[ -f "$HOME/.ssh/keys/$NAME-ed25519" ]] + wx-ssh-sign-create warengroup sysadmin 3600 + elif [[ $ORG == "cwinfo" ]] then - echo "$NAME/$ROLE" - echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config[$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME-ed25519.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME-ed25519.sig 2>&1 + wx-ssh-sign-create cwinfo sysadmin 3600 + elif [[ $ORG == "cwchristerw" ]] + then + wx-ssh-sign-create warengroup sysadmin 3600 + wx-ssh-sign-create cwinfo sysadmin 3600 + wx-ssh-sign-create cwchristew sysadmin 3600 fi +} - NAME=cwchristerw - ROLE=sysadmin - PRINCIPALS=sysadmin - TTL=3600 +wx-ssh-sign-create(){ + NAME=$1 + ROLE=$2 + PRINCIPALS=$2 + TTL=$3 + + if [[ ! -f "$HOME/.ssh/keys/$NAME-ed25519" ]] + then + ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$NAME-ed25519 -q -N "" &> /dev/null + fi if [[ -f "$HOME/.ssh/keys/$NAME-ed25519" ]] then diff --git a/src/commands/welcome.sh b/src/commands/welcome.sh index 019bc1e..9dbc653 100644 --- a/src/commands/welcome.sh +++ b/src/commands/welcome.sh @@ -1,4 +1,4 @@ -wx-welcome() { +wx-welcome(){ echo -n "$wxItalic" echo " >> Welcome << " echo -n "$wxNormal" diff --git a/src/functions/login.sh b/src/functions/login.sh index e325675..ae9a80f 100644 --- a/src/functions/login.sh +++ b/src/functions/login.sh @@ -1,4 +1,4 @@ -wx-login() { +wx-login(){ echo -n "$wxItalic" echo " >> Login << " echo -n "$wxNormal"; diff --git a/src/functions/start.sh b/src/functions/start.sh index 3187d88..fbcf2a7 100644 --- a/src/functions/start.sh +++ b/src/functions/start.sh @@ -1,4 +1,4 @@ -wx-start() { +wx-start(){ echo "" echo "" echo "" diff --git a/src/functions/stop.sh b/src/functions/stop.sh index 8f43010..0435f76 100644 --- a/src/functions/stop.sh +++ b/src/functions/stop.sh @@ -1,4 +1,4 @@ -wx-stop () { +wx-stop (){ echo " " echo " " echo " " diff --git a/wx b/wx index 8b95885..8c20a2e 100755 --- a/wx +++ b/wx @@ -20,7 +20,7 @@ wxNormal=$(tput sgr0) declare -Ax config -wx-login() { +wx-login(){ echo -n "$wxItalic" echo " >> Login << " echo -n "$wxNormal"; @@ -210,7 +210,7 @@ wx-login() { fi } -wx-start() { +wx-start(){ echo "" echo "" echo "" @@ -221,7 +221,7 @@ wx-start() { echo "==============================" } -wx-stop () { +wx-stop (){ echo " " echo " " echo " " @@ -239,7 +239,7 @@ wx-stop () { exit 1 } -wx-help() { +wx-help(){ echo -n "$wxItalic" echo " >> Help << " echo -n "$wxNormal"; @@ -258,7 +258,7 @@ Management Commands: "; } -wx-init () { +wx-init(){ wx-login echo -n "$wxItalic" @@ -276,7 +276,7 @@ wx-init () { } -wx-settings() { +wx-settings(){ wx-login echo -n "$wxItalic" @@ -285,7 +285,7 @@ wx-settings() { echo "------------------------------" } -wx-ssh() { +wx-ssh(){ wx-login case $1 in @@ -306,7 +306,7 @@ wx-ssh() { esac } -wx-welcome() { +wx-welcome(){ echo -n "$wxItalic" echo " >> Welcome << " echo -n "$wxNormal" @@ -328,32 +328,30 @@ wx-ssh-sign(){ echo -n "$wxNormal" echo "------------------------------" - NAME=warengroup - ROLE=sysadmin - PRINCIPALS=sysadmin - TTL=3600 - - if [[ -f "$HOME/.ssh/keys/$NAME-ed25519" ]] + if [[ $ORG == "warengroup" ]] then - echo "$NAME/$ROLE" - echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config[$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME-ed25519.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME-ed25519.sig 2>&1 - fi - - NAME=cwinfo - ROLE=sysadmin - PRINCIPALS=sysadmin - TTL=3600 - - if [[ -f "$HOME/.ssh/keys/$NAME-ed25519" ]] + wx-ssh-sign-create warengroup sysadmin 3600 + elif [[ $ORG == "cwinfo" ]] then - echo "$NAME/$ROLE" - echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config[$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME-ed25519.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME-ed25519.sig 2>&1 + wx-ssh-sign-create cwinfo sysadmin 3600 + elif [[ $ORG == "cwchristerw" ]] + then + wx-ssh-sign-create warengroup sysadmin 3600 + wx-ssh-sign-create cwinfo sysadmin 3600 + wx-ssh-sign-create cwchristew sysadmin 3600 fi +} - NAME=cwchristerw - ROLE=sysadmin - PRINCIPALS=sysadmin - TTL=3600 +wx-ssh-sign-create(){ + NAME=$1 + ROLE=$2 + PRINCIPALS=$2 + TTL=$3 + + if [[ ! -f "$HOME/.ssh/keys/$NAME-ed25519" ]] + then + ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$NAME-ed25519 -q -N "" &> /dev/null + fi if [[ -f "$HOME/.ssh/keys/$NAME-ed25519" ]] then