1# This file is part of systemd.
2#
3# Copyright 2011 Dan Walsh
4#
5# systemd is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# systemd is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with systemd; If not, see <http://www.gnu.org/licenses/>.
17
18__contains_word () {
19        local word=$1; shift
20        for w in $*; do [[ $w = $word ]] && return 0; done
21        return 1
22}
23
24__get_all_booleans () {
25    getsebool -a | cut -f1 -d' '
26}
27
28_setsebool () {
29        local command=${COMP_WORDS[1]}
30        local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
31        local verb comps
32
33	if   [ "$verb" = "" -a "$prev" = "setsebool" -o "$prev" = "-P" ]; then
34	        COMPREPLY=( $(compgen -W "-P $( __get_all_booleans ) " -- "$cur") )
35		return 0
36        fi
37        COMPREPLY=( $(compgen -W "0 1 -P" -- "$cur") )
38        return 0
39}
40
41_getsebool () {
42        local command=${COMP_WORDS[1]}
43        local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
44        local verb comps
45
46	if   [ "$verb" = "" -a "$prev" == "getsebool" ]; then
47	        COMPREPLY=( $(compgen -W "-a $( __get_all_booleans ) " -- "$cur") )
48		return 0
49        fi
50	if   [ "$verb" = "" -a "$prev" != "-a" ]; then
51	        COMPREPLY=( $(compgen -W "$( __get_all_booleans ) " -- "$cur") )
52		return 0
53        fi
54        return 0
55}
56
57complete -F _setsebool setsebool
58complete -F _getsebool getsebool
59