-
Notifications
You must be signed in to change notification settings - Fork 0
/
maniGen.sh
174 lines (149 loc) · 3.32 KB
/
maniGen.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
# Generate basic manifest xml file for repo remote manifest repository
# Noted : You must offer a address txt file with each line a git repository address written in it
# Author : wendy
# Date : 2018/05/05
outfile=default.xml
tabs=0
#clear the file everytime rerun this script
cat /dev/null > 'default.xml'
remote_name=$1
default_branch=$2
#default for remote name and default branch
if [[ $remote_name -eq "" ]]; then
remote_name="github"
fi
if [[ $default_branch -eq "" ]]; then
default_branch="master"
fi
array_index=0
path=""
put(){
echo -e '<'${*}'>' >> $outfile
}
put_head(){
put '?'${1}'?'
}
out_tabs(){
tmp=0
tabsstr=""
while [ $tmp -lt $((tabs)) ]
do
tabsstr=${tabsstr}'\t'
tmp=$((tmp+1))
done
echo -e -n $tabsstr >> $outfile
}
tag_start(){
out_tabs
put $1
tabs=$((tabs+1))
}
tag_end(){
tabs=$((tabs-1))
out_tabs
put '/'${1}
}
tag_remote(){
out_tabs
str=""
str='remote name="'${1}'"\n\t\t\t
fetch="'${2}'"/'
put $str
}
tag_default(){
out_tabs
str=""
sync_cvalue=false
sync_svalue=false
if [[ ${3} -eq true ]]; then
sync_cvalue=$3
fi
if [[ ${4} -eq true ]]; then
sync_svalue=$4
fi
str='default revision="'${1}'"\n\t\t\t
remote="'${2}'"\n\t\t\t
sync_j="4"\n\t\t\t
sync_c="'$sync_cvalue'"\n\t\t\t
sync_s="'$sync_svalue'"/'
put $str
}
tag_project(){
out_tabs
str=""
sync_cvalue=false
sync_svalue=false
if [[ ${3} -eq true ]]; then
sync_cvalue=$3
fi
if [[ ${4} -eq true ]]; then
sync_svalue=$4
fi
str='project path="'${1}'"\n\t\t\t
name="'${2}'"\n\t\t\t
sync_c="'$sync_cvalue'"\n\t\t\t
sync_s="'$sync_svalue'"\n\t\t\t
revision="'${5}'"\n\t\t\t
remote="'${6}'"/'
put $str
}
check_can_clone(){
# uncomment here when internet is usable!
if ! git clone ${1};then
echo >&2 "error: you don't have permission on this repository!skipping..."
else
file_name=$(echo $(basename ${1}))
repo_name=$(echo $file_name | sed 's/\.[^.]*$//')
rm -rf $repo_name
echo "deleting temporaly cloned repo... >>>"
write_info ${1}
fi
# write_info ${1}
}
read_address(){
if [ ! -f "address.txt" ]; then
echo "address.txt doesn't exist!check your path..."
exit -1
else
for line in $(cat address.txt)
do
echo "read address :${line} >>>"
#检查这个仓库是否可以clone(是否有权限)
check_can_clone ${line}
done
fi
}
write_info(){
line=${1}
#对地址处理,最后的是仓库名,将仓库名和前缀分离。
fullsuffix=$(echo $(basename ${1}))
path=$(echo $(dirname ${1}))
#这是仓库名
filename=$(echo $fullsuffix | sed 's/\.[^.]*$//')
#保存进数组用于稍后生成xml节点信息
arr[$array_index]=$filename
array_index=`expr $array_index + 1`
}
gen_XML(){
put_head 'xml version="1.0" encoding="UTF-8"'
tag_start 'manifest'
#default can only have one!
tag_default $2 $1 false true
#but you can have multiple remote.
tag_remote $1 $path
for address in ${arr[@]}; do
tag_project repos/$address $address false true $2 $1
done
tag_end 'manifest'
echo "manifest file generate success!"
}
print_Info(){
echo '-----------------generated xml file content:--------------'
echo `cat default.xml`
echo '---------------------------end:---------------------------'
}
# main process goes here...
read_address
gen_XML $remote_name $default_branch
print_Info