forked from tuna/tunasync-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cros.sh
executable file
·81 lines (72 loc) · 2.19 KB
/
cros.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
#!/bin/bash
set -e
USE_BITMAP_INDEX=${USE_BITMAP_INDEX:-"0"}
CONCURRENT_JOBS=${CONCURRENT_JOBS:-"1"}
MANIFEST_URL=$TUNASYNC_UPSTREAM_URL/chromiumos/manifest.git
MANIFEST_DIR=$TUNASYNC_WORKING_DIR/.manifest
MANIFEST_XML_REPOLIST=$(dirname $0)/helpers/manifest-xml-repolist.py
IGNORED_REPO=(
)
export GIT_TERMINAL_PROMPT=0
function contains() {
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
function git_clone_or_pull {
URL=$1
DIRECTORY=$2
BARE=$3
name=$(basename $2)
if [[ -z $BARE ]]; then
if [[ -d $DIRECTORY ]]; then
git -C "$DIRECTORY" remote set-url origin "$URL"
git -C "$DIRECTORY" pull
else
git clone "$URL" "$DIRECTORY"
fi
else
if [[ -d "$DIRECTORY" ]]; then
git -C "$DIRECTORY" remote set-url origin "$URL"
git -C "$DIRECTORY" fetch --force --prune 2>&1 | sed "s/^/$name: /"
else
git clone --bare "$URL" "$DIRECTORY"
fi
fi
}
function git_repack() {
echo "Start writing bitmap index"
while read repo; do
cd $repo
size=$(du -sk .|cut -f1)
total_size=$(($total_size+1024*$size))
objs=$(find objects -type f | wc -l)
if [[ "$objs" -gt 8 && "$size" -gt "100000" ]]; then
git repack -a -b -d
fi
done < <(find $TUNASYNC_WORKING_DIR -not -path "$MANIFEST_DIR/.git/*" -type f -name HEAD -exec dirname '{}' ';')
}
git_clone_or_pull $MANIFEST_URL $MANIFEST_DIR
for repo in $($MANIFEST_XML_REPOLIST $MANIFEST_DIR/default.xml cros chromium); do
contains $repo ${IGNORED_REPO[@]} && continue
echo $TUNASYNC_UPSTREAM_URL/$repo
if [[ -z ${DRY_RUN:-} ]]; then
while true
do
running=$(jobs -r | wc -l)
if [ "$running" -lt "$CONCURRENT_JOBS" ]
then
echo "start cloning $repo"
git_clone_or_pull $TUNASYNC_UPSTREAM_URL/$repo $TUNASYNC_WORKING_DIR/$repo yes &
break
else
wait -n
fi
done
fi
done
wait # wait for all background jobs
total_size=0
if [[ -z ${DRY_RUN:-} && "$USE_BITMAP_INDEX" == "1" ]]; then
git_repack
echo "Total size is" $(numfmt --to=iec $total_size)
fi