aboutsummaryrefslogtreecommitdiff
path: root/core/baselayout/files/install-sv
blob: 509b25169525a07045beae0355d9b97fa9153670 (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
#!/bin/sh -e
# Carbs Linux service installer

usage() {
    printf '%s\n' \
        "usage: ${0##*/} [FILE...]" \
        "or:    ${0##*/} [-a NAME FILE]" "" \
        "You can set the DESTDIR environment variable to set a different root."
    exit 1
}

svname=''
case "$1" in
    --help|-h|'') usage ;;
    -a) [ "$#" -eq 3 ] || usage
        svname=$2; shift 2
esac

for service; do
    # Remove .run suffix and the directory name for service files.
    sv=${svname:-${service%.run}} sv=${sv##*/}

    # Create the service directories and copy the service file to them.
    mkdir -p "$DESTDIR/etc/sysmgr" "$DESTDIR/etc/sv/$sv"
    cp "$service" "$DESTDIR/etc/sysmgr/$sv"
    cp "$service" "$DESTDIR/etc/sv/$sv/run"

    # Set permissions for the services.
    chmod 0755 "$DESTDIR/etc/sysmgr/$sv" "$DESTDIR/etc/sv/$sv/run"

    # Create supervise directories for runit.
    ln -s "/run/runit/supervise.$sv" "$DESTDIR/etc/sv/$sv/supervise"

done