Skip to content

Commit

Permalink
Small fixes for SSH usage
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
zdykstra committed Sep 21, 2021
1 parent 0e14c7b commit 78656b0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 8 additions & 3 deletions 90zfsbootmenu/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,15 @@ EOF
[ -f /lib/zfsbootmenu-lib.sh ] && source /lib/zfsbootmenu-lib.sh
export PATH=/usr/sbin:/usr/bin:/sbin:/bin
export TERM=linux
export HOME=/root
zdebug "sourced /etc/profile"
EOF

# Setup a default environment for all login shells
cat << EOF >> "${initdir}/.bashrc"
# Setup a default environment for bash -i
cat << EOF >> "${initdir}/root/.bashrc"
[ -f /etc/profile ] && source /etc/profile
[ -f /lib/zfsbootmenu-completions.sh ] && source /lib/zfsbootmenu-completions.sh
export PS1="\033[0;33mzfsbootmenu\033[0m \w > "
Expand All @@ -327,7 +329,10 @@ alias trace="ztrace"
alias debug="ztrace"
alias help="/libexec/zfsbootmenu-help -L recovery-shell"
zdebug "sourced /.bashrc"
zdebug "sourced /root/.bashrc"
EOF

# symlink to .profile for /bin/sh - launched by dropbear
ln -s "/root/.bashrc" "${initdir}/root/.profile"
}
2 changes: 1 addition & 1 deletion 90zfsbootmenu/zfsbootmenu-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2402,7 +2402,7 @@ emergency_shell() {
echo -n "Launching emergency shell: "
echo -e "${message}\n"

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

# shellcheck disable=SC2034
Expand Down
4 changes: 4 additions & 0 deletions 90zfsbootmenu/zfsbootmenu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ if [ -d /libexec/setup.d ]; then
unset _hook
fi

# Override control_term if executing over SSH
# shellcheck disable=SC2034
[ -n "${SSH_TTY}" ] && control_term="${SSH_TTY}"

# shellcheck disable=SC2016
fuzzy_default_options=( "--ansi" "--no-clear"
"--layout=reverse-list" "--inline-info" "--tac" "--color=16"
Expand Down

0 comments on commit 78656b0

Please sign in to comment.