From ba6dd53f6c25cb049968434db16b2edd71698f81 Mon Sep 17 00:00:00 2001 From: MOIS3Y Date: Thu, 12 Dec 2024 21:29:22 +0900 Subject: [PATCH] update: new config support DE go server and --test option --- scripts/gogo/gogo.sh | 49 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/scripts/gogo/gogo.sh b/scripts/gogo/gogo.sh index 91b56c9..f2d1922 100755 --- a/scripts/gogo/gogo.sh +++ b/scripts/gogo/gogo.sh @@ -5,7 +5,7 @@ # -- -- -- -- -- -- # INIT GLOBAL VARIABLES: -_VERSION="0.1.0" +_VERSION="0.1.1" _SCRIPT_NAME="$(basename $0)" _GO_CMD="go3" _DEBUG_MODE=false @@ -67,6 +67,7 @@ help() { printf " \n" printf "${script} --init | init config file \n" printf "${script} --crt | get ssh certificate for go3 connections \n" + printf "${script} --test | check go3 connection availability \n" printf " \n" printf "${script} --bill my.example.com \n" printf "${script} --vm 0.0.0.0 --ssh | only ssh access \n" @@ -90,8 +91,10 @@ help() { printf " --tty for vm6/dci6 echo cmd for run container \n" printf " --mgrctl [args] for vm6/dci6 customize access params \n" printf " \n" + printf "Single options: \n" printf " --init | -i generate configuration \n" printf " --crt | -c generate ssh cert \n" + printf " --test | -t check go3 connection availability \n" printf " --version | -v print version \n" printf " --help | -h print this message and exit \n" } @@ -115,7 +118,9 @@ init_config() { continue_handler fi # get user unputs: - read -p "Enter go server address: " _GO_SERVER_ADDR + read -p "Enter russian go server address: " _GO_SERVER_ADDR_RUSSIAN + read -p "Enter germany go server address: " _GO_SERVER_ADDR_GERMANY + read -p "Enter test go server address: " _GO_SERVER_ADDR_TEST read -p "Enter vault server address: " _VAULT_SERVER_ADDR read -p "Enter username: " _SSH_PRIVATE_KEY_USER read -p "Enter full path to ssh private key: " _SSH_PRIVATE_KEY_PATH @@ -125,7 +130,9 @@ init_config() { # save config: mkdir -p $_CONFIG_DIR cat << EOF > "${_CONFIG}" -GO_SERVER_ADDR=$_GO_SERVER_ADDR +GO_SERVER_ADDR_RUSSIAN=$_GO_SERVER_ADDR_RUSSIAN +GO_SERVER_ADDR_GERMANY=$_GO_SERVER_ADDR_GERMANY +GO_SERVER_ADDR_TEST=$_GO_SERVER_ADDR_TEST VAULT_SERVER_ADDR=$_VAULT_SERVER_ADDR SSH_PRIVATE_KEY_USER=$_SSH_PRIVATE_KEY_USER SSH_PRIVATE_KEY_PATH=$_SSH_PRIVATE_KEY_PATH @@ -156,10 +163,17 @@ load_config() { while IFS="=" read -r key value; do case "$key" in - "GO_SERVER_ADDR") + "GO_SERVER_ADDR_RUSSIAN") + _GO_SERVER_ADDR_RUSSIAN="$value" _GO_SERVER_ADDR="$value" ;; - "VAULT_SERVER_ADDR") + "GO_SERVER_ADDR_GERMANY") + _GO_SERVER_ADDR_GERMANY="$value" + ;; + "GO_SERVER_ADDR_TEST") + _GO_SERVER_ADDR_TEST="$value" + ;; + "VAULT_SERVER_ADDR") _VAULT_SERVER_ADDR="$value" ;; "SSH_PRIVATE_KEY_USER") @@ -380,6 +394,24 @@ renewal_crt() { } +test_go3_connection() { + # force only ssh connections without platform features: + _IS_SSH_ONLY=true + # set fake client address: + _PLATFORM_IP_ADDR="${_GO_SERVER_ADDR_TEST}" + _PLATFORM_SSH_PORT=22 + + echo "Run TEST: $_GO_SERVER_ADDR_RUSSIAN connection" + get_access + + echo "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --" + + echo "Run TEST: $_GO_SERVER_ADDR_GERMANY connection" + _GO_SERVER_ADDR="${_GO_SERVER_ADDR_GERMANY}" + get_access +} + + # Parse user options optparser() { # count user-passed options: @@ -420,6 +452,9 @@ optparser() { --go|--go3) _GO_CMD=$(sed 's~[^[:alnum:]/]\+~~g' <<< "$1") ;; + --de) + _GO_SERVER_ADDR="${_GO_SERVER_ADDR_GERMANY}" + ;; --mgrctl|--tty|--ssh) if [[ "$1" == "--mgrctl" ]]; then _IS_MGRCTL_ARGS=true @@ -440,6 +475,10 @@ optparser() { renewal_crt exit 0 ;; + --test|-t) + test_go3_connection + exit 0 + ;; --help|-h) help exit 0