Skip to content

Commit 82af0b6

Browse files
committed
zfsbootmenu: add kcl-editing helper, use in kernel page too
1 parent 73cd9f7 commit 82af0b6

3 files changed

Lines changed: 63 additions & 24 deletions

File tree

zfsbootmenu/bin/zfsbootmenu

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ while true; do
145145
"mod-u")
146146
set_default_kernel "${fs}"
147147
;;
148+
"mod-e")
149+
/libexec/zfsbootmenu-edit-kcl -b "${BOOTFS}" -k "${kpath}" "${fs}"
150+
;;
148151
"left")
149152
key="mod-s"
150153
BE_SELECTED=1
@@ -255,26 +258,7 @@ while true; do
255258
tput cnorm
256259
;;
257260
"mod-e")
258-
tput clear
259-
tput cnorm
260-
261-
IFS=$'\t' read -r _ kernel _ <<< "$( select_kernel "${selected_be}" || echo $'-\t-\t-' )"
262-
[ "${kernel}" = "-" ] && kernel=""
263-
264-
echo ""
265-
/libexec/zfsbootmenu-preview -b "${BOOTFS}" -k "${kernel}" "${selected_be}"
266-
267-
BE_ARGS="$( load_be_cmdline "${selected_be}" "${kernel}" )"
268-
while IFS= read -r line; do
269-
def_args="${line}"
270-
done <<< "${BE_ARGS}"
271-
272-
echo -e "\nNew kernel command line (root= arguments will be ignored)"
273-
cmdline="$( /libexec/zfsbootmenu-input "${def_args}" )"
274-
275-
if [ -n "${cmdline}" ] ; then
276-
kcl_tokenize <<< "${cmdline}" | kcl_suppress root > "${BASE}/cmdline"
277-
fi
261+
/libexec/zfsbootmenu-edit-kcl -b "${BOOTFS}" "${selected_be}"
278262
;;
279263
"mod-t")
280264
[ -f "${BASE}/cmdline" ] && rm "${BASE}/cmdline"

zfsbootmenu/lib/zfsbootmenu-ui.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,15 @@ draw_kernel() {
203203
zdebug "using kernels file: ${_kernels}"
204204

205205
header="$( column_wrap "\
206-
^[RETURN] boot:[ESCAPE] back
207-
^[CTRL+D] set default:[CTRL+U] unset default
208-
^[CTRL+L] view logs:[CTRL+H] help" \
206+
^[RETURN] boot:[CTRL+E] edit kcl:[ESCAPE] back
207+
^[CTRL+D] set default::[CTRL+U] unset default
208+
^[CTRL+L] view logs::[CTRL+H] help" \
209209
"\
210210
^[RETURN] boot
211211
^[CTRL+D] set default
212212
^[CTRL+H] help" )"
213213

214-
expects="--expect=alt-d,alt-u,left,right"
214+
expects="--expect=alt-d,alt-u,alt-e,left,right"
215215

216216
if ! selected="$( HELP_SECTION=kernel-management ${FUZZYSEL} \
217217
--prompt "${benv} > " --tac --delimiter=$'\t' --with-nth=2 \
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
# vim: softtabstop=2 shiftwidth=2 expandtab
3+
4+
# shellcheck disable=SC1091
5+
source /lib/profiling-lib.sh >/dev/null 2>&1 || true
6+
source /etc/zfsbootmenu.conf >/dev/null 2>&1 || exit 1
7+
source /lib/kmsg-log-lib.sh >/dev/null 2>&1 || exit 1
8+
source /lib/zfsbootmenu-core.sh >/dev/null 2>&1 || exit 1
9+
10+
BOOTFS=""
11+
KERNEL=""
12+
13+
while getopts "b:k:" opt; do
14+
case "${opt}" in
15+
b) BOOTFS="${OPTARG}" ;;
16+
k) KERNEL="${OPTARG}" ;;
17+
*) ;;
18+
esac
19+
done
20+
21+
shift $((OPTIND - 1))
22+
23+
ENV="${1}"
24+
25+
if [ -z "${KERNEL}" ]; then
26+
# shellcheck disable=SC2034
27+
read -r _ KERNEL _ <<< "$( select_kernel "${ENV}" || echo $'-\t-\t-' )"
28+
[ "${KERNEL}" = "-" ] && KERNEL=""
29+
fi
30+
31+
# Clear the screen for the prompt
32+
tput clear
33+
tput cnorm
34+
35+
# Draw the header for this environment and kernel
36+
echo ""
37+
/libexec/zfsbootmenu-preview -b "${BOOTFS}" -k "${KERNEL}" "${ENV}"
38+
39+
# Load the existing command line as the default
40+
BE_ARGS="$( load_be_cmdline "${ENV}" "${KERNEL}" )" || BE_ARGS=""
41+
while IFS= read -r line; do
42+
default_args="${line}"
43+
done <<< "${BE_ARGS}"
44+
45+
cat <<EOF
46+
47+
ENTER A NEW KERNEL COMMAND LINE
48+
- Interrupt with Ctrl+C or specify an empty line to cancel input
49+
- Any "root=" arguments will be ignored
50+
EOF
51+
52+
cmdline="$( /libexec/zfsbootmenu-input "${default_args}" )" || cmdline=""
53+
[ -n "${cmdline}" ] || exit 1
54+
55+
kcl_tokenize <<< "${cmdline}" | kcl_suppress root > "${BASE}/cmdline"

0 commit comments

Comments
 (0)