#!/bin/bash [[ ! $GITEA_DIR ]] && export GITEA_DIR="$(dirname "$(cd "$(readlink -f "$BASH_SOURCE")"; pwd -P)")" source $GITEA_DIR/scripts/library declare OPTARG declare OPTION while getopts 'r:' OPTION; do case "$OPTION" in r) GITEA_DATA_DIR=$OPTARG ;; *) ;; esac done shift $(( OPTIND - 1 )) export GITEA_INSTANCE=${1:-default} export GITEA_BIN="$GITEA_DIR/gitea.bin" [[ ! -f $GITEA_BIN ]] && $GITEA_DIR/scripts/upgrade [[ ! $(version) ]] && echo $GITEA_DIR/gitea.bin missing or corrupt if [[ ! $GITEA_DATA_DIR ]]; then GITEA_DATA_DIR=$GITEA_DIR/data else [[ ! $GITEA_DATA_DIR == /* ]] && { echo "repo directory $GITEA_DATA_DIR was not absolute, aborting" ; exit; } fi export GITEA_DATA_DIR INI=$GITEA_DIR/config/$GITEA_INSTANCE if ([[ -f "$INI.tmpl" ]] && [[ ! -f $GITEA_DATA_DIR/db/git.db ]]); then # if database does not exist unlock the install page so default user can be set # && LOCK=true # https://stackoverflow.com/a/22819516/4695378 # search and replace data subdirectory entries in template file cat $INI.tmpl | sed 's:@@_server_dir:'$GITEA_DATA_DIR':'g | sed 's:\(INSTALL_LOCK *= \)\(.*\):\1'${LOCK:-false}':' > $INI.ini # TODO could replace other values as well fi [[ ! -f "$INI.ini" ]] && { echo "no ini file $INI.ini, aborting" ; exit; } # echo $GITEA_DATA_DIR # echo $GITEA_DIR # echo $ARCH ${ARCHES[$ARCH]} $GITEA_BIN mkdir -p $GITEA_DATA_DIR 2>/dev/null || { echo "unable to make repos directory at $GITEA_DATA_DIR, exiting"; exit; } # setup the custom directory in /current mkdir -p $GITEA_DIR/frontend/current rsync -a --delete $GITEA_DIR/frontend/default/ $GITEA_DIR/frontend/current [[ -d $GITEA_DIR/frontend/$GITEA_INSTANCE ]] && rsync -a $GITEA_DIR/frontend/$GITEA_INSTANCE/ $GITEA_DIR/frontend/current export GITEA_WORK_DIR=$GITEA_DATA_DIR export GITEA_CUSTOM=$GITEA_DIR/frontend/current export USER=sysadmin export HOME=/home/sysadmin echo Running: $GITEA_BIN web -c $INI.ini echo Server repos/logs/data/db will be $GITEA_DATA_DIR $GITEA_BIN web -c $INI.ini