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

%config
    openpkg_external_enable="$openpkg_rc_def"
    openpkg_external_rc=""

%common
    openpkg_external_execute () {
        cmd="$1"
        for spec in $openpkg_external_rc; do
            rc=""; usr="@l_nusr@"
            eval `echo "X$spec" | sed \
                -e 's/^X\(\/.*\):\(.*\)$/rc="\1"; usr="\2"/' \
                -e 's/^X\(\/.*\)$/rc="\1"/' \
                -e 's/^X.*$//'`
            if [ ".$rc" != . ]; then
                su - "$usr" -c "$rc $cmd" || true
            fi
        done
    }

%status -u @l_susr@ -o
    openpkg_external_usable="no"
    openpkg_external_active="unknown"

%start -p 900 -u @l_susr@
    rcService openpkg-external enable yes || exit 0
    openpkg_external_execute start

%stop -p 100 -u @l_susr@
    rcService openpkg-external enable yes || exit 0
    openpkg_external_execute stop

%restart -p 900 -u @l_susr@
    rcService openpkg-external enable yes || exit 0
    openpkg_external_execute restart

%reload -p 900 -u @l_susr@
    rcService openpkg-external enable yes || exit 0
    openpkg_external_execute reload

%quarterly -p 900 -u @l_susr@
    rcService openpkg-external enable yes || exit 0
    openpkg_external_execute quarterly

%hourly -p 900 -u @l_susr@
    rcService openpkg-external enable yes || exit 0
    openpkg_external_execute hourly

%daily -p 900 -u @l_susr@
    rcService openpkg-external enable yes || exit 0
    openpkg_external_execute daily

%weekly -p 900 -u @l_susr@
    rcService openpkg-external enable yes || exit 0
    openpkg_external_execute weekly

%monthly -p 900 -u @l_susr@
    rcService openpkg-external enable yes || exit 0
    openpkg_external_execute monthly

