#!/command/with-contenv bash
# shellcheck shell=bash

set -e

. /bin/common.sh

if [ "$(is_true "$DEBUG")" = '1' ]; then
	set -x
fi

log_info 'Starting backend ...'

if [ "$(is_true "$DEVELOPMENT")" = '1' ]; then
	HOME=$NPMHOME
	GOPATH="$HOME/go"
	mkdir -p "$GOPATH"
	chown -R "$PUID:$PGID" "$GOPATH"
	export HOME GOPATH
	rm -rf /app/backend/.task
	cd /app/backend || exit 1
	exec s6-setuidgid "$PUID:$PGID" task -w
else
	cd /app/bin || exit 1
	exec s6-setuidgid "$PUID:$PGID" /app/bin/server
fi
