-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.sh
executable file
·100 lines (80 loc) · 2.32 KB
/
demo.sh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh
##### VARS ##############
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
blue=$(tput setaf 4)
cyan=$(tput setaf 6)
normal=$(tput sgr0)
RELEASE_NAME=vault-demo
##### HELPERS ###########
function printActionHeader() {
printf "\n${yellow}################################################################################\n"
printf "%*s\n" $(((${#1}+80)/2)) "${2}${1}"
printf "################################################################################${normal}\n"
}
function printSuccess() {
printf '\033[79`%s\n' "${green}OK${normal}"
}
function printFailure() {
printf '\033[75`%s\n' "${red}FAILED${normal}"
}
function printFailureAndExit() {
printf "${1} ${red}FAILED${normal}"
exit 1
}
function waitToContinue() {
printf "\npress any key to continue..."
read -n 1
}
function waitToContinueSilent() {
read -n 1
}
function check() {
[[ $? = 0 ]] && printSuccess || printFailureAndExit ${1}
}
function printfColor() {
printf "$2$1${normal}"
}
function printStep() {
printf "$1"
}
function printCmd() {
printf "\n==> COMMAND: ${green}$1${normal}"
waitToContinueSilent
}
function loadUnsealKeys() {
unsealKey1=$(awk '/Unseal Key 1:/{print $NF}' generated/$1.txt)
unsealKey2=$(awk '/Unseal Key 2:/{print $NF}' generated/$1.txt)
unsealKey3=$(awk '/Unseal Key 3:/{print $NF}' generated/$1.txt)
rootToken=$(awk '/Initial Root Token:/{print $NF}' generated/$1.txt)
}
function getPhase() {
oc get pod $1 -o=jsonpath='{.status.phase}'
}
function init() {
printActionHeader "INITIALIZE"
oc project ${1}
[[ $? = 1 ]] && oc new-project ${1}
open https://play.gepaplexx.com/k8s/ns/vault-demo/pods
mkdir -p generated
}
function deleteAndInitVaultPod() {
oc delete pod $RELEASE_NAME-2
waitToContinue
oc exec $RELEASE_NAME-2 -- vault operator unseal $unsealKey1 > /dev/null
oc exec $RELEASE_NAME-2 -- vault operator unseal $unsealKey2 > /dev/null
oc exec $RELEASE_NAME-2 -- vault operator unseal $unsealKey3 > /dev/null
waitToContinue
}
function main() {
init ${1}
. steps/01-setup-vault.sh
. steps/02-insert-secrets.sh
. steps/03-deploy-app.sh
. cleanup/cleanup-app-without-db.sh
. steps/04-setup-vault-autounseal.sh
. steps/05-deploy-app-with-db.sh
}
# 1 .. Openshift Project
main "${1}"