Skip to content

Commit 9875115

Browse files
committed
Store options from KCL in a file for easy sourcing
zfsbootmenu-parse-commandline.sh defines several configuration variables based on KCL arguments; zfsbootmenu-exec.sh originally exported those to the environment for use by zfsbootmenu-countdown.sh and zfsbootmenu.sh. This works fine if zfsbootmenu.sh is only ever run in a local session. When connecting via SSH and launching zfsbootmenu from the shell, these configuration variables are not accessible. The simple solution is to write the configuration into a file that can be sourced by both zfsbootmenu-countdown.sh and zfsbootmenu.sh to populate their environments regardless of the way they are called. The boot-environment list has been renamed from "env" to "bootenvs" to avoid confusion with the "environment" file. Closes: #165.
1 parent b6ef299 commit 9875115

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

90zfsbootmenu/zfsbootmenu-countdown.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ fi
1616

1717
mkdir -p "${BASE}"
1818

19+
if [ -r "${BASE}/environment" ]; then
20+
# shellcheck disable=SC1090
21+
source "${BASE}/environment"
22+
else
23+
zwarn "failed to source ZBM environment"
24+
fi
25+
1926
# Write out a default or overridden hostid
2027
if [ -n "${spl_hostid}" ] ; then
2128
zinfo "writing /etc/hostid from command line: ${spl_hostid}"

90zfsbootmenu/zfsbootmenu-exec.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
#!/bin/bash
22
# vim: softtabstop=2 shiftwidth=2 expandtab
33

4-
export endian
5-
export spl_hostid
6-
export import_policy
7-
export menu_timeout
8-
export loglevel
9-
export root
10-
export zbm_sort
11-
export zbm_set_hostid
12-
134
# Disable all kernel messages to the console
145
echo 0 > /proc/sys/kernel/printk
156

@@ -30,6 +21,18 @@ echo "Loading ZFSBootMenu ..."
3021
export BASE="/zfsbootmenu"
3122
mkdir -p "${BASE}"
3223

24+
# shellcheck disable=SC2154
25+
cat > "${BASE}/environment" <<EOF
26+
export endian="${endian}"
27+
export spl_hostid="${spl_hostid}"
28+
export import_policy="${import_policy}"
29+
export menu_timeout="${menu_timeout}"
30+
export loglevel="${loglevel}"
31+
export root="${root}"
32+
export zbm_sort="${zbm_sort}"
33+
export zbm_set_hostid="${zbm_set_hostid}"
34+
EOF
35+
3336
getcmdline > "${BASE}/zbm.cmdline"
3437

3538
modprobe zfs 2>/dev/null

90zfsbootmenu/zfsbootmenu.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ if [ -z "${BASE}" ]; then
1212
export BASE="/zfsbootmenu"
1313
fi
1414

15+
if [ -r "${BASE}/environment" ]; then
16+
# shellcheck disable=SC1090
17+
source "${BASE}/environment"
18+
else
19+
zwarn "failed to source ZBM environment"
20+
fi
21+
1522
while [ ! -e "${BASE}/initialized" ]; do
1623
if ! delay=5 prompt="Press [ESC] to cancel" timed_prompt "Waiting for ZFSBootMenu initialization"; then
1724
zdebug "exited while waiting for initialization"
@@ -107,9 +114,9 @@ while true; do
107114
if [ "${BE_SELECTED}" -eq 0 ]; then
108115
# Populate the BE list, load any keys as necessary
109116
# If no BEs were found, remove the empty environment file
110-
populate_be_list "${BASE}/env" || rm -f "${BASE}/env"
117+
populate_be_list "${BASE}/bootenvs" || rm -f "${BASE}/bootenvs"
111118

112-
bootenv="$( draw_be "${BASE}/env" )"
119+
bootenv="$( draw_be "${BASE}/bootenvs" )"
113120
ret=$?
114121

115122
if [ "${ret}" -eq 130 ]; then

0 commit comments

Comments
 (0)