anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0209-bash-completion-analyze-support-security.patch

4fbe94
From 8d1a8f099dbf79d0e18e055721228192a637a759 Mon Sep 17 00:00:00 2001
4fbe94
From: Yu Watanabe <watanabe.yu+github@gmail.com>
4fbe94
Date: Thu, 6 Dec 2018 18:51:56 +0100
4fbe94
Subject: [PATCH] bash-completion: analyze: support 'security'
4fbe94
4fbe94
(cherry picked from commit 83da42c3bf86e8787cfec2c7fb6ca379dfec3632)
4fbe94
4fbe94
Resolves: #1733395
4fbe94
---
4fbe94
 shell-completion/bash/systemd-analyze | 20 +++++++++++++++++++-
4fbe94
 1 file changed, 19 insertions(+), 1 deletion(-)
4fbe94
4fbe94
diff --git a/shell-completion/bash/systemd-analyze b/shell-completion/bash/systemd-analyze
4fbe94
index 21d0fcf1b8..b4fcfc6492 100644
4fbe94
--- a/shell-completion/bash/systemd-analyze
4fbe94
+++ b/shell-completion/bash/systemd-analyze
4fbe94
@@ -31,8 +31,13 @@ __get_machines() {
4fbe94
         machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
4fbe94
 }
4fbe94
 
4fbe94
+__get_services() {
4fbe94
+        systemctl list-units --no-legend --no-pager -t service --all $1 | \
4fbe94
+                { while read -r a b c; do [[ $b == "loaded" ]]; echo " $a"; done }
4fbe94
+}
4fbe94
+
4fbe94
 _systemd_analyze() {
4fbe94
-        local i verb comps
4fbe94
+        local i verb comps mode
4fbe94
         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
4fbe94
 
4fbe94
         local -A OPTS=(
4fbe94
@@ -51,6 +56,7 @@ _systemd_analyze() {
4fbe94
                 [SECCOMP_FILTER]='syscall-filter'
4fbe94
                 [SERVICE_WATCHDOGS]='service-watchdogs'
4fbe94
                 [CAT_CONFIG]='cat-config'
4fbe94
+                [SECURITY]='security'
4fbe94
         )
4fbe94
 
4fbe94
         local CONFIGS='systemd/bootchart.conf systemd/coredump.conf systemd/journald.conf
4fbe94
@@ -149,6 +155,18 @@ _systemd_analyze() {
4fbe94
                         comps="$CONFIGS $( compgen -A file -- "$cur" )"
4fbe94
                         compopt -o filenames
4fbe94
                 fi
4fbe94
+
4fbe94
+        elif __contains_word "$verb" ${VERBS[SECURITY]}; then
4fbe94
+                if [[ $cur = -* ]]; then
4fbe94
+                        comps='--help --version --no-pager --system --user -H --host -M --machine'
4fbe94
+                else
4fbe94
+                        if __contains_word "--user" ${COMP_WORDS[*]}; then
4fbe94
+                                mode=--user
4fbe94
+                        else
4fbe94
+                                mode=--system
4fbe94
+                        fi
4fbe94
+                        comps=$( __get_services $mode )
4fbe94
+                fi
4fbe94
         fi
4fbe94
 
4fbe94
         COMPREPLY=( $(compgen -W '$comps' -- "$cur") )