forked from GoPerry/upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lrepo.sh
executable file
·103 lines (91 loc) · 1.61 KB
/
lrepo.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
100
101
102
103
#!/bin/bash
## globle variables
REMOTE='git@172.16.11.162'
REPOSITORY_DIR='/media/Ubuntu/repository'
ANDROID_SRC_DIR='LINUX/android'
## functions
_repo ()
{
mkdir -p $REPOSITORY_DIR/$1
(
cd $REPOSITORY_DIR/$1
echo $'\n\ny' | repo init -u $REMOTE:$1/manifest
mkdir -p .repo/projects/$ANDROID_SRC_DIR
)
}
_init ()
{
local tmp=${3##*:}
local repository=${tmp%%/*}
if [[ ! -a .repo ]]; then
mkdir .repo
for i in manifests manifests.git projects repo; do
ln -s $REPOSITORY_DIR/$repository/.repo/$i .repo/$i
done
echo $'\n\ny' | repo "$@"
fi
}
_fetch ()
{
if [[ -d .repo ]]; then
(
cd .repo/manifests
git pull
)
if [[ ! -a .repo/manifest.xml.bak ]]; then
mv .repo/manifest.xml .repo/manifest.xml.bak
fi
awk '
BEGIN {
FS = "\"";
OFS = "\"";
}
/<project/ {
if ($4 ~ "^v[^/]*/'$ANDROID_SRC_DIR'/") {
$4 = substr($4, index($4, "/") + 1);
} else if ($2 ~ "^amss_....$") {
$4 = $2;
} else {
$4 = "'$ANDROID_SRC_DIR'/" $4;
}
}
/<copyfile/ {
if ($2 ~ "^v[^/]*/'$ANDROID_SRC_DIR'/") {
$2 = substr($2, index($2, "/") + 1);
} else {
$2 = "'$ANDROID_SRC_DIR'/" $2;
}
}
/.*/ {
printf("%s\n", $0);
}
' .repo/manifest.xml.bak > .repo/manifest.xml
fi
}
_sync ()
{
if [[ -d .repo ]]; then
_fetch
repo sync
fi
}
## main
cmd=$1
case $cmd in
init)
_init "$@"
;;
fetch)
_fetch
;;
sync)
_sync
;;
repo)
# _repo "$@"
;;
*)
echo 'help'
;;
esac
exit $?