Skip to content

Commit 78656b0

Browse files
committed
Small fixes for SSH usage
- dropbear launches bash as /bin/sh, which needs $HOME/.profile - emergency_shell launches bash as bash -i, which needs $HOME/.bashrc - when zfsbootmenu is launched via SSH, override control_term to point to the SSH TTY, so that output is always sent to the right location - restore a TERM= value, so that SSH connections have a proper env
1 parent 0e14c7b commit 78656b0

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

90zfsbootmenu/module-setup.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,15 @@ EOF
308308
[ -f /lib/zfsbootmenu-lib.sh ] && source /lib/zfsbootmenu-lib.sh
309309
310310
export PATH=/usr/sbin:/usr/bin:/sbin:/bin
311+
export TERM=linux
312+
export HOME=/root
311313
312314
zdebug "sourced /etc/profile"
313315
314316
EOF
315317

316-
# Setup a default environment for all login shells
317-
cat << EOF >> "${initdir}/.bashrc"
318+
# Setup a default environment for bash -i
319+
cat << EOF >> "${initdir}/root/.bashrc"
318320
[ -f /etc/profile ] && source /etc/profile
319321
[ -f /lib/zfsbootmenu-completions.sh ] && source /lib/zfsbootmenu-completions.sh
320322
export PS1="\033[0;33mzfsbootmenu\033[0m \w > "
@@ -327,7 +329,10 @@ alias trace="ztrace"
327329
alias debug="ztrace"
328330
alias help="/libexec/zfsbootmenu-help -L recovery-shell"
329331
330-
zdebug "sourced /.bashrc"
332+
zdebug "sourced /root/.bashrc"
331333
332334
EOF
335+
336+
# symlink to .profile for /bin/sh - launched by dropbear
337+
ln -s "/root/.bashrc" "${initdir}/root/.profile"
333338
}

90zfsbootmenu/zfsbootmenu-lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2402,7 +2402,7 @@ emergency_shell() {
24022402
echo -n "Launching emergency shell: "
24032403
echo -e "${message}\n"
24042404

2405-
# -i (interactive) mode will source /.bashrc
2405+
# -i (interactive) mode will source $HOME/.bashrc
24062406
/bin/bash -i
24072407

24082408
# shellcheck disable=SC2034

90zfsbootmenu/zfsbootmenu.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ if [ -d /libexec/setup.d ]; then
6767
unset _hook
6868
fi
6969

70+
# Override control_term if executing over SSH
71+
# shellcheck disable=SC2034
72+
[ -n "${SSH_TTY}" ] && control_term="${SSH_TTY}"
73+
7074
# shellcheck disable=SC2016
7175
fuzzy_default_options=( "--ansi" "--no-clear"
7276
"--layout=reverse-list" "--inline-info" "--tac" "--color=16"

0 commit comments

Comments
 (0)