#!/bin/bash

ROOT_DATA=${ROOT_DATA:-/data}
DATA_REPO=${DATA_REPO:-$ROOT_DATA/repo}
DATA_DOC=${DATA_DOC:-$ROOT_DATA/doc}
DATA_DBS=${DATA_DBS:-$ROOT_DATA/dbs}
DATA_WEBHOOKS=${DATA_WEBHOOKS:-$ROOT_DATA/webhooks}

sudo mkdir -p $ROOT_DATA
sudo chown -R $(id -u):$(id -g)  $ROOT_DATA

if [ ! -r ".env" ] ; then 
	echo "# Env settings " >.env
	# Set your data directory, this is where gitea save files
	echo "GITEA_DATA_DIR=$DATA_REPO" >>.env

	echo "DOC_DIR=$DATA_DOC" >>.env
	echo "DBS_DIR=$DATA_DBS" >>.env
	echo "WEBHOOKS_DIR=$DATA_WEBHOOKS" >>.env
fi

sudo mkdir -p $GITEA_DATA_DIR/gitea/conf
sudo mkdir -p $DATA_DOC
sudo mkdir -p $DATA_DBS

[ -r "bin/apply.sh" ] && ./bin/apply.sh 

exit 0

