-
Notifications
You must be signed in to change notification settings - Fork 3
/
sync.sh
executable file
·100 lines (85 loc) · 2.56 KB
/
sync.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
BASE=$HOME/mirrors
LOCAL_SVN=${BASE}/chibios-svn
LOCAL_GIT=${BASE}/chibios-git
#REMOTE_SVN=https://svn.osdn.net/svnroot/chibios/ # Moved back to SF, see url below
REMOTE_SVN=https://svn.code.sf.net/p/chibios/code/
[email protected]:ChibiOS/ChibiOS.git
SVN_UUID=27425a3e-05d8-49a3-a47f-9c15f0e5edd8
# Add spaces between mirrors ([name1]=value1 [name2]=value2). No spaces in names.
declare -A EXTRA_GIT_MIRRORS=([bitbucket][email protected]:chibios/chibios.git)
if [ -z "$1" ]
then
echo "No argument supplied, need init, update, or push"
exit 1
fi
if [[ "$1" == "init" ]]
then
if [ -d $BASE ]
then
echo repo already exists at ${BASE}
# exit 1
fi
mkdir -p ${BASE}
echo Creating SVN Mirror...
svnadmin create ${LOCAL_SVN} ${REMOTE_SVN}
mkdir ${LOCAL_SVN}/hooks
echo '#!/bin/sh' > ${LOCAL_SVN}/hooks/pre-revprop-change
chmod 755 ${LOCAL_SVN}/hooks/pre-revprop-change
echo Syncing SVN mirror for the first time, this will take a while...
svnsync sync file://${LOCAL_SVN}
echo Cloning from git...
git clone ${REMOTE_GIT} ${LOCAL_GIT}
echo Setting up additional mirrors
cd ${LOCAL_GIT}
for i in ${!EXTRA_GIT_MIRRORS[@]}
do
git remote add ${i} ${EXTRA_GIT_MIRRORS[$i]}
done
cd ..
echo Adding SVN config
cp authors.txt ${BASE}/
cat << EOF >> ${LOCAL_GIT}/.git/config
[svn-remote "svn"]
url = file://${LOCAL_SVN}
fetch = trunk:refs/remotes/origin/master
fetch = branches/stable_18.2.x:refs/remotes/origin/stable_18.2.x
fetch = branches/stable_19.1.x:refs/remotes/origin/stable_19.1.x
fetch = branches/stable_20.3.x:refs/remotes/origin/stable_20.3.x
fetch = branches/stable_21.6.x:refs/remotes/origin/stable_21.6.x
fetch = branches/stable_21.11.x:refs/remotes/origin/stable_21.11.x
tags = tags/ver*:refs/tags/*
rewriteRoot = svn://svn.code.sf.net/p/chibios/svn
rewriteUUID = ${SVN_UUID}
[svn]
authorsfile = ${BASE}/authors.txt
useLogAuthor = true
EOF
fi
if [[ "$1" == "update" ]]
then
echo Syncing SVN mirror...
svnsync sync file://${LOCAL_SVN}
echo Updating SVN refs...
cd ${LOCAL_GIT}
find .git/svn/refs/remotes/origin/ -name .rev_map* -delete # Force rebuilding revision maps
git svn fetch
for i in $(git branch | cut -c 3-)
do
echo Updating branch: $i
git checkout $i
git rebase
done
git checkout master
fi
if [[ "$1" == "push" ]]
then
echo Pushing to all git mirrors...
cd ${LOCAL_GIT}
for i in $(git remote)
do
echo $i
git push $i --all
git push $i --tags --force
done
fi