forked from drunkard/ceph-Chinese-doc
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcommit-updated.sh
More file actions
executable file
·77 lines (67 loc) · 1.85 KB
/
Copy pathcommit-updated.sh
File metadata and controls
executable file
·77 lines (67 loc) · 1.85 KB
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
#!/bin/bash
MAINLINE=/git/ceph
ZH_CODE=/repo/ceph-Chinese-doc
ZH_READABLE=/repo/ceph-readable-doc
MAINLINE_HEAD_ID=`awk -F'=' '{if($1=="CUR") print $2}' $ZH_CODE/update-doc.sh`
ZH_CODE_HEAD_ID=`git -C $ZH_CODE log -1 --pretty=%H`
CODE_MSG="doc: sync with mainline
Updated to: $MAINLINE_HEAD_ID"
READABLE_MSG="ceph doc: updates
sync with $ZH_CODE_HEAD_ID in github.com/drunkard/ceph-Chinese-doc or
$MAINLINE_HEAD_ID in official ceph.git"
commit_zh_code() {
cd $ZH_CODE || {
echo "$FUNCNAME: cd $ZH_CODE failed"
return 1
}
# check if updated cursor
if [ `git -C $ZH_CODE diff update-doc.sh |grep -c CUR=` -ne 2 ]; then
echo "$FUNCNAME: update-doc.sh not changed, please update CUR="
return 2
fi
git commit -a --signoff -m "$CODE_MSG"
if [ $? -eq 0 ]; then
echo -e "$FUNCNAME: commit ok in git repo: $ZH_CODE\n"
else
echo -e "$FUNCNAME: commit failed in git repo: $ZH_CODE\n"
return 1
fi
}
commit_zh_readable() {
if [ -d $MAINLINE/build-doc ] && cd $MAINLINE/build-doc; then
if rsync -avrR output/ $ZH_READABLE/; then
echo -e "synced with most recent build\n"
else
echo -e "$FUNCNAME: sync failed"
return 2
fi
fi
git -C $ZH_READABLE add output/ && \
git -C $ZH_READABLE commit --signoff -m "$READABLE_MSG" output/
if [ $? -eq 0 ]; then
echo -e "$FUNCNAME: commit ok in repo: $ZH_READABLE\n"
else
echo -e "$FUNCNAME: commit failed in repo: $ZH_READABLE\n"
return 1
fi
}
push_remotes() {
local repos repo
local remotes remote
if [ $# -ge 1 ]; then
repos=$@
else
echo "$FUNCNAME: wrong argument, need at least one git repo"
return 127
fi
for repo in $repos; do
remotes=`git -C $repo remote`
for remote in $remotes; do
echo -e "\nPushing $repo to remote: $remote ..."
git -C $repo push $remote
done
done
}
if commit_zh_code && commit_zh_readable; then
push_remotes $ZH_CODE $ZH_READABLE
fi