aboutsummaryrefslogtreecommitdiff
path: root/xdg-runtime-dirs
blob: bc04d17cb978daaa2384facb8be1761ce0cb9af2 (plain) (blame)
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
#!/bin/bash

xdg-runtime-dirs_exists() {
    true
}

xdg-runtime-dirs_start() {
    [[ -d "@@runstatedir@@"/user ]] || mkdir "@@runstatedir@@"/user >/dev/null 2>&1
    for u in $(cut -f1,3-4 -d ':' "@@sysconfdir@@"/passwd);do
        user=${u%%:*}
        gid=${u##*:}
        uid=${u%**}; uid=${uid##*:}
        status CUSTOM "xdg-runtime-dirs: ${user}"
        if [[ ! -d "@@runstatedir@@"/user/"${uid}" ]];then
            mkdir "@@runstatedir@@"/user/"${uid}"
            # make sure directory is owned by user's primary group
            chown "${uid}:${gid}" "@@runstatedir@@"/user/"${uid}"
            chmod 700 "@@runstatedir@@"/user/"${uid}"
        fi
        if [[ ! -L "@@runstatedir@@"/user/"${user}" ]];then
            # programs seem to default to /run/user/${USER} if XDG_RUNTIME_DIR unset
            ln -sf "@@runstatedir@@"/user/"${uid}" "@@runstatedir@@"/user/"${user}"
        fi
    done
}

xdg-runtime-dirs_stop() {
    # runtime dirs are cleared at startup, we should not stop because we can't be sure they aren't
    # being used when we delete them
    [[ "${BEGINNING_RUNNER}" == rc.shutdown ]] || return 1
    return 0
}

xdg-runtime-dirs_status() {
    for u in $(cut -f1,3-4 -d ':' "@@sysconfdir@@"/passwd);do
        user=${u%%:*}
        gid=${u##*:}
        uid=${u%**}; uid=${uid##*:}
        if [[ ! -d "@@runstatedir@@"/user/"${uid}" || ! -L "@@runstatedir@@"/user/"${user}" ]];then
            return 1
        fi
    done
    return 0
}