Repository navigation
Expand file tree
/
Copy pathxssh.sh
More file actions
64 lines (55 loc) · 1.95 KB
/
Copy pathxssh.sh
File metadata and controls
64 lines (55 loc) · 1.95 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Extended ssh
declare -f _xssh_timestamp >/dev/null || {
# Turn case-insensitive matching temporarily on, if necessary.
nocasematchWasOff=0
shopt nocasematch >/dev/null || nocasematchWasOff=1
(( nocasematchWasOff )) && shopt -s nocasematch
case "${OSTYPE}" in
darwin*) _xssh_timestamp() { stat -f %m "$1"; } ;;
*) _xssh_timestamp() { stat --printf='%Y' "$1"; } ;;
esac
# Restore state of 'nocasematch' option, if necessary.
(( nocasematchWasOff )) && shopt -u nocasematch
unset nocasematchWasOff
}
xssh() {
ssh_bin=$(type -P ssh)
_xssh() {
local source_script=$(readlink -e "$HOME/.xssh_rc")
if [[ -z "$xssh_encrypt_script" || \
-z "$xssh_encrypt_timestamp" || \
$( _xssh_timestamp $source_script ) -gt "$xssh_encrypt_timestamp" \
]]; then
echo "Using new \`$source_script' file as remote bash script..."
xssh_encrypt_script=$( gzip --stdout $source_script | openssl enc -a -A )
xssh_encrypt_timestamp=$(date '+%s')
fi
script_name=$(mktemp -u "/tmp/.xssh_${USER}_XXXXXXXXXXXXX")
$ssh_bin -t "$@" \
"export xssh_script=$script_name; echo '$xssh_encrypt_script' | \
openssl enc -a -A -d | zcat >\$xssh_script; \
exec bash --rcfile \$xssh_script";
}
local nbargs word script_name oldExpandAliases
nbargs=0
for word in "$@"; do
case "$word" in
-*) : option ;;
*=*) : setting env ;;
*) nbargs=$((++nbargs)) ;;
esac
done
case "$nbargs" in
0) echo "Vous devez spécifier un host" ;;
1) _xssh "$@" ;;
*) $ssh_bin "$@" ;;
esac
}
typeset -f _ssh >/dev/null && shopt -u hostcomplete && complete -F _ssh xssh
# Local Variables: #
# mode: ksh #
# tab-width: 4 #
# indent-tabs-mode: nil #
# End: #
#
# vi: set expandtab ts=4 sw=4 sts=4: #