-
Notifications
You must be signed in to change notification settings - Fork 1
/
to-grace
executable file
·65 lines (55 loc) · 1.91 KB
/
to-grace
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
#!/usr/bin/env bash
E_DOESNOTEXIST=2
E_UNKNOWNSOURCE=4
E_NOTYOURS=5
E_NOTTHOSEFILES=6
E_FAILEDREADLINK=7
if hostname -A | grep -q legion
then
target_host="login01.ext.grace.ucl.ac.uk"
elif hostname -A | grep -q grace
then
target_host="login05.external.legion.ucl.ac.uk"
else
echo -e "This script does not know where it is.\n It is panicking, like a lost kitten. \n"
exit $E_UNKNOWNSOURCE
fi
for source in "$@"; do
if [ ! -e "$source" ]; then
echo "File or directory does not exist: $source" >&2
exit $E_DOESNOTEXIST
fi
source_path=`readlink -e "$source"`
if [ $? -ne 0 ]; then
echo "Could not determine full path of file: $source" >&2
exit $E_FAILEDREADLINK
fi
# Check owner of target
owner=`stat -c%U "$source_path"`
current_user=`whoami`
if [ "$owner" != "$current_user" ]; then
echo "This script will not operate on files you do not own." >&2
exit $E_NOTYOURS
fi
echo "Trying to transfer: ${source_path}" >&2
case "${source_path}" in
/imports/iridis/*)
tar -cz ${source_path} | ssh -t "$target_host" tar -xvz --xform="simports/iridis/${current_user}/iridis_import/"
# ^-- So, if you send over your iridis files, they'll end up in
# ~/iridis_imports
# which isn't ideal but isn't the worst either
#
# At least I hope that's what'll happen
# oh and tar strips the leading / automatically
;;
/home/${current_user}/*|/imports/home?/${current_user}/*|/scratch/scratch/${current_user}/*)
tar -cz ${source_path} | ssh -t "$target_host" tar -xvz --xform="simports/home./${current_user}/./"
# ^-- I was going to use rsync here but the /imports/home? link messed that up
#rsync -a --stats -r --relative "$source_path" "$target_host":"$target_relative"
;;
*)
echo "This script will not operate on files outside your home or Scratch area." >&2
exit $E_NOTTHOSEFILES
;;
esac
done