From 131e5c8db120b83364349268ec91e38ba77d1f04 Mon Sep 17 00:00:00 2001 From: mrjk Date: Tue, 27 Feb 2018 21:57:59 -0500 Subject: [PATCH] Dev: Many little improvement, output reduxx DONE: - Reduce wasted output blank lines - Simplifie ls output on all modules - Remove sterr output on ls - Clean function syntax (for hier output) - Fix a bug on missing pid for ssh-agent - Remove portion of debug traces (mod_ssh) --- bin/idmgr | 28 +++++++---- lib/idmgr_mod_cloud.sh | 8 ++-- lib/idmgr_mod_gpg.sh | 5 +- lib/idmgr_mod_pass.sh | 5 +- lib/idmgr_mod_ssh.sh | 16 ++++--- lib/idmgr_mod_tomb.sh | 105 +++++++++++++++++++++++------------------ 6 files changed, 100 insertions(+), 67 deletions(-) diff --git a/bin/idmgr b/bin/idmgr index 587865b..34c95d9 100755 --- a/bin/idmgr +++ b/bin/idmgr @@ -99,7 +99,7 @@ idm_core__ls () local id=${1} #set -x - idm_core_exec_mod $id __ls "\n%s ls" ${IDM_MOD_ORDER//:/ } + idm_core_exec_mod $id __ls "%s ls" ${IDM_MOD_ORDER//:/ } } @@ -243,14 +243,26 @@ idm_core_exec_mod () #set +x #lib_log INFO "Loading module $i ..." - [ "$sep" == "_" ] || lib_log NOTICE "$(printf "$sep" $i )" + #${val} $id || \ + # { + # # DO NOT DISABLE THIS BLOCK, that force plugin to load in anyway + # true + # lib_log WARN "Module $i failed in some way ... ($action)" + # } + export IDM_MOD_EXEC=chain - ${val} $id || \ - { - # DO NOT DISABLE THIS BLOCK, that force plugin to load in anyway - true - lib_log WARN "Module $i failed in some way ... ($action)" - } + local rc=0 + out="$( ${val} $id || rc=$? )" + + if [ "$rc" -eq 0 -a ! -z "$out" ]; then + [ "$sep" == "_" ] || + lib_log NOTICE "$(printf "$sep" $i )" + echo -e "$out\n" + elif [ "$rc" -ne 0 ]; then + lib_log WARN "Module $i failed in some way ... ($action)" + echo -e "$out\n" + fi + else echo "" lib_log INFO "Skip module $i" diff --git a/lib/idmgr_mod_cloud.sh b/lib/idmgr_mod_cloud.sh index 8e8e0b0..2e7f003 100644 --- a/lib/idmgr_mod_cloud.sh +++ b/lib/idmgr_mod_cloud.sh @@ -22,11 +22,11 @@ idm_cloud__ls () if lib_id_is_enabled $id; then if [ -f "${OS_CLOUD-}" ]; then echo " enabled ($OS_CLOUD)" - else - echo " disabled (config is absent ${OS_CLOUD:-${OS_CLOUD:+$OS_CLOUD}})" + #else + # echo " disabled (config is absent ${OS_CLOUD:-${OS_CLOUD:+$OS_CLOUD}})" fi - else - echo " disabled" + #else + # echo " disabled" fi } diff --git a/lib/idmgr_mod_gpg.sh b/lib/idmgr_mod_gpg.sh index 8870557..483ba9b 100644 --- a/lib/idmgr_mod_gpg.sh +++ b/lib/idmgr_mod_gpg.sh @@ -66,7 +66,10 @@ idm_gpg__ls () local id=${1} lib_id_is_enabled $id || return 0 - gpg --list-keys | sed 's/^/ /' #| lib_log DUMP - + { + gpg --list-keys 2>/dev/null \ + || true + } | sed 's/^/ /' #| lib_log DUMP - } idm_gpg__new () diff --git a/lib/idmgr_mod_pass.sh b/lib/idmgr_mod_pass.sh index d9294bd..601a49c 100644 --- a/lib/idmgr_mod_pass.sh +++ b/lib/idmgr_mod_pass.sh @@ -33,7 +33,10 @@ idm_pass__ls () local id=${1} lib_id_is_enabled $id || return 0 - PASSWORD_STORE_DIR=~/.config/pass/${id} pass ls | sed 's/^/ /' + { + PASSWORD_STORE_DIR=~/.config/pass/${id} \ + pass ls || true + } 2>/dev/null | sed 's/^/ /' } idm_pass__help () diff --git a/lib/idmgr_mod_ssh.sh b/lib/idmgr_mod_ssh.sh index d166a37..a247d48 100644 --- a/lib/idmgr_mod_ssh.sh +++ b/lib/idmgr_mod_ssh.sh @@ -58,7 +58,7 @@ idm_ssh__ls () lib_id_is_enabled $id || return 0 - { ssh-add $opt || true ; } | sed 's/^/ /' + { ssh-add $opt || true ; } 2>/dev/null | sed 's/^/ /' } idm_ssh__disable () @@ -97,7 +97,8 @@ idm_ssh__enable () } # LOGOUT -idm_ssh__kill () { +idm_ssh__kill () +{ #set -x @@ -178,26 +179,27 @@ idm_ssh__agent_start() { } -idm_ssh__agent_clean () { +idm_ssh__agent_clean () +{ local id=$1 local socket=$2 local pid=${3:-0} # We should kill all agents .... if [ "${pid}" == '0' ]; then - set +x + #set +x pid=$(grep -a "$socket" /proc/*/cmdline \ | grep -a -v 'thread-self' \ | strings -s' ' -1 \ | sed -E 's@ /proc/@ \n/proc/@g' ) - set -x + #set -x pid="$( sed -E 's@/proc/([0-9]*)/.*@\1@' <<<"$pid" )" fi - set -x + #set -x # Remove process - if [ "$pid" != '0' ]; then + if [ "$pid" != '0' -a "$pid" -gt 0 ]; then kill $pid fi diff --git a/lib/idmgr_mod_tomb.sh b/lib/idmgr_mod_tomb.sh index 68a16e4..3fa9b6f 100644 --- a/lib/idmgr_mod_tomb.sh +++ b/lib/idmgr_mod_tomb.sh @@ -70,54 +70,67 @@ idm_tomb__ls () { local id=$1 - echo " Tombs:" - find $IDM_CONFIG_DIR/enc/ -type f -name "*.tomb" | sed "s@$HOME@ ~@" - - - if lib_id_is_enabled $id; then - local tomb_status= - local tomb_date= - local git_status= - local git_date= - - # Load local vars - idm_tomb_header $id - - # Get status of tomb file - if [ -f "$git_tomb_enc" ]; then - tomb_status=present - tomb_date=$( lib_date_diff_human $(find $git_tomb_enc -printf "%Ts") ) - tomb_date=", $tomb_date old" - else - tomb_status=absent - fi - - # Get status of git repo - if [ -d "$git_tomb_dir" ]; then - git_status=open - #git_date=$( lib_date_diff_human $(find $git_tomb_dir -maxdepth 0 -printf "%Ts") ) - #git_date=" $git_date" - else - git_status=closed - fi - - # Display - echo " Status:" - printf " %-20s: %s\n" "encrypted tomb" "$tomb_status${tomb_date}" - printf " %-20s: %s\n" "encrypted file" "$git_tomb_enc" - printf " %-20s: %s\n" "tomb git status" "$git_status${git_date}" - printf " %-20s: %s\n" "tomb git dir" "$git_tomb_dir" - - # Show git remotes - if lib_git_is_repo id &>/dev/null ; then - echo " Git remotes:" - lib_git id remote -v | sed 's/^/ /' - echo " Last commits:" - lib_git id l --color=always | sed 's/^/ /' - echo - fi + # Show files if there are some + if [ -d "$IDM_CONFIG_DIR/enc/" ]; then + echo " Tombs:" + find $IDM_CONFIG_DIR/enc/ -type f -name "*.tomb" | sed "s@$HOME@ ~@" fi + # Leave if not enabled + lib_id_is_enabled $id && + return 0 + + # Status vars + local tomb_status= + local tomb_date= + local tomb_show=0 + local git_status= + local git_date= + local git_show=0 + + # Load local vars + idm_tomb_header $id + + # Get status of tomb file + if [ -f "$git_tomb_enc" ]; then + tomb_status=present + tomb_date=$( lib_date_diff_human $(find $git_tomb_enc -printf "%Ts") ) + tomb_date=", $tomb_date old" + tomb_show=1 + else + tomb_status=absent + fi + + # Get status of git repo + if [ -d "$git_tomb_dir" ]; then + git_status=open + #git_date=$( lib_date_diff_human $(find $git_tomb_dir -maxdepth 0 -printf "%Ts") ) + #git_date=" $git_date" + else + git_status="absent (closed)" + fi + + # Leave if nothing to show + [ $(( $git_show + $tomb_show )) -eq 0 ] && return + + # Display + echo " Status:" + printf " %-20s: %s\n" "encrypted tomb" "$tomb_status${tomb_date}" + printf " %-20s: %s\n" "encrypted file" "$git_tomb_enc" + printf " %-20s: %s\n" "tomb git status" "$git_status${git_date}" + printf " %-20s: %s\n" "tomb git dir" "$git_tomb_dir" + + # Check if local repo is enabled + lib_git_is_repo id &>/dev/null || + return 0 + + # Show git remotes + echo " Git remotes:" + lib_git id remote -v | sed 's/^/ /' + echo " Last commits:" + lib_git id l --color=always | sed 's/^/ /' + echo + }