-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathcommon.sh
More file actions
executable file
·66 lines (58 loc) · 1.82 KB
/
Copy pathcommon.sh
File metadata and controls
executable file
·66 lines (58 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# ==============================
# COMMON FUNCTIONS
# ==============================
RED="\033[31m"
BLUE="\033[94m"
GREEN="\033[32m"
ENDCOLOR="\033[0m"
function print_error {
echo -e "${RED}\n==========================================${ENDCOLOR}"
echo -e "${RED} FAILED${ENDCOLOR}"
echo -e "${RED}==========================================\n${ENDCOLOR}"
echo -e "${RED}$1${ENDCOLOR}"
echo -e ""
}
function print_msg {
echo -e "${BLUE}$1${ENDCOLOR}"
}
function print_success {
echo -e "${GREEN}$1${ENDCOLOR}"
}
# Helper function to check whether prerequisites are installed
function check_prerequisites {
# Ensure that jq tool is installed
if ! command -v jq &>/dev/null; then
print_error "'jq' tool is not installed"
exit 1
fi
}
# ==============================
# COMMON IBMCLOUD HELPERS
# ==============================
# helper function to check whether IBM Cloud CLI plugins should get updated, or not
function ensure_plugin_is_up_to_date() {
echo "Checking $1 ..."
# check whether plugin is installed
if ! ibmcloud plugin show $1 -q >/dev/null; then
# install it
ibmcloud plugin install $1 -f --quiet
else
# check whether there is an update available
ibmcloud plugin update $1 -f --quiet
fi
}
function target_region {
print_msg "\nTargetting IBM Cloud region '$1' ..."
current_region=$(ibmcloud target --output JSON |jq -r '.region|.name')
if [[ "$current_region" != "$1" ]]; then
ibmcloud target -r $1 --quiet
fi
}
function target_resource_group {
print_msg "\nTargetting resource group '$resource_group_name' ..."
current_resource_group=$(ibmcloud target --output JSON |jq -r '.resource_group|.name')
if [[ "$current_resource_group" != "$1" ]]; then
ibmcloud target -g $1 --quiet
fi
}