-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploymentArgument.lib
executable file
·82 lines (76 loc) · 1.99 KB
/
deploymentArgument.lib
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
################################################################
# This is shared library
################################################################
get_deployment_name()
{
case $1 in
aks)
DEPLOYMENT_NAME="Azure AKS"
;;
eks)
DEPLOYMENT_NAME="AWS EKS"
;;
ocp)
DEPLOYMENT_NAME="OpenShift on Google GKE"
;;
gke)
DEPLOYMENT_NAME="Google GKE"
;;
*)
DEPLOYMENT_NAME=$1
;;
esac
}
show_deployment_help()
{
echo ""
echo "============================================="
echo "Missing or Invalid 'deployment type' argument. "
echo "Valid 'deployment types' are:"
echo ""
echo "eks = AWS"
echo "aks = Azure"
#echo "ocp = Open Shift"
echo "gke = Google"
echo "============================================="
echo ""
exit 1
}
validate_deployment_argument() {
# Validate passed in an argument.
# If don't pass is in then attempt to look for value in creds.json
if [ -z $1 ]; then
# if jq not installed, then can not parse file so show the help
# if it is, then look for value in creds.json
command -v jq &> /dev/null
if [ $? -ne 0 ]; then
show_deployment_help
else
DEPLOYMENT=$(cat creds.json | jq -r '.deployment')
if [ -z "$DEPLOYMENT" ]
then
show_deployment_help
fi
fi
else
DEPLOYMENT=$1
fi
# Validate Deployment argument value
# uncomment as enable these....
#OK=0 ; DEPLOY_TYPES="ocp eks gke aks"
OK=0 ; DEPLOY_TYPES="eks aks gke"
for DT in $DEPLOY_TYPES ; do [ $DEPLOYMENT == $DT ] && { OK=1 ; break; } ; done
if [ $OK -eq 0 ]; then
show_deployment_help
fi
# ths will store name into DEPLOYMENT_NAME variable
get_deployment_name $DEPLOYMENT
# update creds file with new value
if [ -f ./creds.json ]; then
cp ./creds.json ./creds.json.bak 2> /dev/null
else
cp ./creds.sav ./creds.json.bak 2> /dev/null
fi
cat creds.json.bak | \
sed -e 's/"deployment": ".*/"deployment": "'$DEPLOYMENT'",/g' > creds.json
}