<commit_before>#!/usr/bin/env bash

set -e
set -m

[ -z "${COZY_STACK_HOST}" ] && COZY_STACK_HOST="cozy.tools"
[ -z "${COZY_STACK_PORT}" ] && COZY_STACK_PORT="8080"
[ -z "${COZY_STACK_PASS}" ] && COZY_STACK_PASS="<PASSWORD>"
[ -z "${COZY_STACK_ADMIN_PORT}" ] && COZY_STACK_ADMIN_PORT="6060"
[ -z "${COUCHDB_URL}" ] && COUCHDB_URL="http://localhost:5984/"

if [ -d "${COZY_STACK_PATH}" ] && [ -f "${COZY_STACK_PATH}/cozy-stack" ]; then
	COZY_STACK_PATH="${COZY_STACK_PATH}/cozy-stack"
fi

echo_err() {
	>&2 echo -e "error: ${1}"
}

real_path() {
	[[ "${1}" = /* ]] && echo "${1}" || echo "${PWD}/${1#./}"
}

usage() {
	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.tools."
	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."
}

do_start() {
	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 ":${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 "${COZY_STACK_HOST}" \
		--port "${COZY_STACK_PORT}" \
		--admin-port "${COZY_STACK_ADMIN_PORT}" \
		--couchdb-url "${COUCHDB_URL}" \
		--mail-host "${COZY_STACK_HOST}" \
		--mail-port 1025 \
		--mail-disable-tls \
		--fs-url "file://localhost${vfsdir}" &

	wait_for "${COZY_STACK_HOST}:${COZY_STACK_PORT}/version/" "cozy-stack"

	if [ "${COZY_STACK_PORT}" = "80" ]; then
		cozy_dev_addr="${COZY_STACK_HOST}"
	else
		cozy_dev_addr="${COZY_STACK_HOST}:${COZY_STACK_PORT}"<commit_msg>Fix the cozy-app-dev image for docker (#1737)<commit_after>#!/usr/bin/env bash

set -e
set -m

[ -z "${COZY_STACK_HOST}" ] && COZY_STACK_HOST="cozy.tools"
[ -z "${COZY_STACK_PORT}" ] && COZY_STACK_PORT="8080"
[ -z "${COZY_STACK_PASS}" ] && COZY_STACK_PASS="<PASSWORD>"
[ -z "${COZY_STACK_ADMIN_PORT}" ] && COZY_STACK_ADMIN_PORT="6060"
[ -z "${COUCHDB_URL}" ] && COUCHDB_URL="http://localhost:5984/"

if [ -d "${COZY_STACK_PATH}" ] && [ -f "${COZY_STACK_PATH}/cozy-stack" ]; then
	COZY_STACK_PATH="${COZY_STACK_PATH}/cozy-stack"
fi

echo_err() {
	>&2 echo -e "error: ${1}"
}

real_path() {
	[[ "${1}" = /* ]] && echo "${1}" || echo "${PWD}/${1#./}"
}

usage() {
	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.tools."
	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."
}

do_start() {
	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 ":${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}" \
		--port "${COZY_STACK_PORT}" \
		--admin-port "${COZY_STACK_ADMIN_PORT}" \
		--couchdb-url "${COUCHDB_URL}" \
		--mail-port 1025 \
		--mail-disable-tls \
		--fs-url "file://localhost${vfsdir}" &

	wait_for "${COZY_STACK_HOST}:${COZY_STACK_PORT}/version/" "cozy-stack"

	if [ "${COZY_STACK_PORT}" = "80" ]; then
		cozy_dev_addr="${COZY_STACK_HOST}"
	else
		cozy_dev_addr="${COZY_STACK_HOST}:${COZY_STACK_PORT}"
{'fraction_non_alphanumeric': 0.18047882136279927, 'fraction_numerical': 0.010766397506728998, 'mean_word_length': 3.0951276102088165, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '82556', 'n_tokens_mistral': 3117, 'n_tokens_neox': 2874, 'n_words': 757}