Skip to contentSkip to conversation

semanage bash completion: handle semanage module #246

PATCH Superseded Topi Miettinen 2 participants 2 messages May 25, 2020 – May 29, 2020 SELinux security module

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 semanage bash completion: handle semanage module #246

List modules for bash completion of semanage module.

---
 python/semanage/semanage-bash-completion.sh | 11 +++++++++++
 1 file changed, 11 insertions(+)
python/semanage/semanage-bash-completion.sh +11 -0
index 2d811c98..a3993c58 100644
@@ -54,6 +54,9 @@ __get_all_roles () {
 __get_all_stores () {
     dir -1 -F /etc/selinux/ | grep '/' | cut -d'/' -f 1
 }
+__get_all_modules () {
+    semodule -l
+}
 __get_import_opts () { echo '$ALL_OPTS --f --input_file' ; }
 __get_export_opts () { echo '$ALL_OPTS --f --output_file' ; }
 __get_boolean_opts () { echo '$ALL_OPTS --on -off -1 -0' ; }
@@ -88,6 +91,14 @@ _semanage () {
 	if   [ "$prev" = "-a" -a "$command" = "permissive" ]; then
 	        COMPREPLY=( $(compgen -W "$( __get_all_domains ) " -- "$cur") )
 		return 0
+	elif [ "$command" = "module" ]; then
+		if [ "$prev" = "-a" ] || [ "$prev" = "--add" ] \
+		    || [ "$prev" = "-d" ] || [ "$prev" = "--disable" ] \
+		    || [ "$prev" = "-e" ] || [ "$prev" = "--enable" ] \
+		    || [ "$prev" = "-r" ] || [ "$prev" = "--remove" ]; then
+	            COMPREPLY=( $(compgen -W "$( __get_all_modules ) " -- "$cur") )
+		    return 0
+		fi
 	fi
 	if   [ "$verb" = "" -a "$prev" = "semanage" ]; then
                 comps="${VERBS[*]}"
Signature · 1 line
2.26.2
maintainer
#1 lore raw
Quoted 23 lines · Topi Miettinen

List modules for bash completion of semanage module.

---
 python/semanage/semanage-bash-completion.sh | 11 +++++++++++
 1 file changed, 11 insertions(+)
python/semanage/semanage-bash-completion.sh +3 -0
index 2d811c98..a3993c58 100644
@@ -54,6 +54,9 @@ __get_all_roles () {
 __get_all_stores () {
     dir -1 -F /etc/selinux/ | grep '/' | cut -d'/' -f 1
 }
+__get_all_modules () {
+    semodule -l
+}
 __get_import_opts () { echo '$ALL_OPTS --f --input_file' ; }
 __get_export_opts () { echo '$ALL_OPTS --f --output_file' ; }
 __get_boolean_opts () { echo '$ALL_OPTS --on -off -1 -0' ; }

python/semanage/semanage-bash-completion.sh _semanage () { · line 95

Quoted 5 lines
python/semanage/semanage-bash-completion.sh +2 -0
@@ -88,6 +91,14 @@ _semanage () {
        if   [ "$prev" = "-a" -a "$command" = "permissive" ]; then
                COMPREPLY=( $(compgen -W "$( __get_all_domains ) " -- "$cur") )
                return 0
+       elif [ "$command" = "module" ]; then
+               if [ "$prev" = "-a" ] || [ "$prev" = "--add" ] \

For -a we likely don't want this because the argument should be a module file path not an already installed module name.

Quoted 12 lines
python/semanage/semanage-bash-completion.sh +6 -1
+                   || [ "$prev" = "-d" ] || [ "$prev" = "--disable" ] \
+                   || [ "$prev" = "-e" ] || [ "$prev" = "--enable" ] \
+                   || [ "$prev" = "-r" ] || [ "$prev" = "--remove" ]; then
+                   COMPREPLY=( $(compgen -W "$( __get_all_modules ) " -- "$cur") )
+                   return 0
+               fi
        fi
        if   [ "$verb" = "" -a "$prev" = "semanage" ]; then
                 comps="${VERBS[*]}"
--

2.26.2