-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgenerate_clid.sh
executable file
·61 lines (51 loc) · 1.82 KB
/
generate_clid.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
#!/bin/bash
# Generate NUXEO_CLID and add to the .env file.
set -euf
NUXEO_ENV=".env"
ERR=""
TMP_DIR=$(mktemp -d)
mkdir -p ${TMP_DIR}
chmod 777 ${TMP_DIR}
CONF_DIR=$(readlink -f ./conf)
NUXEO_CLID=$(grep '^NUXEO_CLID' ${NUXEO_ENV} | tail -n 1 | cut -d '=' -f2)
if [ -n "${NUXEO_CLID}" ]; then
echo "NUXEO_CLID appears to be configured in ${NUXEO_ENV} or your system environment. Remove and then run this script again."
exit 2
fi
FROM_IMAGE=$(grep '^NUXEO_IMAGE' ${NUXEO_ENV} | tail -n 1 | cut -d '=' -f2)
if [ -z "${FROM_IMAGE}" ]; then
FROM_IMAGE="docker.packages.nuxeo.com/nuxeo/nuxeo:latest"
echo "Upstream image 'NUXEO_IMAGE' is not set in ${NUXEO_ENV}, using: ${FROM_IMAGE}"
fi
STUDIO_USERNAME=$(grep '^STUDIO_USERNAME' ${NUXEO_ENV} | tail -n 1 | cut -d '=' -f2)
if [ -z "${STUDIO_USERNAME}" ]; then
echo "'STUDIO_USERNAME' is not set, please configure ${NUXEO_ENV}"
ERR="yes"
fi
APPLICATION_NAME=$(grep '^APPLICATION_NAME' ${NUXEO_ENV} | tail -n 1 | cut -d '=' -f2)
if [ -z "${APPLICATION_NAME}" ]; then
echo "'APPLICATION_NAME' (project name) is not set, please configure ${NUXEO_ENV}"
ERR="yes"
fi
STUDIO_CREDENTIALS=$(grep '^STUDIO_CREDENTIALS' ${NUXEO_ENV} | tail -n 1 | cut -d '=' -f2)
if [ -z "${STUDIO_CREDENTIALS}" ]; then
echo "'STUDIO_CREDENTIALS' are not set, please configure ${NUXEO_ENV}"
ERR="yes"
fi
if [ -n "${ERR}" ]; then
rm -rf ${TMP_DIR}
exit 1
fi
docker run --rm -v ${TMP_DIR}:/var/lib/nuxeo/:rw -v ${CONF_DIR}:/etc/nuxeo/conf.d/:ro ${FROM_IMAGE}\
nuxeoctl register "${STUDIO_USERNAME}" "${APPLICATION_NAME}" "dev" "Docker" "${STUDIO_CREDENTIALS}"
CLID="${TMP_DIR}/instance.clid"
# Write CLID to file
if [ -f ${CLID} ]; then
echo -n "NUXEO_CLID=" >> ${NUXEO_ENV}
awk 1 ORS="--" ${CLID} >> ${NUXEO_ENV}
echo "" >> ${NUXEO_ENV}
rm -rf ${TMP_DIR}
else
rm -rf ${TMP_DIR}
exit 2
fi