online bottlenecks soak throughtputs
[releng.git] / utils / fetch_k8_conf.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2018 Huawei and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 set -o errexit
10 set -o nounset
11 set -o pipefail
12
13 info ()  {
14     logger -s -t "fetch_k8_conf.info" "$*"
15 }
16
17
18 error () {
19     logger -s -t "fetch_k8_conf.error" "$*"
20     exit 1
21 }
22
23 : ${DEPLOY_TYPE:=''}
24
25 #Get options
26 while getopts ":d:i:a:h:s:o:v" optchar; do
27     case "${optchar}" in
28         d) dest_path=${OPTARG} ;;
29         i) installer_type=${OPTARG} ;;
30         v) DEPLOY_TYPE="virt" ;;
31         *) echo "Non-option argument: '-${OPTARG}'" >&2
32            usage
33            exit 2
34            ;;
35     esac
36 done
37
38 # set vars from env if not provided by user as options
39 dest_path=${dest_path:-$HOME/admin.conf}
40 installer_type=${installer_type:-$INSTALLER_TYPE}
41
42 if [ -z $dest_path ] || [ -z $installer_type ]; then
43     usage
44     exit 2
45 fi
46
47 # Checking if destination path is valid
48 if [ -d $dest_path ]; then
49     error "Please provide the full destination path for the credentials file including the filename"
50 else
51     # Check if we can create the file (e.g. path is correct)
52     touch $dest_path || error "Cannot create the file specified. Check that the path is correct and run the script again."
53 fi
54
55 if [ "$installer_type" == "compass" ]; then
56     info "Fetching admin.conf file on Compass"
57     sudo docker cp compass-tasks:/opt/admin.conf $dest_path &> /dev/null
58     sudo chown $(whoami):$(whoami) $dest_path
59     info "Fetch admin.conf successfully"
60 elif [ "$installer_type" == "joid" ]; then
61     info "Do nothing, config file has been provided in $HOME/joid_config/config for joid"
62 else
63     error "Installer $installer_type is not supported by this script"
64 fi
65