-
Notifications
You must be signed in to change notification settings - Fork 0
/
help.sh
executable file
·105 lines (92 loc) · 3.17 KB
/
help.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
#
# Salomon - Simple log file monitor and analyzer
# Help dialog display script
# Copyright (c) 2024 by Ralf Kilian
# Distributed under the MIT License (https://opensource.org/licenses/MIT)
#
# GitHub: https://github.com/urbanware-org/salomon
# GitLab: https://gitlab.com/urbanware-org/salomon
#
script_dir=$(dirname $(readlink -f $0))
. ${script_dir}/core/shell.sh # Use POSIX standard instead of 'source' here
shell_precheck
source ${script_dir}/core/compat.sh
compatibility_precheck
script_file=$(basename "$0")
source ${script_dir}/core/common.sh
read_config_file; check_config
dialog_help() {
doc_file="$1"
temp_file="/tmp/salomon_help_$$.tmp"
sed 's/\r$//' < ${script_dir}/docs/usage_${doc_file}.txt > ${temp_file}
dos2unix ${temp_file} &>/dev/null
if [ "$dialog_program" = "dialog" ]; then
dialog ${dlg_shadow} --exit-label "Back" --textbox ${temp_file} 256 90
else
whiptail --ok-button "Back" --textbox ${temp_file} 0 90
fi
rm -f ${temp_file}
}
while true; do
if [ "${dialog_program}" = "auto" ]; then
command -v dialog &>/dev/null
if [ $? -eq 0 ]; then
dialog_program="dialog"
else
command -v whiptail &>/dev/null
if [ $? -eq 0 ]; then
dialog_program="whiptail"
else
dialog_program=""
fi
fi
elif [ "${dialog_program}" = "dialog" ]; then
command -v dialog &>/dev/null
if [ $? -ne 0 ]; then
dialog_program=""
fi
elif [ "${dialog_program}" = "whiptail" ]; then
command -v whiptail &>/dev/null
if [ $? -ne 0 ]; then
dialog_program=""
fi
else
dialog_program=""
usage "The given dialog program is not supported"
fi
if [ -z "${dialog_program}" ]; then
usage "No supported dialog program found"
fi
dlg_text="Available usage information files:"
if [ "${dialog_program}" = "dialog" ]; then
user_input=$(dialog ${dlg_shadow} \
--ok-button "View" \
--cancel-button "Exit" \
--title "Help" \
--menu "${dlg_text}" 12 40 3 \
"S" "Salomon (main help)" \
"I" "Installation" \
"C" "Compatibility" \
"H" "Help" \
3>&1 1>&2 2>&3 3>&-)
else
user_input=$(whiptail --ok-button "View" \
--cancel-button "Exit" \
--title "Help" \
--menu "${dlg_text}" 14 40 3 \
"S" "Salomon (main help)" \
"I" "Installation" \
"C" "Compatibility" \
"H" "Help" \
3>&1 1>&2 2>&3 3>&-)
fi
case "${user_input}" in
[Ss]) dialog_help "salomon" ;;
[Ii]) dialog_help "install" ;;
[Cc]) dialog_help "compat" ;;
[Hh]) dialog_help "help" ;;
*) break;;
esac
done
clear