From cae3a94dd810377f4a90e63adcd8e139193d900f Mon Sep 17 00:00:00 2001 From: David Kebler Date: Mon, 23 Nov 2020 15:14:18 -0800 Subject: [PATCH] add support for sourcing for remote shell via ssh. Works for both interactive and non-interactive added support for alises in non-interactive shell via bash.bashrc add TODO markdown file to track desired changes --- TODO.md | 4 ++++ load.sh | 1 + setup/deploy-user.sh | 3 ++- setup/etc/bash.bashrc | 10 +++++++--- setup/etc/profile | 8 ++++---- shell.env | 2 ++ ssh/readme.md | 1 + 7 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 TODO.md create mode 100644 ssh/readme.md diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..dd288bd --- /dev/null +++ b/TODO.md @@ -0,0 +1,4 @@ +# TODOS + +add ability to disable loading shell repos +add ability to disable alias in non-interactive and interactive shells diff --git a/load.sh b/load.sh index c316af7..00f19d3 100755 --- a/load.sh +++ b/load.sh @@ -53,6 +53,7 @@ function shell_process_directory () { local SUBDIRS local IGNORE_FILE SUBDIRS=$([[ -f "$DIR/.bash-shell-include" ]] && cat "$DIR/.bash-shell-include" || echo $BASH_SHELL_BASE_SUBDIRS) + [[ $SSH_LOGIN ]] && SUBDIRS+=" ssh" IGNORE_FILE="$([[ -f "$DIR/.bash-shell-ignore" ]] && echo "$DIR" || echo "$BASH_SHELL_BASE")/.bash-shell-ignore" for SUBDIR in $SUBDIRS; do if [ -e "$DIR/$SUBDIR" ]; then diff --git a/setup/deploy-user.sh b/setup/deploy-user.sh index 031ba42..7e86897 100755 --- a/setup/deploy-user.sh +++ b/setup/deploy-user.sh @@ -1,7 +1,8 @@ #!/bin/bash -_USER=${1:-USER} +_USER=${1:-$USER} [[ ! $(id -u $_USER) -ge 1000 ]] && echo "no user $_USER or user not a regular" && exit 1 +echo user: $_USER deployment [[ ! $BASH_SHELL_BASE ]] && BASH_SHELL_BASE="$(dirname "$(cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")" echo Base Shell Directory as detected is $BASH_SHELL_BASE echo ok to continue? diff --git a/setup/etc/bash.bashrc b/setup/etc/bash.bashrc index ed8f64a..e606959 100644 --- a/setup/etc/bash.bashrc +++ b/setup/etc/bash.bashrc @@ -4,8 +4,12 @@ # [ $EUID -eq 0 ] && echo 'Root User' || echo 'Non Root User' # [[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive' # shopt -q login_shell && echo 'Login shell' || echo 'Not login shell' -# echo ---- -# echo sourcing $BASH_SHELL_LOAD - +# ([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]) && echo ssh remote user || echo local user +# echo --------------------- +if ([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]); then + export SSH_SESSION=true + source /etc/profile +fi +shopt -s expand_aliases source $BASH_SHELL_LOAD diff --git a/setup/etc/profile b/setup/etc/profile index 62603d5..b202743 100644 --- a/setup/etc/profile +++ b/setup/etc/profile @@ -22,9 +22,9 @@ export BASH_SHELL_BASE=THISWILLCHANGEDBYDEPLOYSCRIPT # uncomment to NOT load the BASH SHELL Repos for interactive login shell # NO_LOGIN_BASHRC=true if [[ $- == *i* ]]; then # interactive? - echo interactive login shell - if [[ ! $NO_LOGIN_BASHRC ]]; then - # echo loading $BASH_SHELL_LOAD + [[ ! $SSH_SESSION ]] && echo interactive login shell + if [[ ! $NO_LOGIN_BASHRC ]]; then + # echo interactive shell loading $BASH_SHELL_LOAD source "$BASH_SHELL_LOAD" else NORMAL="\[\e[0m\]" @@ -38,7 +38,7 @@ if [[ $- == *i* ]]; then # interactive? unset RED GREEN NORMAL fi else - if [[ $EUID -ne 0 ]]; then + if [[ $EUID -ne 0 ]] && [[ ! $SSH_SESSION ]]; then export LOGIN_LOG=$HOME/logs/login.log mkdir -p $HOME/logs touch $LOGIN_LOG diff --git a/shell.env b/shell.env index 5a01d3d..df86111 100644 --- a/shell.env +++ b/shell.env @@ -43,6 +43,8 @@ export BASH_SHELL_STARTUP=$BASH_SHELL_BASE/startup.sh # strtup.sh is default # shopt -u expand_aliases #################### +([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]) && export SSH_SESSION=true + # identify a network name that this host resides on # make a directory of the same name # if unset then only /all will be sourced diff --git a/ssh/readme.md b/ssh/readme.md new file mode 100644 index 0000000..c56107f --- /dev/null +++ b/ssh/readme.md @@ -0,0 +1 @@ +*this will be sourced if this is a an ssh login session*