on master help sign in
Add script to use for diagnosing issues
commitad42b275a936b9ac07c9dcb292dcb958f683480a authorEthan P <eth-p+git@hidden.email> dateSat 22 Feb 2020, 18:14 (7 years ago) parent2dac1c8
1 file changed+157
diagnostics/info.sh+157
diagnostics/info.shnew file+157
@@ -0,0 +1,157 @@
1+#!/usr/bin/env bash
2+_modules=('system' 'bat' 'bat_config' 'bat_wrapper' 'tool')
3+_modules_consented=()
4+
5+
6+# -----------------------------------------------------------------------------
7+# Modules:
8+# -----------------------------------------------------------------------------
9+
10+_bat_:description() {
11+ _collects "Version information for 'bat'."
12+}
13+
14+_bat_config_:description() {
15+ _collects "The environment variables used by 'bat'."
16+ _collects "The 'bat' configuration file."
17+}
18+
19+_bat_wrapper_:description() {
20+ _collects "Any wrapper script used by 'bat'."
21+}
22+
23+_system_:description() {
24+ _collects "Operating system name."
25+ _collects "Operating system version."
26+}
27+
28+_tool_:description() {
29+ _collects "Version information for 'less'."
30+}
31+
32+
33+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
34+
35+_bat_:run() {
36+ _out bat --version
37+ _out env | grep '^BAT_\|^PAGER='
38+}
39+
40+_bat_config_:run() {
41+ if [[ -f "$(bat --config-file)" ]]; then
42+ _out cat "$(bat --config-file)";
43+ fi
44+}
45+
46+_bat_wrapper_:run() {
47+ if file "$(which bat)" | grep "text executable" &>/dev/null; then
48+ _out cat "$(which bat)"
49+ fi
50+}
51+
52+_system_:run() {
53+ _out uname -srm
54+
55+ if command -v "sw_vers" &>/dev/null; then _out sw_vers; fi
56+ if command -v "lsb_release" &>/dev/null; then _out lsb_release -a; fi
57+}
58+
59+_tool_:run() {
60+ _out less --version | head -n1
61+}
62+
63+
64+# -----------------------------------------------------------------------------
65+# Functions:
66+# -----------------------------------------------------------------------------
67+
68+_out() {
69+ printf "\n+" 1>&2
70+ printf " %s" "$@" 1>&2
71+ printf "\n" 1>&2
72+
73+ "$@" 2>&1
74+}
75+
76+_tput() {
77+ tput "$@" 1>&2 2>/dev/null
78+}
79+
80+_collects() {
81+ printf " - %s\n" "$1" 1>&2
82+}
83+
84+_ask_module() {
85+ _tput clear
86+ _tput cup 0 0
87+
88+cat 1>&2 <<EOF
89+--------------------------------------------------------------------------------
90+This script will collect information to help assist in issue resolution.
91+You will be provided with a description of the data collected, and will be
92+offered the opportunity to give consent for each piece of information collected.
93+--------------------------------------------------------------------------------
94+EOF
95+
96+ # Print description.
97+ _tput setaf 3
98+ printf "The following data will be collected:\n" 1>&2
99+ _tput sgr0
100+ "_$1_:description"
101+ _tput sgr0
102+
103+ # Print preview.
104+ _tput setaf 3
105+ printf "\nThe following commands will be run:\n" 1>&2
106+ _tput sgr0
107+ declare -f "_$1_:run" \
108+ | sed 's/^ *//; s/;$//' \
109+ | grep '^_out ' \
110+ | sed 's/^_out //' 1>&2
111+
112+ # Prompt
113+ printf "\n" 1>&2
114+ local response
115+ while true; do
116+ _tput cup "$(( $(tput lines 2>/dev/null || echo 22) - 1 ))"
117+ _tput el
118+ read -er -p "Collect $(sed 's/_/ /' <<< "$1") data? [Y/n] " response
119+ case "$response" in
120+ Y|y|yes|'') return 0 ;;
121+ N|n|no) return 1 ;;
122+ *) continue
123+ esac
124+ done
125+}
126+
127+_run_module() {
128+ printf "========== %s ==========\n" "$1"
129+ "_$1_:run"
130+}
131+
132+
133+# -----------------------------------------------------------------------------
134+# Functions:
135+# -----------------------------------------------------------------------------
136+
137+# Ask for consent.
138+if [[ "$1" = '-y' ]]; then
139+ _modules_consented=("${_modules[@]}")
140+else
141+ trap '_tput rmcup; exit 1' INT
142+ _tput smcup
143+ for _module in "${_modules[@]}"; do
144+ if _ask_module "$_module"; then
145+ _modules_consented+=("$_module")
146+ fi
147+ done
148+ _tput rmcup
149+fi
150+
151+# Collect information.
152+for _module in "${_modules_consented[@]}"; do
153+ _run_module "$_module"
154+ printf "\n"
155+done
156+
157+