-
Notifications
You must be signed in to change notification settings - Fork 4
/
func_server.sh
83 lines (73 loc) · 1.86 KB
/
func_server.sh
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# SERVER
#-------------------------------------------------------------------------------
# What: Set server specific aliases and functions
# Who: Gregor Gorjanc
#-------------------------------------------------------------------------------
server()
{
# $1 = server name abbreviation
# $2 = server IP address
# $3 = username
# $4 = SSH options
optSSH=$(echo ${4} | sed -e "s/-P/-p/")
optSCP=$(echo ${4} | sed -e "s/-p/-P/")
eval "alias ping${1}=\"ping ${2}\""
eval "alias login${1}=\"ssh ${optSSH} ${3}@${2}\""
eval "rsyncFrom${1}()
{
local i
for i in \$@; do
rsync ${3}@${2}:\$i .
done
}; export -f rsyncFrom${1}"
eval "pull${1}()
{
local i
for i in \$@; do
scp -r ${optSCP} ${3}@${2}:\$i .
done
}; export -f pull${1}"
eval "push${1}()
{
echo "TODO: how to add an option to push to a user defined folder instead of ~/."
scp -r ${optSCP} \$@ ${3}@${2}:~/.
}; export -f push${1}"
eval "diff${1}()
{
DIFF=diff
case \${1} in
--diff=* )
DIFF=\$(echo \${1} | sed -e \"s/--diff=//\")
shift
;;
esac
file=\$(basename \${1})
scp ${optSCP} ${3}@${2}:\${1} \${file}_from_${1}
if [ -z \"\${2}\" ]; then
trg=\${file}
else
trg=\${2}
fi
echo \"Compare \${file}_from_${1} to \${trg} (12=default) or vice versa (21)?\"
read WAY
if [ \"\${WAY}\" == \"21\" ]; then
\${DIFF} \${trg} \${file}_from_${1}
else
\${DIFF} \${file}_from_${1} \${trg}
fi
echo \"\nRemove the copied file \${file}_from_${1} (Y/n)?\"
read YORN
if [ \"\${YORN}\" != \"n\" ]; then
rm -f \${file}_from_${1}
fi
}; export -f diff${1}"
eval "cwdiff${1}()
{
diff${1} --diff=cwdiff \${@}
}; export -f cwdiff${1}"
eval "colordiff${1}()
{
diff${1} --diff=colordiff \${@}
}; export -f colordiff${1}"
}
export -f server