]>
git.ipfire.org Git - people/arne_f/ipfire-3.x.git/blob - policycoreutils/semanage-bash-completion.sh
1 # This file is part of systemd.
3 # Copyright 2011 Dan Walsh
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.
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.
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/>.
20 for w
in $
*; do [[ $w = $word ]] && return 0; done
24 ALL_OPTS
='-l --list -S -o -n --noheading -h --help'
25 MANAGED_OPTS
='-a --add -m --modify -d --delete -D --deleteall -C --locallist '
28 dir
-1 -F /etc
/selinux
/ |
grep '/' | cut
-d'/' -f 1
31 echo '-- -d -c -b -s -l -p'
34 seinfo
-u 2> /dev
/null |
tail -n +3
37 seinfo
-t 2> /dev
/null |
tail -n +3
39 __get_all_port_types
() {
40 seinfo
-aport_type -x 2>/dev
/null |
tail -n +2
42 __get_all_domains
() {
43 seinfo
-adomain -x 2>/dev
/null |
tail -n +2
45 __get_all_node_types
() {
46 seinfo
-anode_type -x 2>/dev
/null |
tail -n +2
48 __get_all_file_types
() {
49 seinfo
-afile_type -x 2>/dev
/null |
tail -n +2
52 seinfo
-t 2> /dev
/null |
tail -n +3
55 dir
-1 -F /etc
/selinux
/ |
grep '/' | cut
-d'/' -f 1
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' ; }
69 local command=${COMP_WORDS[1]}
70 local cur
=${COMP_WORDS[COMP_CWORD]} prev
=${COMP_WORDS[COMP_CWORD-1]}
76 [INTERFACE
]='interface'
81 [PERMISSIVE
]='permissive'
82 [DONTAUDIT
]='dontaudit'
85 if [ "$prev" = "-a" -a "$command" = "permissive" ]; then
86 COMPREPLY
=( $
(compgen
-W "$( __get_all_domains ) " -- "$cur") )
89 if [ "$verb" = "" -a "$prev" = "semanage" ]; then
91 elif [ "$verb" = "" -a "$prev" = "-S" -o "$prev" = "--store" ]; then
92 COMPREPLY
=( $
(compgen
-W "$( __get_all_stores ) " -- "$cur") )
94 elif [ "$verb" = "" -a "$prev" = "-p" -o "$prev" = "--proto" ]; then
95 COMPREPLY
=( $
(compgen
-W "tcp udp" -- "$cur") )
97 elif [ "$verb" = "" -a "$prev" = "-r" -o "$prev" = "--roles" ]; then
98 COMPREPLY
=( $
(compgen
-W "$( __get_all_roles ) " -- "$cur") )
100 elif [ "$verb" = "" -a "$prev" = "-s" -o "$prev" = "--seuser" ]; then
101 COMPREPLY
=( $
(compgen
-W "$( __get_all_users ) " -- "$cur") )
103 elif [ "$verb" = "" -a "$prev" = "-f" -o "$prev" = "--ftype" ]; then
104 COMPREPLY
=( $
(compgen
-W "$( __get_all_ftypes ) " -- "$cur") )
106 elif [ "$verb" = "" -a "$prev" = "-t" -o "$prev" = "--types" ]; then
107 if [ "$command" = "port" ]; then
108 COMPREPLY
=( $
(compgen
-W "$( __get_all_port_types ) " -- "$cur") )
111 if [ "$command" = "fcontext" ]; then
112 COMPREPLY
=( $
(compgen
-W "$( __get_all_file_types ) " -- "$cur") )
115 COMPREPLY
=( $
(compgen
-W "$( __get_all_types ) " -- "$cur") )
117 elif __contains_word
"$command" ${VERBS[LOGIN]} ; then
118 COMPREPLY
=( $
(compgen
-W "$( __get_login_opts ) " -- "$cur") )
120 elif __contains_word
"$command" ${VERBS[USER]} ; then
121 COMPREPLY
=( $
(compgen
-W "$( __get_user_opts ) " -- "$cur") )
123 elif __contains_word
"$command" ${VERBS[PORT]} ; then
124 COMPREPLY
=( $
(compgen
-W "$( __get_port_opts ) " -- "$cur") )
126 elif __contains_word
"$command" ${VERBS[INTERFACE]} ; then
127 COMPREPLY
=( $
(compgen
-W "$( __get_interface_opts ) " -- "$cur") )
129 elif __contains_word
"$command" ${VERBS[MODULE]} ; then
130 COMPREPLY
=( $
(compgen
-W "$( __get_module_opts ) " -- "$cur") )
132 elif __contains_word
"$command" ${VERBS[NODE]} ; then
133 COMPREPLY
=( $
(compgen
-W "$( __get_node_opts ) " -- "$cur") )
135 elif __contains_word
"$command" ${VERBS[FCONTEXT]} ; then
136 COMPREPLY
=( $
(compgen
-W "$( __get_fcontext_opts ) " -- "$cur") )
138 elif __contains_word
"$command" ${VERBS[BOOLEAN]} ; then
139 COMPREPLY
=( $
(compgen
-W "$( __get_boolean_opts ) " -- "$cur") )
141 elif __contains_word
"$command" ${VERBS[PERMISSIVE]} ; then
142 COMPREPLY
=( $
(compgen
-W "$( __get_permissive_opts ) " -- "$cur") )
144 elif __contains_word
"$command" ${VERBS[DONTAUDIT]} ; then
145 COMPREPLY
=( $
(compgen
-W "$( __get_dontaudit_opts ) " -- "$cur") )
148 COMPREPLY
=( $
(compgen
-W "$comps" -- "$cur") )
151 complete
-F _semanage semanage