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__get_all_booleans () { 19 getsebool -a | cut -f1 -d' ' 20} 21 22_setsebool () { 23 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} 24 25 if [ "$prev" = '=' ]; then 26 COMPREPLY=( $(compgen -W "on off" -- "$cur") ) 27 return 0 28 fi 29 30 case "$cur" in 31 '0') 32 COMPREPLY=( $(compgen -W "0 1" -- "$cur") ) 33 return 0 34 ;; 35 '1') 36 COMPREPLY=( $(compgen -W "0 1" -- "$cur") ) 37 return 0 38 ;; 39 =) 40 COMPREPLY=( $(compgen -W "on off" -- "") ) 41 return 0 42 ;; 43 -*) 44 COMPREPLY=( $(compgen -W "-N -P -V" -- "$cur") ) 45 return 0 46 ;; 47 '') 48 if [ "$prev" = '0' ] || [ "$prev" = '1' ]; then 49 COMPREPLY=( $(compgen -W "-N -P -V" -- "$cur") ) 50 return 0 51 fi 52 if getsebool "$prev" > /dev/null 2>&1; then 53 COMPREPLY=( $(compgen -W "0 1" -- "$cur") ) 54 return 0 55 fi 56 ;; 57 *) 58 if getsebool "$cur" > /dev/null 2>&1; then 59 COMPREPLY=( $(compgen -W '$( __get_all_booleans ) "$cur=on " "$cur=off "' -- "$cur") ) 60 compopt -o nospace 61 return 0 62 fi 63 ;; 64 esac 65 66 COMPREPLY=( $(compgen -W '"-N " "-P " "-V " $( __get_all_booleans ) ' -- "$cur") ) 67 compopt -o nospace 68 return 0 69} 70 71_getsebool () { 72 local command=${COMP_WORDS[1]} 73 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} 74 local verb comps 75 76 if [ "$verb" = "" -a "$prev" == "getsebool" ]; then 77 COMPREPLY=( $(compgen -W "-a $( __get_all_booleans ) " -- "$cur") ) 78 return 0 79 fi 80 if [ "$verb" = "" -a "$prev" != "-a" ]; then 81 COMPREPLY=( $(compgen -W "$( __get_all_booleans ) " -- "$cur") ) 82 return 0 83 fi 84 return 0 85} 86 87complete -F _setsebool setsebool 88complete -F _getsebool getsebool 89