diff options
| author | Dennis Camera <skonfig@dtnr.ch> | 2022-08-25 22:52:37 +0200 |
|---|---|---|
| committer | Dennis Camera <skonfig@dtnr.ch> | 2022-08-25 22:52:37 +0200 |
| commit | 494fe560e6e0367cc64f6796d103a296e49191ec (patch) | |
| tree | 71eeb11cb698ea6c177479497f614c9afffe72f7 | |
| parent | 704e87a95e6729f1fe1a7505ed01da23fcb1afc2 (diff) | |
| download | skonfig-c-494fe560e6e0367cc64f6796d103a296e49191ec.tar.gz skonfig-c-494fe560e6e0367cc64f6796d103a296e49191ec.zip | |
[scripts/sdump] Add sdump script
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Makefile.am | 3 | ||||
| -rw-r--r-- | configure.ac | 3 | ||||
| -rwxr-xr-x | scripts/sdump.in | 289 |
4 files changed, 298 insertions, 0 deletions
@@ -1,5 +1,8 @@ /skonfig +/scripts/* +!/scripts/*.in + /config.h /build-aux .dirstamp diff --git a/Makefile.am b/Makefile.am index faf7197..7ccdca6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,3 +16,6 @@ skonfig_SOURCES = \ src/util/exec.c \ src/util/fs.c \ src/util/string.c + +bin_SCRIPTS = \ + scripts/sdump diff --git a/configure.ac b/configure.ac index 6f135bf..debf933 100644 --- a/configure.ac +++ b/configure.ac @@ -11,6 +11,9 @@ AC_CONFIG_FILES([Makefile]) AM_INIT_AUTOMAKE([subdir-objects]) +# scripts +AC_CONFIG_FILES([scripts/sdump], [chmod +x scripts/sdump]) + # Checks for programs. AC_LANG([C]) diff --git a/scripts/sdump.in b/scripts/sdump.in new file mode 100755 index 0000000..fe8262e --- /dev/null +++ b/scripts/sdump.in @@ -0,0 +1,289 @@ +#!/bin/sh + +VERSION='@VERSION@' + +set -u + +hosts= +cache_dir=~/.skonfig/dump + +do_all=true +do_global_explorer=false +do_type_explorer=false +do_script_stdout=false +do_script_stderr=false +do_gencode=false +do_code=false +do_messages=false +do_parameter=false +delimiter=':' +filename_prefix=true +linenumber_prefix=false +verbosity=0 + +myname=${0##*/} + +print_version() +{ + printf '%s %s\n' "${myname}" "${VERSION}" +} + +usage() +{ + cat <<EOF +${myname}: [options] [host...] +$(print_version) + +Dump data from cache directories. + +host + Dump data for specified hosts. If not specified then all data + from cache directory is dumped. + +Options + -a dump all + -C CACHE-DIR use specified CACHE-DIR (default: ~/.cdist/cache) + -c dump code-* + -d DELIMITER delimiter used for filename and line number prefix (default: ':') + -E dump global explorers + -e dump type explorers + -F disable filename prefix (enabled by default) + -f enable filename prefix (default) + -g dump gencode-* + -h show this help screen and exit + -L disable line number prefix (default) + -l enable line number prefix (disabled by default) + -m dump messages + -o dump executions' stdout + -p dump parameters + -r dump executions' stderr + -V show version and exit + -v increase verbosity +EOF +} + +exit_err() +{ + printf '%s\n' "$*" + exit 1 +} + +# parse options +while test $# -ge 1 +do + case $1 + in + (-a) + do_all=true + ;; + (-C) + if test $# -ge 2 + then + case $2 + in + (-*) + exit_err 'Missing cache directory' + ;; + (*) + cache_dir=$2 + shift + ;; + esac + else + exit_err 'Missing cache directory' + fi + ;; + (-c) + do_code=true + do_all=false + ;; + (-d) + if test $# -ge 2 + then + case $2 + in + (-*) + exit_err 'Missing delimiter' + ;; + (*) + delimiter=$2 + shift + ;; + esac + else + exit_err 'Missing delimiter' + fi + ;; + (-E) + do_global_explorer=true + do_all=false + ;; + (-e) + do_type_explorer=true + do_all=false + ;; + (-F) + filename_prefix=false + ;; + (-f) + filename_prefix=true + ;; + (-g) + do_gencode=true + do_all=false + ;; + (-h) + usage + exit 0 + ;; + (-L) + linenumber_prefix=false + ;; + (-l) + linenumber_prefix=true + ;; + (-m) + do_messages=true + do_all=false + ;; + (-o) + do_script_stdout=true + do_all=false + ;; + (-p) + do_parameter=true + do_all=false + ;; + (-r) + do_script_stderr=true + do_all=false + ;; + (-V) + print_version + exit 0 + ;; + (-v) + : $((verbosity += 1)) + ;; + (*) + hosts=${hosts-}${hosts:+ }$1 + break + ;; + esac + shift +done + +if ${do_all:-false} +then + do_global_explorer=true + do_type_explorer=true + do_script_stdout=true + do_script_stderr=true + do_gencode=true + do_code=true + do_messages=true + do_parameter=true +fi + +set -- + +print_verbose() +{ + if test $((verbosity)) -ge $1 + then + printf '%s\n' "$2" + fi +} + +hor_line() +{ + printf '%78s\n' '' | tr ' ' "${1:-=}" +} + +if ${do_global_explorer} +then + print_verbose 2 'Dumping global explorers' + # shellcheck disable=SC2086 + set -- "$@" ${1:+-o} \( \ + -path '*/explorer/*' \ + -a ! -path '*/conf/*' \ + -a ! -path '*/object/*/explorer/*' \ + \) +fi + +if ${do_type_explorer} +then + print_verbose 2 'Dumping type explorers' + set -- "$@" ${1:+-o} -path '*/object/*/explorer/*' +fi + +if ${do_script_stdout} +then + print_verbose 2 "Dumping execution's stdout" + set -- "$@" ${1:+-o} -path '*/stdout/*' +fi + +if ${do_script_stderr} +then + print_verbose 2 "Dumping execution's stderr" + set -- "$@" ${1:+-o} -path '*/stderr/*' +fi + +if ${do_gencode} +then + print_verbose 2 'Dumping gencode-*' + set -- "$@" ${1:+-o} \( -name 'gencode-*' -a ! -path '*/stdout/*' -a ! -path '*/stderr/*' \) +fi + +if ${do_code} +then + print_verbose 2 'Dumping code-*' + set -- "$@" ${1:+-o} \( -name 'code-*' -a ! -path '*/stdout/*' -a ! -path '*/stderr/*' \) +fi + +if ${do_messages} +then + print_verbose 2 'Dumping messages' + set -- "$@" ${1:+-o} -name 'messages' +fi + +if ${do_parameter} +then + print_verbose 2 'Dumping parameters' + set -- "$@" ${1:+-o} -path '*/parameter/*' +fi + +print_fields='$0' +${linenumber_prefix} && print_fields="FNR delim ${print_fields}" +${filename_prefix} && print_fields="FILENAME delim ${print_fields}" +awk_cmd="{ print ${print_fields} }" +set -- . -size +0 \( "$@" \) -exec awk -v delim="${delimiter}" "${awk_cmd}" {} \; + +print_verbose 2 "Using cache dir: ${cache_dir}" + +# If no host is specified then search all +for host in ${hosts:--} +do + test "${host}" = '-' && host= + + # find host dump directory + host_dir=$(find "${cache_dir}" -type f -name 'target_host' -exec grep -lxF "${host}" {} +) + print_verbose 3 'found host directory files:' + print_verbose 3 "${host_dir}" + + OLD_IFS=${IFS} + IFS=' +' + + for d in ${host_dir} + do + dir=${d%/*} + + print_verbose 0 "target host: $(cat "${dir}/target_host"), host directory: ${dir}" + hor_line '=' + + (cd "${dir}" && find "$@") + done + + IFS=${OLD_IFS} +done |
