-
Notifications
You must be signed in to change notification settings - Fork 171
/
git.sh
executable file
·35 lines (31 loc) · 984 Bytes
/
git.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
#!/bin/bash
UPSTREAM=${TUNASYNC_UPSTREAM_URL}
if [[ -z "$UPSTREAM" ]];then
echo "Please set the TUNASYNC_UPSTREAM_URL"
exit 1
fi
function repo_init() {
git clone --mirror "$UPSTREAM" "$TUNASYNC_WORKING_DIR"
}
function update_linux_git() {
cd "$TUNASYNC_WORKING_DIR"
echo "==== SYNC $UPSTREAM START ===="
git remote set-url origin "$UPSTREAM"
/usr/bin/timeout -s INT 3600 git remote -v update -p
local ret=$?
[[ $ret -ne 0 ]] && echo "git update failed with rc=$ret"
local head=$(git remote show origin | awk '/HEAD branch:/ {print $NF}')
[[ -n "$head" ]] && echo "ref: refs/heads/$head" > HEAD
objs=$(find objects -type f | wc -l)
[[ "$objs" -gt 8 ]] && git repack -a -b -d
sz=$(git count-objects -v|grep -Po '(?<=size-pack: )\d+')
sz=$(($sz*1024))
echo "Total size is" $(numfmt --to=iec $sz)
echo "==== SYNC $UPSTREAM DONE ===="
return $ret
}
if [[ ! -f "$TUNASYNC_WORKING_DIR/HEAD" ]]; then
echo "Initializing $UPSTREAM mirror"
repo_init
fi
update_linux_git