-
Notifications
You must be signed in to change notification settings - Fork 9
/
bootstrap.sh
executable file
·66 lines (57 loc) · 1.77 KB
/
bootstrap.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
#!/bin/sh
_ctl=./bin/fedboxctl
_env=${1}
if ! expect -v &> /dev/null ; then
echo "Unable to find 'expect' command, which is required"
exit 1
fi
_ENV_FILE="./.env"
if [[ ! -f ${_ENV_FILE} ]]; then
_ENV_FILE="./.env.${_env}"
fi
if [ ! -f "${_ENV_FILE}" ]; then
echo "Invalid configuration file ${_ENV_FILE}"
exit 1
fi
source ${_ENV_FILE}
if [[ -z "${FEDBOX_HOSTNAME}" ]]; then
FEDBOX_HOSTNAME=${HOSTNAME}
fi
if [[ -z "${FEDBOX_HOSTNAME}" ]]; then
echo "Missing fedbox hostname in environment";
exit 1
fi
if [[ -z "${OAUTH2_SECRET}" ]]; then
echo "Missing OAuth2 secret in environment";
exit 1
fi
if [[ -z "${OAUTH2_CALLBACK_URL}" ]]; then
echo "Missing OAuth2 callback url in environment";
exit 1
fi
_FULL_PATH="${STORAGE_PATH}/${ENV}/${FEDBOX_HOSTNAME}"
if [[ -d "${_FULL_PATH}" ]]; then
echo "skipping bootstrapping ${_FULL_PATH}"
else
# create storage
${_ctl} bootstrap
fi
_HAVE_OAUTH2_SECRET=$(grep OAUTH2_SECRET "${_ENV_FILE}" | cut -d'=' -f2 | tail -n1)
_HAVE_OAUTH2_CLIENT=$(${_ctl} oauth client ls | grep -c "${OAUTH2_KEY}")
if [[ ${_HAVE_OAUTH2_CLIENT} -ge 1 && "z${_HAVE_OAUTH2_SECRET}" == "z${OAUTH2_SECRET}" ]]; then
echo "skipping adding OAuth2 client"
else
# add oauth2 client for Brutalinks
echo OAUTH2_APP=$(./tools/clientadd.sh "${OAUTH2_SECRET}" "${OAUTH2_CALLBACK_URL}" | grep Client | tail -1 | awk '{print $3}')
echo OAUTH2_SECRET="${OAUTH2_SECRET}"
fi
_ADMIN_NAME=admin
_HAVE_ADMIN=$(${_ctl} ap ls --type Person | jq -r .[].preferredUsername | grep -c "${_ADMIN_NAME}")
if [[ ${_HAVE_ADMIN} -ge 1 ]]; then
echo "skipping adding user ${_ADMIN_NAME}"
else
if [[ -n "${ADMIN_PW}" ]]; then
# add admin user for Brutalinks
./tools/useradd.sh "${_ADMIN_NAME}" "${ADMIN_PW}"
fi
fi