change invocation of remote shell in sshs
This commit is contained in:
parent
0bd8b45e55
commit
ec2bd6b3f2
1 changed files with 135 additions and 108 deletions
243
functions.sh
243
functions.sh
|
@ -372,115 +372,142 @@ EOF
|
|||
|
||||
}
|
||||
|
||||
sshs() {
|
||||
ENTRY
|
||||
|
||||
|
||||
local LOGLEVEL="WARN"
|
||||
# MKTMPCMD='mktemp $(echo ${XDG_RUNTIME_DIR}/bashrc.XXXXXXXX.conf)'
|
||||
# VIMMKTMPCMD="mktemp ${XDG_RUNTIME_DIR}/vimrc.XXXXXXXX.conf"
|
||||
|
||||
local f
|
||||
local TMPBASHCONFIG=$(mktemp -p ${XDG_RUNTIME_DIR} -t bashrc.XXXXXXXX --suffix=.conf)
|
||||
local FILELIST=( "${MSC_BASE}/functions.sh" "${MSC_BASE}/logging" "${MSC_BASE}/myshell_load_fortmpconfig" $(getbashrcfile) ~/.aliases "${MSC_BASE}/aliases" "${MSC_BASE}/PS1" "${MSC_BASE}/bash_completion.d/*" )
|
||||
|
||||
logdebug "FILELIST: ${FILELIST[@]}"
|
||||
if [ -e "${HOME}/.config/myshellconfig/sshs_addfiles.conf" ] ; then
|
||||
for f in $(cat "${HOME}/.config/myshellconfig/sshs_addfiles.conf");do
|
||||
[ -e "$f" ] && {\
|
||||
logdebug "add $f to FILELIST"; \
|
||||
FILELIST+=("$f"); }
|
||||
done
|
||||
fi
|
||||
logdebug "FILELIST1: ${FILELIST[@]}"
|
||||
local SSH_OPTS="-o VisualHostKey=no -o ControlMaster=auto -o ControlPersist=20s -o ControlPath=~/.ssh/master-%C"
|
||||
#local SSH_OPTS="-o VisualHostKey=no -o ControlMaster=yes -o ControlPersist=10s -o ControlPath=~/.ssh/ssh-%C"
|
||||
# Read /etc/bashrc or /etc/bash.bashrc (depending on distribution) and /etc/profile.d/*.sh first
|
||||
ssh -T ${SSH_OPTS} $@ "pwd" >/dev/null 2>/dev/null || { logerror "Server $@ not reachable -> exit"; return 1; }
|
||||
cat << EOF >> "${TMPBASHCONFIG}"
|
||||
[ -e /etc/bashrc ] && BASHRC=/etc/bashrc
|
||||
[ -e /etc/bash.bashrc ] && BASHRC=/etc/bash.bashrc
|
||||
. \$BASHRC
|
||||
|
||||
export USERNAME="${USERNAME}"
|
||||
export FULLNAME="${FULLNAME}"
|
||||
export USEREMAIL="${USEREMAIL}"
|
||||
export SCRIPT_LOG="\$(cat /proc/\$$/cmdline | xargs -0 echo|awk '{print \$3}' |sed 's/.conf$/.log/')"
|
||||
export LOGLEVEL_DEFAULT="${LOGLEVEL_DEFAULT}"
|
||||
export FILELOGLEVEL_DEFAULT="${FILELOGLEVEL_DEFAULT}"
|
||||
|
||||
for i in /etc/profile.d/*.sh; do
|
||||
if [ -r "$i" ];then
|
||||
if [ "$PS1" ]; then
|
||||
. "$i"
|
||||
else
|
||||
. "$i" >/dev/null
|
||||
fi
|
||||
fi
|
||||
done
|
||||
unset i
|
||||
EOF
|
||||
|
||||
for f in ${FILELIST[*]}; do
|
||||
if [ -e $f ]; then
|
||||
logdebug "add $f to tmpconfig"
|
||||
cat "$f" >> "${TMPBASHCONFIG}";
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $# -ge 1 ]; then
|
||||
if [ -e "${TMPBASHCONFIG}" ] ; then
|
||||
logdebug "create remote bashrc"
|
||||
logdebug "SSH_OPTS: $SSH_OPTS"
|
||||
local REMOTETMPCONFIGS=($(ssh -T ${SSH_OPTS} $@ "mktemp -p \${XDG_RUNTIME_DIR-~} -t bashrc.XXXXXXXX --suffix=.conf" | tr -d '[:space:]' ) $(ssh -T ${SSH_OPTS} $@ "mktemp -p \${XDG_RUNTIME_DIR-~} -t vimrc.XXXXXXXX --suffix=.conf" | tr -d '[:space:]' ))
|
||||
echo remote tmp bashrc ${REMOTETMPCONFIGS[0]}
|
||||
echo remote tmp vimrc ${REMOTETMPCONFIGS[1]}
|
||||
#local REMOTETMPBASHCONFIG=$(ssh -T ${SSH_OPTS} $@ "mktemp -p \${XDG_RUNTIME_DIR-~} -t bashrc.XXXXXXXX --suffix=.conf" | tr -d '[:space:]' )
|
||||
#logdebug "REMOTETMPBASHCONFIG: $REMOTETMPBASHCONFIG"
|
||||
# logdebug $(ssh -T ${SSH_OPTS} $@ "stat ${REMOTETMPBASHCONFIG}")
|
||||
# logdebug $(ssh -T ${SSH_OPTS} $@ "hostnamectl")
|
||||
#logdebug "create remote vimrc"
|
||||
#local REMOTETMPVIMCONFIG=$(ssh -T ${SSH_OPTS} $@ "mktemp -p \${XDG_RUNTIME_DIR-~} -t vimrc.XXXXXXXX --suffix=.conf" | tr -d '[:space:]' )
|
||||
#logdebug "REMOTETMPVIMCONFIG: $REMOTETMPVIMCONFIG"
|
||||
|
||||
# Add additional aliases to bashrc for remote-machine
|
||||
cat << EOF >> "${TMPBASHCONFIG}"
|
||||
alias vi='vim -u ${REMOTETMPCONFIGS[1]}'
|
||||
alias vim='vim -u ${REMOTETMPCONFIGS[1]}'
|
||||
alias vimdiff='vimdiff -u ${REMOTETMPCONFIGS[1]}'
|
||||
export LS_OPTIONS="${LS_OPTIONS}"
|
||||
export VIMRC="${REMOTETMPCONFIGS[1]}"
|
||||
export BASHRC="${REMOTETMPCONFIGS[0]}"
|
||||
title "\$USER@\$HOSTNAME: \$PWD"
|
||||
loginfo "This bash runs with temporary config from \$BASHRC"
|
||||
EOF
|
||||
|
||||
logdebug "create fill remote bashrc"
|
||||
#ssh -T ${SSH_OPTS} $@ "cat > ${REMOTETMPBASHCONFIG}" < "${TMPBASHCONFIG}"
|
||||
ssh -T ${SSH_OPTS} $@ "cat > ${REMOTETMPCONFIGS[0]}" < "${TMPBASHCONFIG}"
|
||||
# logtrace $(ssh -T ${SSH_OPTS} $@ "stat ${REMOTETMPBASHCONFIG}")
|
||||
logdebug "create file remote vimrc"
|
||||
#ssh -T ${SSH_OPTS} $@ "cat > ${REMOTETMPVIMCONFIG}" < "${MSC_BASE}/vimrc"
|
||||
ssh -T ${SSH_OPTS} $@ "cat > ${REMOTETMPCONFIGS[1]}" < "${MSC_BASE}/vimrc"
|
||||
local RCMD="/bin/bash --noprofile --norc -c "
|
||||
RCMD="
|
||||
trap \"rm -f ${REMOTETMPCONFIGS[0]} ${REMOTETMPCONFIGS[1]}\" EXIT " ;
|
||||
logdebug "run remote shell with temporary config"
|
||||
#ssh -t ${SSH_OPTS} $@ "$RCMD; SSHS=true bash -c \"function bash () { /bin/bash --rcfile ${REMOTETMPBASHCONFIG} -i ; } ; export -f bash; exec bash --rcfile ${REMOTETMPBASHCONFIG}\""
|
||||
ssh -t ${SSH_OPTS} $@ "$RCMD; SSHS=true bash -c \"function bash () { /bin/bash --rcfile ${REMOTETMPCONFIGS[0]} -i ; } ; export -f bash; exec bash --rcfile ${REMOTETMPCONFIGS[0]}\""
|
||||
rm "${TMPBASHCONFIG}"
|
||||
else
|
||||
logwarn "${TMPBASHCONFIG} does not exist. Using »ssh -t $@«"
|
||||
ssh -t "$@"
|
||||
fi
|
||||
else
|
||||
logwarn "too few arguments for sshs" >&2
|
||||
ssh
|
||||
fi
|
||||
|
||||
EXIT
|
||||
}
|
||||
#sshs() {
|
||||
# ENTRY
|
||||
#
|
||||
#
|
||||
# local LOGLEVEL="WARN"
|
||||
## MKTMPCMD='mktemp $(echo ${XDG_RUNTIME_DIR}/bashrc.XXXXXXXX.conf)'
|
||||
## VIMMKTMPCMD="mktemp ${XDG_RUNTIME_DIR}/vimrc.XXXXXXXX.conf"
|
||||
#
|
||||
# local f
|
||||
# local TMPBASHCONFIG=$(mktemp -p ${XDG_RUNTIME_DIR} -t bashrc.XXXXXXXX --suffix=.conf)
|
||||
# local FILELIST=( "${MSC_BASE}/functions.sh" "${MSC_BASE}/logging" "${MSC_BASE}/myshell_load_fortmpconfig" $(getbashrcfile) ~/.aliases "${MSC_BASE}/aliases" "${MSC_BASE}/PS1" "${MSC_BASE}/bash_completion.d/*" )
|
||||
#
|
||||
# logdebug "FILELIST: ${FILELIST[@]}"
|
||||
# if [ -e "${HOME}/.config/myshellconfig/sshs_addfiles.conf" ] ; then
|
||||
# for f in $(cat "${HOME}/.config/myshellconfig/sshs_addfiles.conf");do
|
||||
# [ -e "$f" ] && {\
|
||||
# logdebug "add $f to FILELIST"; \
|
||||
# FILELIST+=("$f"); }
|
||||
# done
|
||||
# fi
|
||||
# logdebug "FILELIST1: ${FILELIST[@]}"
|
||||
# local SSH_OPTS="-o VisualHostKey=no -o ControlMaster=auto -o ControlPersist=20s -o ControlPath=~/.ssh/master-%C"
|
||||
# #local SSH_OPTS="-o VisualHostKey=no -o ControlMaster=yes -o ControlPersist=10s -o ControlPath=~/.ssh/ssh-%C"
|
||||
# # Read /etc/bashrc or /etc/bash.bashrc (depending on distribution) and /etc/profile.d/*.sh first
|
||||
# #ssh -T ${SSH_OPTS} $@ "pwd" >/dev/null 2>/dev/null || { logerror "Server $@ not reachable -> exit"; return 1; }
|
||||
# cat << EOF >> "${TMPBASHCONFIG}"
|
||||
#[ -e /etc/bashrc ] && BASHRC=/etc/bashrc
|
||||
#[ -e /etc/bash.bashrc ] && BASHRC=/etc/bash.bashrc
|
||||
#. \$BASHRC
|
||||
#
|
||||
#export USERNAME="${USERNAME}"
|
||||
#export FULLNAME="${FULLNAME}"
|
||||
#export USEREMAIL="${USEREMAIL}"
|
||||
#export SCRIPT_LOG="\$(cat /proc/\$$/cmdline | xargs -0 echo|awk '{print \$3}' |sed 's/.conf$/.log/')"
|
||||
#export LOGLEVEL_DEFAULT="${LOGLEVEL_DEFAULT}"
|
||||
#export FILELOGLEVEL_DEFAULT="${FILELOGLEVEL_DEFAULT}"
|
||||
#
|
||||
#for i in /etc/profile.d/*.sh; do
|
||||
# if [ -r "$i" ];then
|
||||
# if [ "$PS1" ]; then
|
||||
# . "$i"
|
||||
# else
|
||||
# . "$i" >/dev/null
|
||||
# fi
|
||||
# fi
|
||||
#done
|
||||
#unset i
|
||||
#EOF
|
||||
#
|
||||
# for f in ${FILELIST[*]}; do
|
||||
# if [ -e $f ]; then
|
||||
# logdebug "add $f to tmpconfig"
|
||||
# cat "$f" >> "${TMPBASHCONFIG}";
|
||||
# fi
|
||||
# done
|
||||
#
|
||||
# if [ $# -ge 1 ]; then
|
||||
# if [ -e "${TMPBASHCONFIG}" ] ; then
|
||||
# logdebug "create remote bashrc"
|
||||
# logdebug "SSH_OPTS: $SSH_OPTS"
|
||||
#
|
||||
# sshcmd=$(cat << _remote_commands
|
||||
#mktemp -p \${XDG_RUNTIME_DIR-~} -t bashrc.XXXXXXXX --suffix=.conf | tr -d '[:space:]'
|
||||
#echo " "
|
||||
#mktemp -p \${XDG_RUNTIME_DIR-~} -t vimrc.XXXXXXXX --suffix=.conf | tr -d '[:space:]'
|
||||
#echo " "
|
||||
#mktemp -p \${XDG_RUNTIME_DIR-~} -t tst.XXXXXXXX --suffix=.conf | tr -d '[:space:]'
|
||||
#echo " "
|
||||
#_remote_commands
|
||||
#)
|
||||
# local REMOTETMPCONFIGS=($(ssh -T ${SSH_OPTS} $@ "$sshcmd") )
|
||||
## local REMOTETMPCONFIGS=($(ssh -T ${SSH_OPTS} $@ "mktemp -p \${XDG_RUNTIME_DIR-~} -t bashrc.XXXXXXXX --suffix=.conf" | tr -d '[:space:]' ) $(ssh -T ${SSH_OPTS} $@ "mktemp -p \${XDG_RUNTIME_DIR-~} -t vimrc.XXXXXXXX --suffix=.conf" | tr -d '[:space:]' ))
|
||||
# logdebug remote tmp bashrc ${REMOTETMPCONFIGS[0]}
|
||||
# logdebug remote tmp vimrc ${REMOTETMPCONFIGS[1]}
|
||||
# #local REMOTETMPBASHCONFIG=$(ssh -T ${SSH_OPTS} $@ "mktemp -p \${XDG_RUNTIME_DIR-~} -t bashrc.XXXXXXXX --suffix=.conf" | tr -d '[:space:]' )
|
||||
# #logdebug "REMOTETMPBASHCONFIG: $REMOTETMPBASHCONFIG"
|
||||
## logdebug $(ssh -T ${SSH_OPTS} $@ "stat ${REMOTETMPBASHCONFIG}")
|
||||
## logdebug $(ssh -T ${SSH_OPTS} $@ "hostnamectl")
|
||||
# #logdebug "create remote vimrc"
|
||||
# #local REMOTETMPVIMCONFIG=$(ssh -T ${SSH_OPTS} $@ "mktemp -p \${XDG_RUNTIME_DIR-~} -t vimrc.XXXXXXXX --suffix=.conf" | tr -d '[:space:]' )
|
||||
# #logdebug "REMOTETMPVIMCONFIG: $REMOTETMPVIMCONFIG"
|
||||
#
|
||||
# # Add additional aliases to bashrc for remote-machine
|
||||
# cat << EOF >> "${TMPBASHCONFIG}"
|
||||
#alias vi='vim -u ${REMOTETMPCONFIGS[1]}'
|
||||
#alias vim='vim -u ${REMOTETMPCONFIGS[1]}'
|
||||
#alias vimdiff='vimdiff -u ${REMOTETMPCONFIGS[1]}'
|
||||
#export LS_OPTIONS="${LS_OPTIONS}"
|
||||
#export VIMRC="${REMOTETMPCONFIGS[1]}"
|
||||
#export BASHRC="${REMOTETMPCONFIGS[0]}"
|
||||
#title "\$USER@\$HOSTNAME: \$PWD"
|
||||
#loginfo "This bash runs with temporary config from \$BASHRC"
|
||||
#EOF
|
||||
#
|
||||
# logdebug "create fill remote bashrc"
|
||||
# local TESTFILE=/tmp/bla
|
||||
# cat << EOF3 > "${TESTFILE}"
|
||||
#ich bin ein testfile
|
||||
#zweite zeile
|
||||
#EOF3
|
||||
#
|
||||
#ssh -T ${SSH_OPTs} $@ << _remote_cmd
|
||||
#stat "${REMOTETMPCONFIGS[2]}"
|
||||
#echo BLA
|
||||
#cat <<- 'eof2' > ${REMOTETMPCONFIGS[2]}
|
||||
#$(cat ${TMPBASHCONFIG})
|
||||
#eof2
|
||||
#echo BLA2
|
||||
#_remote_cmd
|
||||
#echo BLA3
|
||||
# #ssh -T ${SSH_OPTS} $@ "cat > ${REMOTETMPBASHCONFIG}" < "${TMPBASHCONFIG}"
|
||||
# #ssh -T ${SSH_OPTS} $@ "cat > ${REMOTETMPCONFIGS[0]}" < "${TMPBASHCONFIG}"
|
||||
# # logtrace $(ssh -T ${SSH_OPTS} $@ "stat ${REMOTETMPBASHCONFIG}")
|
||||
# logdebug "create file remote vimrc"
|
||||
# #ssh -T ${SSH_OPTS} $@ "cat > ${REMOTETMPVIMCONFIG}" < "${MSC_BASE}/vimrc"
|
||||
# ssh -T ${SSH_OPTS} $@ "cat > ${REMOTETMPCONFIGS[1]}" < "${MSC_BASE}/vimrc"
|
||||
# local RCMD="/bin/bash --noprofile --norc -c "
|
||||
# RCMD="
|
||||
# trap \"rm -f ${REMOTETMPCONFIGS[0]} ${REMOTETMPCONFIGS[1]}\" EXIT " ;
|
||||
# logdebug "run remote shell with temporary config"
|
||||
# #ssh -t ${SSH_OPTS} $@ "$RCMD; SSHS=true bash -c \"function bash () { /bin/bash --rcfile ${REMOTETMPBASHCONFIG} -i ; } ; export -f bash; exec bash --rcfile ${REMOTETMPBASHCONFIG}\""
|
||||
# ssh -t ${SSH_OPTS} $@ "$RCMD; SSHS=true bash -c \"function bash () { /bin/bash --rcfile ${REMOTETMPCONFIGS[0]} -i ; } ; export -f bash; exec bash --rcfile ${REMOTETMPCONFIGS[0]}\""
|
||||
# rm "${TMPBASHCONFIG}"
|
||||
# else
|
||||
# logwarn "${TMPBASHCONFIG} does not exist. Using »ssh -t $@«"
|
||||
# ssh -t "$@"
|
||||
# fi
|
||||
# else
|
||||
# logwarn "too few arguments for sshs" >&2
|
||||
# ssh
|
||||
# fi
|
||||
#
|
||||
# EXIT
|
||||
#}
|
||||
|
||||
[ -e ${MSC_BASE}/sshs ] && source ${MSC_BASE}/sshs
|
||||
|
||||
VIMRC="${MSC_BASE}/vimrc"
|
||||
|
||||
|
|
Loading…
Reference in a new issue