summaryrefslogtreecommitdiff
path: root/app-admin/eselect-lightdm/files/lightdm-0.2.eselect
blob: 00cf7e1daf2f9f83ecb1d886087f2af1501d2141 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# -*-eselect-*-  vim: ft=eselect
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2 or later
# $Id: $

DESCRIPTION="Switch between LightDM greeters"
MAINTAINER="lxnay@gentoo.org"
VERSION="0.1"

# Module variables
GREETERS_DIR="${EROOT}/usr/share/xgreeters"
GREETER_SYM="${GREETERS_DIR}/default.desktop"

find_targets() {
    local f fname
    for f in "${GREETERS_DIR}/"*; do
        [[ "${f}" == "${GREETER_SYM}" ]] && continue
        # skip dirs
        [[ -d "${f}" ]] && continue
        # skip broken syms etc
        [[ ! -e "${f}" ]] && continue
        # skip non reg files
        [[ ! -f "${f}" ]] && continue

        fname=$(basename "${f}")
        [[ "${fname}" == *.desktop ]] || continue

        echo "${fname%%.desktop}"
    done
}

remove_symlink() {
    rm "${GREETER_SYM}"
}

set_symlink() {
    local target="${1}"

    if is_number "${target}"; then
        local targets=( $(find_targets) )
        target=${targets[target-1]}
    fi

    [[ -z "${target}" || ! -f "${GREETERS_DIR}/${target}.desktop" ]] \
        && die -q "Target \"${target}\" doesn't appear to be valid!"

    echo "Setting LightDM greeter to ${target}"
    ln -sf "${target}.desktop" "${GREETER_SYM}" || die "Cannot create symlink"
}

### show action ###

describe_show() {
    echo "Show the current LightDM greeter"
}

describe_show_options() {
    echo "--quiet  : only print the actual symlink value"
    echo "--silent : same as --quiet"
}

do_show() {
    local quiet=""

    while [[ $# -gt 0 ]]; do
        case ${1##--} in
            quiet|silent)
                quiet="1"
                ;;
        esac
        shift
    done

    [[ -z "${quiet}" ]] && write_list_start "Current greeter:"
    if [[ -L "${GREETER_SYM}" ]] && [[ -e "${GREETER_SYM}" ]]; then
        local greeter=$(canonicalise "${GREETER_SYM}")
        local greeter_bn=$(basename "${greeter%.desktop}")
        if [[ -n "${quiet}" ]]; then
            echo "${greeter_bn}"
        else
            write_kv_list_entry "${greeter_bn}" ""
        fi
    else
        if [[ -z "${quiet}" ]]; then
            write_kv_list_entry "(unset)" ""
        fi
    fi
}

### list action ###

describe_list() {
    echo "List available LightDM greeters"
}

describe_list_options() {
    echo "--quiet  : only print the actual symlink value"
    echo "--silent : same as --quiet"
}

do_list() {
    local quiet

    while [[ $# -gt 0 ]]; do
        case ${1##--} in
            quiet|silent)
                quiet="1"
                ;;
        esac
        shift
    done

    local i targets=( $(find_targets) )

    [[ -z "${quiet}" ]] && write_list_start "Available LightDM greeters:"
    for (( i = 0; i < ${#targets[@]}; i++ )); do
        if [[ -z "${quiet}" ]]; then
            # highlight the target where the symlink is pointing to
            [[ ${targets[i]} = \
                $(basename "$(canonicalise "${GREETER_SYM}")") ]] \
                    && targets[i]=$(highlight_marker "${targets[i]}")
        else
            echo "${targets[i]}"
        fi
    done
    [[ -z "${quiet}" ]] && \
        write_numbered_list -m "(none found)" "${targets[@]}"
}

### set action ###
describe_set() {
    echo "Set a new LightDM greeter"
}

describe_set_parameters() {
    echo "<target>"
}

describe_set_options() {
    echo "target : Target name or number (from 'list' action)"
    echo "--use-old : use the old value if target is already set"
}

do_set() {
    local use_old
    local target="${1}"

    while [[ $# -gt 0 ]]; do
        case ${1##--} in
            use-old)
                use_old="1"
                ;;
        esac
        shift
    done

    [[ -z "${target}" ]] && \
       die -q "You didn't tell me what to set the symlink to"
    [[ ${#} -gt 1 ]] && die -q "Too many parameters"

    if [[ "${use_old}" = "1" ]]; then
       old_target=$(do_show --quiet)
       target="${old_target:-${target}}"
    fi

    if [[ -L "${GREETER_SYM}" ]]; then
        # existing symlink
        remove_symlink || die -q "Couldn't remove existing symlink"
        set_symlink "${target}" || die -q "Couldn't set a new symlink"
    elif [[ -e "${GREETER_SYM}" ]]; then
        # we have something strange
        die -q "${GREETER_SYM} exists but is not a symlink"
    else
        set_symlink "${target}" || die -q "Couldn't set a new symlink"
    fi
}