summaryrefslogtreecommitdiff
blob: 11c50d437914ed8893af17180f14e747779cf32e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/sbin/openrc-run
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

my_daemon="shellinaboxd"
pidfile="/var/run/${my_daemon}.pid"
command="/usr/sbin/${my_daemon}"
command_args="${SIAB_OPTS}"

depend() {
    use net
}

start_pre() {
    function my_join() { local IFS="${1}"; shift; echo "$*"; }

    if [[ -n ${SIAB_CSS_DIR} ]]; then
        # This code searches SIAB_CSS_DIR for CSS files
        # and formats the --user-css option accordingly.
        local CSS_FILES=( "${SIAB_CSS_DIR}"/*.css )
        local SIAB_CSS_FILES=()

        # Try to keep environment pollution low.
        local _CSS _BASE _NAME

        for _CSS in "${CSS_FILES[@]}"; do
            _BASE="$(basename ${_CSS})"
            _NAME="${_BASE%%\.css}"
            _NAME="${_NAME//-/_}"
            _NAME="${_NAME^}"
            # These are the default style sheets. Don't load them.
            [[ ${_NAME} =~ ^(Print|Styles).*? ]] && continue
            SIAB_CSS_FILES+=("\"${_NAME}\":-${_CSS}")
        done

        # The 1st one, which is the default one, must be turned on using the + sign.
        SIAB_CSS_FILES[0]=$(sed 's#:-#:+#' <<< ${SIAB_CSS_FILES[0]})

        command_args="${command_args} --user-css=$(my_join , "${SIAB_CSS_FILES[@]}")"
    fi

    return 0
}

start() {
    ebegin "Starting ${my_daemon}"
    start-stop-daemon \
        --start \
        --background \
        --pidfile ${pidfile} \
        --make-pidfile \
        --exec ${command} \
        -1 ${SIAB_LOGFILE} -2 ${SIAB_LOGFILE} \
        -- ${command_args}
    eend $?
}

stop() {
    ebegin "Stopping ${my_daemon}"
    start-stop-daemon \
        --stop \
        --pidfile ${pidfile}
    eend $?
}