]> git.ipfire.org Git - people/amarx/ipfire-3.x.git/blob - policycoreutils/semanage-bash-completion.sh
pdns: Update to version 3.4.7
[people/amarx/ipfire-3.x.git] / policycoreutils / semanage-bash-completion.sh
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 ALL_OPTS='-l --list -S -o -n --noheading -h --help'
25 MANAGED_OPTS='-a --add -m --modify -d --delete -D --deleteall -C --locallist '
26
27 __get_all_stores () {
28 dir -1 -F /etc/selinux/ | grep '/' | cut -d'/' -f 1
29 }
30 __get_all_ftypes () {
31 echo '-- -d -c -b -s -l -p'
32 }
33 __get_all_users () {
34 seinfo -u 2> /dev/null | tail -n +3
35 }
36 __get_all_types () {
37 seinfo -t 2> /dev/null | tail -n +3
38 }
39 __get_all_port_types () {
40 seinfo -aport_type -x 2>/dev/null | tail -n +2
41 }
42 __get_all_domains () {
43 seinfo -adomain -x 2>/dev/null | tail -n +2
44 }
45 __get_all_node_types () {
46 seinfo -anode_type -x 2>/dev/null | tail -n +2
47 }
48 __get_all_file_types () {
49 seinfo -afile_type -x 2>/dev/null | tail -n +2
50 }
51 __get_all_roles () {
52 seinfo -t 2> /dev/null | tail -n +3
53 }
54 __get_all_stores () {
55 dir -1 -F /etc/selinux/ | grep '/' | cut -d'/' -f 1
56 }
57 __get_boolean_opts () { echo '$ALL_OPTS --on -off -1 -0 -F' ; }
58 __get_user_opts () { echo '$ALL_OPTS $MANAGED_OPTS -L -r -R --role '; }
59 __get_login_opts () { echo '$ALL_OPTS $MANAGED_OPTS -s -r '; }
60 __get_port_opts () { echo '$ALL_OPTS $MANAGED_OPTS -t -type -r --range -p --proto'; }
61 __get_interface_opts () { echo '$ALL_OPTS $MANAGED_OPTS -t --type '; }
62 __get_node_opts () { echo '$ALL_OPTS $MANAGED_OPTS -t --type -M --mask -p --proto'; }
63 __get_fcontext_opts () { echo '$ALL_OPTS $MANAGED_OPTS -t --type -e --equal -f --ftype '; }
64 __get_module_opts () { echo '$ALL_OPTS --enable --disable '; }
65 __get_dontaudit_opts () { echo '-S on off' ; }
66 __get_permissive_opts () { echo '$ALL_OPTS -a --add -d --delete' ; }
67
68 _semanage () {
69 local command=${COMP_WORDS[1]}
70 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
71 local verb comps
72 local -A VERBS=(
73 [LOGIN]='login'
74 [USER]='user'
75 [PORT]='port'
76 [INTERFACE]='interface'
77 [MODULE]='module'
78 [NODE]='node'
79 [FCONTEXT]='fcontext'
80 [BOOLEAN]='boolean'
81 [PERMISSIVE]='permissive'
82 [DONTAUDIT]='dontaudit'
83 )
84
85 if [ "$prev" = "-a" -a "$command" = "permissive" ]; then
86 COMPREPLY=( $(compgen -W "$( __get_all_domains ) " -- "$cur") )
87 return 0
88 fi
89 if [ "$verb" = "" -a "$prev" = "semanage" ]; then
90 comps="${VERBS[*]}"
91 elif [ "$verb" = "" -a "$prev" = "-S" -o "$prev" = "--store" ]; then
92 COMPREPLY=( $(compgen -W "$( __get_all_stores ) " -- "$cur") )
93 return 0
94 elif [ "$verb" = "" -a "$prev" = "-p" -o "$prev" = "--proto" ]; then
95 COMPREPLY=( $(compgen -W "tcp udp" -- "$cur") )
96 return 0
97 elif [ "$verb" = "" -a "$prev" = "-r" -o "$prev" = "--roles" ]; then
98 COMPREPLY=( $(compgen -W "$( __get_all_roles ) " -- "$cur") )
99 return 0
100 elif [ "$verb" = "" -a "$prev" = "-s" -o "$prev" = "--seuser" ]; then
101 COMPREPLY=( $(compgen -W "$( __get_all_users ) " -- "$cur") )
102 return 0
103 elif [ "$verb" = "" -a "$prev" = "-f" -o "$prev" = "--ftype" ]; then
104 COMPREPLY=( $(compgen -W "$( __get_all_ftypes ) " -- "$cur") )
105 return 0
106 elif [ "$verb" = "" -a "$prev" = "-t" -o "$prev" = "--types" ]; then
107 if [ "$command" = "port" ]; then
108 COMPREPLY=( $(compgen -W "$( __get_all_port_types ) " -- "$cur") )
109 return 0
110 fi
111 if [ "$command" = "fcontext" ]; then
112 COMPREPLY=( $(compgen -W "$( __get_all_file_types ) " -- "$cur") )
113 return 0
114 fi
115 COMPREPLY=( $(compgen -W "$( __get_all_types ) " -- "$cur") )
116 return 0
117 elif __contains_word "$command" ${VERBS[LOGIN]} ; then
118 COMPREPLY=( $(compgen -W "$( __get_login_opts ) " -- "$cur") )
119 return 0
120 elif __contains_word "$command" ${VERBS[USER]} ; then
121 COMPREPLY=( $(compgen -W "$( __get_user_opts ) " -- "$cur") )
122 return 0
123 elif __contains_word "$command" ${VERBS[PORT]} ; then
124 COMPREPLY=( $(compgen -W "$( __get_port_opts ) " -- "$cur") )
125 return 0
126 elif __contains_word "$command" ${VERBS[INTERFACE]} ; then
127 COMPREPLY=( $(compgen -W "$( __get_interface_opts ) " -- "$cur") )
128 return 0p
129 elif __contains_word "$command" ${VERBS[MODULE]} ; then
130 COMPREPLY=( $(compgen -W "$( __get_module_opts ) " -- "$cur") )
131 return 0
132 elif __contains_word "$command" ${VERBS[NODE]} ; then
133 COMPREPLY=( $(compgen -W "$( __get_node_opts ) " -- "$cur") )
134 return 0
135 elif __contains_word "$command" ${VERBS[FCONTEXT]} ; then
136 COMPREPLY=( $(compgen -W "$( __get_fcontext_opts ) " -- "$cur") )
137 return 0
138 elif __contains_word "$command" ${VERBS[BOOLEAN]} ; then
139 COMPREPLY=( $(compgen -W "$( __get_boolean_opts ) " -- "$cur") )
140 return 0
141 elif __contains_word "$command" ${VERBS[PERMISSIVE]} ; then
142 COMPREPLY=( $(compgen -W "$( __get_permissive_opts ) " -- "$cur") )
143 return 0
144 elif __contains_word "$command" ${VERBS[DONTAUDIT]} ; then
145 COMPREPLY=( $(compgen -W "$( __get_dontaudit_opts ) " -- "$cur") )
146 return 0
147 fi
148 COMPREPLY=( $(compgen -W "$comps" -- "$cur") )
149 return 0
150 }
151 complete -F _semanage semanage