-
Notifications
You must be signed in to change notification settings - Fork 1
/
update-mirror.sh
executable file
·71 lines (56 loc) · 1.56 KB
/
update-mirror.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
#!/bin/bash
#in: json description of asso repo src [mirrors]
#action: for all src
# if local copy does not exist git clone and add remote
# git pull;
# for all mirror
# git push
#requires: jq, git
scriptPath=$0
oldWorkingDir=`pwd`
workingDir="."
gitPrefix="[email protected]:"
if [[ "$scriptPath" == *"/"* ]]; then
scriptName=`echo $scriptPath | rev | cut -d '/' -f1 | rev`
workingDir=`echo $scriptPath | sed "s/$scriptName//g"`
fi
cd $workingDir
MIRRORS_LIST="mirror-list.json"
ABSOLUTE_PATH_OF_LOCAL_REPOS=`pwd`
LOG_FILE="logs"
cd $ABSOLUTE_PATH_OF_LOCAL_REPOS
echo " ### Start updates ### " >> $LOG_FILE
date >> $LOG_FILE
#For all repo to mirror
for rep in `cat $MIRRORS_LIST | jq -r '.[] | "\(.src)"'`
do
cd $ABSOLUTE_PATH_OF_LOCAL_REPOS
u=`echo $rep | cut -d '/' -f1`
r=`echo $rep | cut -d '/' -f2`
echo "Repo: $rep"
mirrors=`cat $MIRRORS_LIST | jq -r ".[] | select(.src==\"$rep\") | \"\(.mirrors)\""`
echo " -> mirrors: $mirrors"
#If local copy does not exists
if [ ! -d "$r" ]; then
echo "$ABSOLUTE_PATH_OF_LOCAL_REPOS/$r does not exist."
git clone $gitPrefix$u/$r.git 2>&1
fi
cd $r
git pull 2>&1
#For all mirror
for m in `echo $mirrors | jq -r '.[]'`
do
echo " mirror: $m"
remote_u=`echo $m | cut -d '/' -f1`
remote_r=`echo $m | cut -d '/' -f2`
#if mirror is new
git remote get-url $remote_u 2>&1
if [ $? -ne 0 ]; then
echo "Mirror $remote_u not registered yet"
git remote add $remote_u $gitPrefix$remote_u/$remote_r.git 2>&1
fi
#push to mirror
git push $remote_u master 2>&1
done
done >> $LOG_FILE
cd $oldWorkingDir