#!@l_prefix@/bin/openpkg rc
##
##  rc.subversion -- Run-Commands
##

%config
    subversion_enable="$openpkg_rc_def"
    subversion_env="no"
    subversion_daemon="no"
    subversion_daemon_user="@l_rusr@"
    subversion_daemon_host="127.0.0.1"
    subversion_daemon_port="3690"
    subversion_daemon_root="@l_prefix@/var/subversion/default"
    subversion_daemon_pidfile="@l_prefix@/var/subversion/subversion.pid"
    subversion_daemon_logfile="@l_prefix@/var/subversion/subversion.log"
    subversion_daemon_log_prolog="true"
    subversion_daemon_log_epilog="true"
    subversion_daemon_log_numfiles="10"
    subversion_daemon_log_minsize="1M"
    subversion_daemon_log_complevel="9"

%common
    subversion_signal () {
        [ -f $subversion_daemon_pidfile ] \
        && kill -$1 `cat $subversion_daemon_pidfile`
    }

%status -u @l_susr@ -o
    subversion_usable="unknown"
    subversion_active="no"
    rcService subversion enable yes && \
        subversion_signal 0 && subversion_active="yes"
    echo "subversion_enable=\"$subversion_enable\""
    echo "subversion_usable=\"$subversion_usable\""
    echo "subversion_active=\"$subversion_active\""

%start -u @l_susr@
    rcService subversion enable yes || exit 0
    rcService subversion active yes && exit 0
    if rcVarIsYes subversion_daemon; then
        su - $subversion_daemon_user -c \
        "@l_prefix@/bin/svnserve --daemon \
              --listen-host $subversion_daemon_host \
              --listen-port $subversion_daemon_port \
              --root $subversion_daemon_root \
              --pid-file $subversion_daemon_pidfile"
    fi

%stop -u @l_susr@
    rcService subversion enable yes || exit 0
    rcService subversion active no  && exit 0
    if rcVarIsYes subversion_daemon; then
        subversion_signal TERM
        sleep 2
        rm -f $subversion_daemon_pidfile 2>/dev/null || true
    fi

%restart -u @l_susr@
    rcService subversion enable yes || exit 0
    rcService subversion active no  && exit 0
    rc subversion stop start

%daily -u @l_susr@
    rcService subversion enable yes || exit 0
    shtool rotate -f \
        -n $subversion_daemon_log_numfiles -s $subversion_daemon_log_minsize -d \
        -z $subversion_daemon_log_complevel -m 664 -o @l_susr@ -g @l_sgrp@ \
        -P "$subversion_daemon_log_prolog" \
        -E "$subversion_daemon_log_epilog; rc subversion restart" \
        $subversion_daemon_logfile

%env
    rcService subversion enable yes || exit 0
    if rcVarIsYes subversion_env; then
        if [ ".$BASH" != . ]; then
            shopt -s extglob progcomp
            . @l_prefix@/etc/subversion/bashrc
        fi
    fi

