-
Notifications
You must be signed in to change notification settings - Fork 0
/
lukskeychainfunctions
159 lines (120 loc) · 4.02 KB
/
lukskeychainfunctions
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/sh
script_version_functions="06032024-0247"
PREREQ=""
# Output prerequisites
prereqs() {
echo "$PREREQ"
}
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
clear_the_line() {
echo -ne "\033[2K" ; echo -ne "\r"
}
clear_the_line_go_up_and_clean_the_line() {
echo -ne "\033[2K" # erase line
echo -ne "\033[A\033[K" # up and erase to end of line (and go to new line)
echo -ne "\033[2K" # erase line
echo -ne "\r"
}
clear_input_buffer() {
echo -n " Clearing the input buffer (1 second)..."
read -t 1 -n 111
clear_the_line
# Non-working examples in my version of BusyBox:
#while read -t 0; do : ; done
#read -d '' -t 0 -n 1
#read -t 0 -n 1
}
# Function to clear the character
clear_character() {
printf '\b \b' # Move the cursor back, print a space, move the cursor back again
}
debug_pause() {
if [ -n "${1}" ]; then
timeout=$1
else
timeout=5
fi
while :; do
echo "[ DEBUG: debug_pause ${timeout} / script version: ${script_version}/${script_version_functions} ]"
clear_input_buffer
clear_the_line_go_up_and_clean_the_line
echo "Press 's' to drop to shell, or wait $timeout seconds to continue automatically, or press the spacebar to continue now..."
choice="" # Setting the default value of choice to '' because the BusyBox read command
# doesn't change its value when no user input is provided.
# Read a single character with timeout
read -t $timeout -n 1 -r choice
clear_the_line_go_up_and_clean_the_line
# clear_character
if [ "${choice}" = "s" ] || [ "${choice}" = "d" ]; then
if [ -r /usr/bin/mcedit ]; then
echo "Dropping to shell... (Type 'exit' and press Enter to exit. Programs 'mc' and 'mcedit' are available.)"
else
echo "Dropping to shell... (Type 'exit' and press Enter to exit.)"
fi
/bin/sh
break
elif [ -n "${choice}" ]; then
continue
else
break
fi
done
echo "Continuing..."
clear_input_buffer
clear_the_line_go_up_and_clean_the_line
}
dialog_skip_or_do() {
if [ -n "${1}" ]; then
timeout_dialog_skip_or_do=$1 # local variable
else
echo "ERROR: timeout not specified."
exit 2
fi
if [ -n "${2}" ]; then # if string is not null
echo "${2}"
fi
while :; do
clear_input_buffer
clear_the_line
echo "Press 'c' to cancel, or press 's' to drop to shell,"
echo "or wait $timeout_dialog_skip_or_do seconds to continue automatically, or press the spacebar to continue now..."
choice="" # Setting the default value of choice to '' because the BusyBox read command
# doesn't change its value when no user input is provided.
# Read a single character with timeout
read -t $timeout_dialog_skip_or_do -n 1 -r key
clear_the_line_go_up_and_clean_the_line
# clear_character
if [ "${choice}" = "s" ] || [ "${choice}" = "d" ]; then
if [ -r /usr/bin/mcedit ]; then
echo "Dropping to shell... (Type 'exit' and press Enter to exit. Programs 'mc' and 'mcedit' are available.)"
else
echo "Dropping to shell... (Type 'exit' and press Enter to exit.)"
fi
/bin/sh
break
elif [ "${choice}" = "c" ]; then
echo "Cancelling..."
clear_input_buffer
clear_the_line_go_up_and_clean_the_line
clear_the_line_go_up_and_clean_the_line
echo "... Canceled."
return 1
elif [ -n "${choice}" ]; then
continue
else
break
fi
done
echo "Continuing..."
clear_input_buffer
clear_the_line_go_up_and_clean_the_line
if [ -n "${2}" ]; then # if string is not null
clear_the_line_go_up_and_clean_the_line
fi
return 0
}