]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Select environments in bin/get-k8s-master-configs
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 28 May 2019 12:53:02 +0000 (14:53 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 28 May 2019 12:53:02 +0000 (14:53 +0200)
bin/get-k8s-master-configs

index 6bfc3e497b8d7a02fafcf7e51bbc69655cee9ee8..0905b8d59f520b8aef1c0078de46611a670e6e47 100755 (executable)
@@ -7,7 +7,7 @@ VERBOSE="n"
 DEBUG="n"
 QUIET='n'
 
-VERSION="0.1"
+VERSION="0.2"
 
 # console colors:
 RED=""
@@ -24,6 +24,24 @@ BASE_DIR="$(dirname ${0})"
 REL_K8S_CFGDIR='.kube'
 REL_K8S_CFGFILE='config.yaml'
 
+declare -A ENV_HOST=()
+declare -A ENV_PORT=()
+declare -A ENV_USER=()
+declare -A ENV_GROUP=()
+declare -A ENV_HOME=()
+
+ENV_HOST['live']='live-master01-k8s-spk.spk.pixelpark.net'
+ENV_HOST['stage']='stage-master01-k8s-spk.spk.pixelpark.net'
+
+ENV_PORT['live']=1080
+ENV_PORT['stage']=1080
+
+ENV_USER['live']='k8s-live'
+ENV_USER['stage']='k8s-stage'
+
+ENV_GROUP['live']='users'
+ENV_GROUP['stage']='users'
+
 #-------------------------------------------------------------------
 detect_color() {
 
@@ -171,6 +189,12 @@ get_options() {
         exit 1
     fi
 
+    if [[ "$( type -t curl || true )" != "file" ]] ; then
+        error "Command '${RED}curl${NORMAL}' not found, please install the appropriate package."
+        echo >&2
+        exit 5
+    fi
+
     local cur_user_id=$( id -u )
     if [[ "${cur_user_id}" != "0" ]] ; then
         error "Wrong user '${RED}$( id -u -n )${NORMAL}'."
@@ -217,6 +241,31 @@ error() {
     echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASENAME}:${RED}ERROR${NORMAL}]: $@" >&2
 }
 
+#------------------------------------------------------------------------------
+get_config() {
+
+    local env="$1"
+
+    info "Get current Kubernetes configuration for environment '${GREEN}${env}${NORMAL}'."
+
+    local host="${ENV_HOST[${env}]}"
+    local port="${ENV_PORT[${env}]}"
+    local user="${ENV_USER[${env}]}"
+    local group="${ENV_GROUP[${env}]}"
+
+    local url="http://${host}"
+    if [[ "${port}" != "80" ]] ; then
+        url+=":${port}"
+    fi
+    url+="/"
+    debug "URL to get the config: '${url}'."
+
+    local user_home=$( getent passwd "${user}" | head -n 1 | awk -F: '{print $6}' )
+    debug "Home diectory of user '${user}': '${user_home}'"
+
+
+}
+
 ################################################################################
 ##
 ## Main
@@ -227,6 +276,8 @@ error() {
 main() {
 
     get_options "$@"
+    get_config 'live'
+    get_config 'stage'
 
 }