-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsetup-environment.sh
113 lines (88 loc) · 2.31 KB
/
setup-environment.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
101
102
103
104
105
106
107
108
109
110
111
112
113
fail()
{
echo "Error:" $* 1>&2
exit 1
}
warn()
{
echo "Warning:" $* 1>&2
}
trim()
{
local trimmed="$1"
# Strip leading space.
trimmed="${trimmed## }"
# Strip trailing space.
trimmed="${trimmed%% }"
echo "$trimmed"
}
SCRIPTS_DIR=`dirname $0`
WORKSHOP_DIR=`dirname $SCRIPTS_DIR`
SOURCE_DIR=`dirname $WORKSHOP_DIR`
REPOSITORY_NAME=`basename $SOURCE_DIR`
if [ `basename $WORKSHOP_DIR` != ".workshop" ]; then
fail "Failed to find workshop directory."
exit 1
fi
echo "### Reading the default configuration."
. $SCRIPTS_DIR/default-settings.sh
echo "### Reading the workshop configuration."
if [ ! -f $WORKSHOP_DIR/settings.sh ]; then
warn "Cannot find any workshop settings."
else
. $WORKSHOP_DIR/settings.sh
fi
if [ x"$SETTINGS_NAME" != x"" ]; then
if [ ! -f $WORKSHOP_DIR/$SETTINGS_NAME-settings.sh ]; then
warn "Cannot find any custom workshop settings."
else
. $WORKSHOP_DIR/$SETTINGS_NAME-settings.sh
fi
fi
for key in "${overrides[@]}"; do
case $key in
@*)
file="${key#*@}"
if [ -f "$file" ]; then
. $file
fi
;;
*)
mapped_key="override_${key}"
value="${!mapped_key}"
declare ${key}="${value}"
;;
esac
done
if [ x"$WORKSHOP_IMAGE" == x"" ]; then
WORKSHOP_IMAGE=$DASHBOARD_IMAGE
fi
if [ -f "$WORKSHOP_DIR/jupyterhub_config.py" ]; then
JUPYTERHUB_CONFIG=`cat $WORKSHOP_DIR/jupyterhub_config.py`
fi
if [ -f "$WORKSHOP_DIR/jupyterhub_config.sh" ]; then
JUPYTERHUB_ENVVARS=`cat $WORKSHOP_DIR/jupyterhub_config.sh`
fi
if [ -f "$WORKSHOP_DIR/terminal.sh" ]; then
TERMINAL_ENVVARS=`cat $WORKSHOP_DIR/terminal.sh`
fi
if [ -f "$WORKSHOP_DIR/workshop.sh" ]; then
WORKSHOP_ENVVARS=`cat $WORKSHOP_DIR/workshop.sh`
fi
if [ -f "$WORKSHOP_DIR/gateway.sh" ]; then
GATEWAY_ENVVARS=`cat $WORKSHOP_DIR/gateway.sh`
fi
echo "### Setting the workshop application."
WORKSHOP_NAME=${WORKSHOP_NAME:-$REPOSITORY_NAME}
if [ x"$NAMESPACE" == x"" ]; then
NAMESPACE=`oc project --short 2>/dev/null`
fi
if [ x"$NAMESPACE" == x"" ]; then
fail "Cannot determine name of project."
exit 1
fi
oc get project "$NAMESPACE" > /dev/null 2>&1
if [ "$?" != "0" ]; then
fail "Project $NAMESPACE does not exist."
exit 1
fi