reduce number of ssh-calls on sshs

This commit is contained in:
Jakobus Schürz 2022-05-19 08:48:34 +02:00
parent 0ecb4308b3
commit 0bd8b45e55

View file

@ -432,36 +432,42 @@ EOF
if [ -e "${TMPBASHCONFIG}" ] ; then
logdebug "create remote bashrc"
logdebug "SSH_OPTS: $SSH_OPTS"
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"
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 ${REMOTETMPVIMCONFIG}'
alias vim='vim -u ${REMOTETMPVIMCONFIG}'
alias vimdiff='vimdiff -u ${REMOTETMPVIMCONFIG}'
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="${REMOTETMPVIMCONFIG}"
export BASHRC="${REMOTETMPBASHCONFIG}"
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}"
logtrace $(ssh -T ${SSH_OPTS} $@ "stat ${REMOTETMPBASHCONFIG}")
#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 > ${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 ${REMOTETMPBASHCONFIG} ${REMOTETMPVIMCONFIG}\" EXIT " ;
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 ${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 $@«"