Newer
Older
[ -z "${COZY_STACK_HOST}" ] && COZY_STACK_HOST="cozy.tools"
[ -z "${COZY_STACK_PORT}" ] && COZY_STACK_PORT="8080"
[ -z "${COZY_STACK_PASS}" ] && COZY_STACK_PASS="cozy"
[ -z "${COZY_STACK_ADMIN_PORT}" ] && COZY_STACK_ADMIN_PORT="6060"
[ -z "${COUCHDB_URL}" ] && COUCHDB_URL="http://localhost:5984/"
[ -n "${COZY_KONNECTORS_CMD}" ] && COZY_KONNECTORS_CMD_OPTION="--konnectors-cmd $COZY_KONNECTORS_CMD"
if [ -d "${COZY_STACK_PATH}" ] && [ -f "${COZY_STACK_PATH}/cozy-stack" ]; then
[[ "${1}" = /* ]] && echo "${1}" || echo "${PWD}/${1#./}"
echo -e "Usage: ${0} [-hu] [-d <app path>] [–f <fs directory>]"
echo -e ""
echo -e " -d <app path> specify the application directory to serve"
echo -e " -f <app path> specify the fs directory (optional)"
echo -e " -u try to update cozy-stack on start"
echo -e " -h show this usage message"
echo -e "\nEnvironment variables"
echo -e "\n COZY_STACK_PATH"
echo -e " specify the path of the cozy-stack binary folder or the binary"
echo -e " itself. default: \"\$GOPATH/bin\"."
echo -e "\n COZY_STACK_HOST"
echo -e " specify the hostname on which the cozy-stack is launched."
echo -e " default: cozy.localhost."
echo -e "\n COZY_STACK_PORT"
echo -e " specify the port on which the cozy-stack is listening."
echo -e " default: 8080."
echo -e "\n COZY_STACK_ADMIN_PORT"
echo -e " specify the admin port on which the cozy-stack is listening."
echo -e " default: 6060."
echo -e "\n COZY_STACK_PASS"
echo -e " specify the password to register the instance with."
echo -e " default: cozy."
echo -e "\n COUCHDB_URL"
echo -e " specify the URL of the CouchDB database. If specified,"
echo -e " the script won't try to start couchdb."
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
114
115
116
117
118
119
if [ -z "${COZY_STACK_PATH}" ]; then
COZY_STACK_PATH="${GOPATH}/bin/cozy-stack"
if [ ! -f "${COZY_STACK_PATH}" ]; then
if [ -z "$(command -v go)" ]; then
echo_err "executable \"go\" not found in \$PATH"
exit 1
fi
printf "installing cozy-stack... "
go get "github.com/cozy/cozy-stack"
echo "ok"
fi
fi
if [ -n "${cozy_stack_version}" ]; then
echo_err "not implemented... we do not have a release yet"
exit 1
fi
if [ "$update" = true ]; then
printf "updating cozy-stack... "
go get -u "github.com/cozy/cozy-stack"
echo "ok"
fi
trap 'kill $(jobs -p)' SIGINT SIGTERM EXIT
check_not_running "localhost:${COZY_STACK_PORT}" "cozy-stack"
do_check_couchdb
if [ -n "${appdir}" ]; then
if [ -f "${appdir}/manifest.webapp" ]; then
slug="app"
else
appsdir=""
for i in ${appdir}/*; do
if [ -f "${i}/manifest.webapp" ]; then
appsdir="${appsdir},$(basename "$i"):${i}"
fi
if [ -z "$slug" ]; then
slug=$(basename "$i")
fi
done
if [ -z "${appsdir}" ]; then
echo_err "No manifest found in ${appdir}"
exit 1
fi
appdir=${appsdir:1}
fi
fi
echo "starting cozy-stack with ${vfsdir}..."
${COZY_STACK_PATH} serve --allow-root \
--appdir "${appdir}" \
--host "::" \
--port "${COZY_STACK_PORT}" \
--admin-port "${COZY_STACK_ADMIN_PORT}" \
--couchdb-url "${COUCHDB_URL}" \
--mailhog \
${COZY_KONNECTORS_CMD_OPTION} \
--fs-url "file://localhost${vfsdir}" &
wait_for "localhost:${COZY_STACK_PORT}/version/" "cozy-stack"
if [ "${COZY_STACK_PORT}" = "80" ]; then
cozy_dev_addr="cozy.tools"
cozy_dev_addr="cozy.tools:${COZY_STACK_PORT}"
fi
echo ""
do_create_instances
if [ -n "${slug}" ]; then
echo "Everything is setup. Go to http://${slug}.${cozy_dev_addr}/"
fi
echo "To exit, press ^C"
fg 1 > /dev/null
printf "waiting for couchdb..."
wait_for "${COUCHDB_URL}" "couchdb"
echo "ok"
printf "checking couchdb on %s... " "${COUCHDB_URL}"
couch_test=$(curl -s -XGET "${COUCHDB_URL}" || echo "")
couch_vers=$(grep "\"version\":\s*\"2" <<< "${couch_test}" || echo "")
if [ -z "${couch_test}" ]; then
echo "failed"
echo_err "could not reach couchdb on ${COUCHDB_URL}"
exit 1
elif [ -z "${couch_vers}" ]; then
echo "failed"
echo_err "couchdb v1 is running on ${COUCHDB_URL}"
echo_err "you need couchdb version >= 2"
exit 1
fi
echo "ok"
for dbname in "_users" "_replicator"; do
curl -s -XPUT "${COUCHDB_URL}/${dbname}" > /dev/null
done
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
printf "creating instance %s" "${cozy_dev_addr}"
if [ -n "${COZY_STACK_PASS}" ]; then
printf " using passphrase \"%s\"" "${COZY_STACK_PASS}"
fi
printf "... "
set +e
add_instance_val=$(
${COZY_STACK_PATH} instances add \
--context-name dev \
--email dev@cozy.io \
--public-name "Jane Doe" \
--passphrase ${COZY_STACK_PASS} \
"${cozy_dev_addr}" 2>&1
)
add_instance_ret="${?}"
set -e
if [ "${add_instance_ret}" = "0" ]; then
echo "ok"
else
exists_test=$(grep -i "already exists" <<< "${add_instance_val}" || echo "")
if [ -z "${exists_test}" ]; then
echo_err "\n${add_instance_val} ${add_instance_ret}"
exit 1
fi
echo "ok (already created)"
fi
do_install_app
echo "Installing apps (home, collect..)"
if cozy-stack apps ls | grep 'home'; then
echo "Removing home..."
cozy-stack apps uninstall home
fi
if cozy-stack apps ls | grep 'collect'; then
echo "Removing collect..."
cozy-stack apps uninstall collect
fi
echo "Installing home, collect, store..."
echo "App succesfully installed"
echo "Installing konnectors"
if cozy-stack konnectors ls | grep 'enedisgrandlyon'; then
echo "Removing konnector enedisgrandlyon..."
cozy-stack konnectors uninstall enedisgrandlyon
if cozy-stack konnectors ls | grep 'grdfgrandlyon'; then
echo "Removing konnector grdfgrandlyon..."
cozy-stack konnectors uninstall grdfgrandlyon
if cozy-stack konnectors ls | grep 'eglgrandlyon'; then
echo "Removing konnector eglgrandlyon..."
cozy-stack konnectors uninstall eglgrandlyon
cozy-stack konnectors install --domain cozy.tools:8080 enedisgrandlyon git://forge.grandlyon.com/web-et-numerique/llle_project/enedis-konnector.git#build
cozy-stack konnectors install --domain cozy.tools:8080 grdfgrandlyon git://forge.grandlyon.com/web-et-numerique/llle_project/grdf-konnector.git#build
cozy-stack konnectors install --domain cozy.tools:8080 eglgrandlyon git://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git#build
i="0"
while ! LC_NUMERIC=C curl -s --max-time 0.5 -XGET "${1}" > /dev/null; do
sleep 0.5
i=$((i+1))
if [ "${i}" -gt "100" ]; then
echo_err "could not listen to ${2} on ${1}"
exit 1
fi
done
printf "checking that %s is free... " "${1}"
if curl -s --max-time 1 -XGET "${1}" > /dev/null; then
printf "\n"
echo_err "${2} is already running on ${1}"
exit 1
fi
echo "ok"
}
update=false
while getopts ":hud:f:v:" optname; do
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
case "${optname}" in
"h")
usage
exit 0
;;
"d")
appdir="${OPTARG}"
;;
"u")
update=true
;;
"f")
vfsdir="${OPTARG}"
;;
"v")
cozy_stack_version="${OPTARG}"
;;
":")
echo_err "Option -${OPTARG} requires an argument"
echo_err "Type ${0} -h"
exit 1
;;
"?")
echo_err "Invalid option ${OPTARG}"
echo_err "Type ${0} -h"
exit 1
;;
esac
done
if [ -n "${appdir}" ] && [ ! -d "${appdir}" ]; then
echo_err "Application directory ${appdir} does not exit"
exit 1
fi
[ -n "${appdir}" ] && appdir=$(real_path "${appdir}")
[ -n "${vfsdir}" ] && vfsdir=$(real_path "${vfsdir}")
do_start
exit 0