-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmtl-copy
executable file
·59 lines (55 loc) · 1.26 KB
/
mtl-copy
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
#!/bin/bash
showUsage() {
cat <<EOF
Usage: 1
copy from ssh://[email protected]:~/mynotes/test
copy to ssh://[email protected]:~/mynotes/test
EOF
}
### this is just quick proof of concept version
### later we add a way to store remotes
if [ $# -eq 3 ]; then
if [ $2 == "to" ]; then
if [[ $3 =~ ":" ]]; then
todir=/tmp/mtl/.mtl
else
todir=${3}/.mtl
fi
echo "copying the mtl ${1} dir to remote ($todir) location.."
#copy the wrk index scr files
mkdir -p ${todir}/d
echo "copying wrk index and src files"
cp .mtl/${1}* ${todir}/.
#get blobs and copy them
for blob in `cat .mtl/${1}.index | cut -f 1 | uniq`
do
echo "copying blob: $blob"
cp .mtl/d/$blob ${todir}/d/.
done
if [[ $3 =~ ":" ]]; then
dest1=`echo $3 | cut -f 1 -d ":"`
dest2=`echo $3 | cut -f 2 -d ":"`
tar -C /tmp/mtl -cvzf - .mtl | ssh $dest1 "cat - | tar xvzf - -C $dest2"
fi
echo "DONE"
elif [ $2 == "from" ]; then
echo "not implemented ..."
else
showUsage
fi
elif [ $# -eq 2 ]; then
if [ $1 == "to" ]; then
echo "copying the mtl dir to remote location.."
#ls mkdir -p ${2}
scp -r .mtl ${2}/.mtl
echo "DONE"
elif [ $1 == "from" ]; then
echo "copying the mtl dir.."
scp -r ${1} .mtl
echo "DONE"
else
showUsage
fi
else
showUsage
fi