-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmtl-mirror
executable file
·83 lines (71 loc) · 1.62 KB
/
mtl-mirror
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
#!/bin/bash
showUsage() {
cat <<EOF
Usage:
mirror to ssh://[email protected]:~/mynotes/test
mirror to :main
mirror doc to :design
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
REM="$3"
if [[ "$3" =~ ^: ]]; then
REM=`cat .mtl/.mirrors | grep "^$2" | head -n 1 | cut -f 2`
else
echo "Failed: No mirror with that name."
REM=""
fi
if [[ $REM != "" ]]; then
if [[ $REM =~ ":" ]]; then
dest1=`echo $REM | cut -f 1 -d ":"`
dest2=`echo $REM | cut -f 2 -d ":"`
ssh $dest1 "mkdir -p ${dest2}/.mtl/d"
else
mkdir -p ${REM}/.mtl/d
fi
tempdir="/tmp/mtl/blobs"
mkdir -p ${tempdir}
echo "copying wrk index and src files to $REM"
scp .mtl/${1}* ${REM}/.mtl/.
#get blobs and copy them
for blob in `cat .mtl/${1}.index | cut -f 1 | uniq`
do
echo "copying blob: $blob to temp"
cp -a .mtl/d/$blob ${tempdir}/.
done
rsync -avz ${tempdir}/. ${REM}/.mtl/d/.
echo "DONE"
else
showUsage
fi
else
showUsage
fi
elif [ $# -eq 2 ]; then
REM="$2"
if [[ "$2" =~ ^: ]]; then
REM=`cat .mtl/.mirrors | grep "^$2" | head -n 1 | cut -f 2`
echo $REM
fi
if [[ $REM != "" ]]; then
if [ $1 == "to" ]; then
echo "rsyncing the mtl dir to $REM"
rsync -avz .mtl/* ${REM}/.mtl
echo "DONE"
elif [ $1 == "from" ]; then
echo "rsyncing the mtl dir from $REM"
rsync -avz ${REM}/.mtl/* .mtl
echo "DONE"
else
showUsage
fi
else
echo "Failed: No mirror with that name."
REM=""
fi
else
showUsage
fi