-
Notifications
You must be signed in to change notification settings - Fork 28
/
one-time-setup.sh
executable file
·82 lines (71 loc) · 2.07 KB
/
one-time-setup.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
#!/bin/bash
RED='\033[0;31m' # Error color
YELLOW='\033[0;33m' # Warning color
NC='\033[0m' # No Color
set -u
DIR="."
GetPathToCurrentlyExecutingScript () {
# Absolute path of this script, e.g. /opt/corda/node/foo.sh
set +e
ABS_PATH=$(readlink -f "$0" 2>&1)
if [ "$?" -ne "0" ]; then
echo "Using macOS alternative to readlink -f command..."
# Unfortunate MacOs issue with readlink functionality, see https://github.com/corda/corda-kubernetes-deployment/issues/4
TARGET_FILE=$0
cd $(dirname $TARGET_FILE)
TARGET_FILE=$(basename $TARGET_FILE)
ITERATIONS=0
# Iterate down a (possible) chain of symlinks
while [ -L "$TARGET_FILE" ]
do
TARGET_FILE=$(readlink $TARGET_FILE)
cd $(dirname $TARGET_FILE)
TARGET_FILE=$(basename $TARGET_FILE)
ITERATIONS=$((ITERATIONS + 1))
if [ "$ITERATIONS" -gt 1000 ]; then
echo "symlink loop. Critical exit."
exit 1
fi
done
# Compute the canonicalized name by finding the physical path
# for the directory we're in and appending the target file.
PHYS_DIR=$(pwd -P)
ABS_PATH=$PHYS_DIR/$TARGET_FILE
fi
# Absolute path of the directory this script is in, thus /opt/corda/node/
DIR=$(dirname "$ABS_PATH")
}
GetPathToCurrentlyExecutingScript
set -eu
checkStatus () {
status=$1
if [ $status -eq 0 ]
then
echo "."
else
echo -e "${RED}ERROR${NC}"
echo "The previous step failed"
exit 1
fi
return 0
}
OneTimeSetup () {
echo "====== One Time Setup Script ====== "
$DIR/docker-images/build_docker_images.sh
checkStatus $?
$DIR/docker-images/push_docker_images.sh
checkStatus $?
$DIR/corda-pki-generator/generate_firewall_pki.sh
checkStatus $?
INITIAL_REGISTRATION=""
INITIAL_REGISTRATION=$(grep -A 3 'initialRegistration:' $DIR/helm/values.yaml | grep 'enabled: ' | cut -d ':' -f 2 | xargs)
if [ "$INITIAL_REGISTRATION" = "true" ]; then
$DIR/helm/initial_registration/initial_registration.sh
checkStatus $?
else
echo -e "${YELLOW}Warning${NC}"
echo "Skipping initial registration step. (disabled in values.yaml)"
fi
echo "====== One Time Setup Script completed. ====== "
}
OneTimeSetup