forked from danrabinowitz/sshrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sshrc
executable file
·41 lines (41 loc) · 1.3 KB
/
sshrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env bash
function sshrc() {
local SSHHOME=${SSHHOME:=~}
local SSHRC_REMOTETMPDIR=${SSHRC_REMOTETMPDIR:='/var/www/webdev/$USER'}
if [ -f $SSHHOME/.sshrc ]; then
local files=.sshrc
if [ -d $SSHHOME/.sshrc.d ]; then
files="$files .sshrc.d"
fi
ssh -t "$@" "
if [ -e /etc/motd ]; then cat /etc/motd; fi
export SSHHOME=\$(mktemp -d $SSHRC_REMOTETMPDIR/.$(whoami).sshrc.XXXX)
export SSHRCCLEANUP=\$SSHHOME
trap \"rm -rf \$SSHRCCLEANUP; exit\" 0
echo $'"$(cat "$0" | xxd -p)"' | xxd -p -r > \$SSHHOME/sshrc
chmod +x \$SSHHOME/sshrc
echo $'"$( cat << 'EOF' | xxd -p
#!/usr/bin/env bash
exec bash --rcfile <(echo '
if [ -e /etc/bash.bashrc ]; then source /etc/bash.bashrc; fi
if [ -e ~/.bashrc ]; then source ~/.bashrc; fi
source '$SSHHOME'/.sshrc;
export PATH=$PATH:'$SSHHOME'
') "$@"
EOF
)"' | xxd -p -r > \$SSHHOME/bashsshrc
chmod +x \$SSHHOME/bashsshrc
echo $'"$(tar cz -h -C $SSHHOME $files | xxd -p)"' | xxd -p -r | tar mxz -C \$SSHHOME
export SSHHOME=\$SSHHOME
\$SSHHOME/bashsshrc
rm -rf \$SSHRCCLEANUP
"
else
echo "No such file: $SSHHOME/.sshrc"
fi
}
if [ $1 ]; then
sshrc $@
else
ssh
fi