c999a3
Added first version of the compsgen.sh script (still be to fully tested !)
@@ -0,0 +1,267 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
#################################################################################
|
4
|
+
#
|
5
|
+
# Name : CentOS comps.xml generator
|
6
|
+
# Function : merge all the upstream comps.xml file into one
|
7
|
+
# How to call it : see usage()
|
8
|
+
# Author : Fabian Arrotin (arrfab@centos.org)
|
9
|
+
# Requirements : sqlite3 / xmlstarlet
|
10
|
+
#
|
11
|
+
#################################################################################
|
12
|
+
|
13
|
+
usage() {
|
14
|
+
|
15
|
+
cat << EOF
|
16
|
+
|
17
|
+
You need to call the script like this : $0 -arguments
|
18
|
+
|
19
|
+
-a : define the arch (required, default:none, values : [i386,x86_64])
|
20
|
+
-p : define the path containing all the Upstream comps.xml files for all variants(required, default:none)
|
21
|
+
-r : release to build ( eg. 6 )
|
22
|
+
-h : display this help
|
23
|
+
|
24
|
+
EOF
|
25
|
+
|
26
|
+
}
|
27
|
+
|
28
|
+
|
29
|
+
while getopts “ha:p:m:r:” OPTION
|
30
|
+
do
|
31
|
+
case $OPTION in
|
32
|
+
h)
|
33
|
+
usage
|
34
|
+
exit 1
|
35
|
+
;;
|
36
|
+
a)
|
37
|
+
arch=$OPTARG
|
38
|
+
;;
|
39
|
+
p)
|
40
|
+
destdir=$OPTARG
|
41
|
+
;;
|
42
|
+
r)
|
43
|
+
release=$OPTARG
|
44
|
+
;;
|
45
|
+
?)
|
46
|
+
usage
|
47
|
+
exit
|
48
|
+
;;
|
49
|
+
esac
|
50
|
+
done
|
51
|
+
|
52
|
+
varcheck() {
|
53
|
+
if [ -z "$1" ] ; then
|
54
|
+
usage
|
55
|
+
exit 1
|
56
|
+
fi
|
57
|
+
|
58
|
+
}
|
59
|
+
|
60
|
+
compsxmlin() {
|
61
|
+
echo Creating Comps DB tables ...
|
62
|
+
echo "CREATE TABLE categories (id ,name, desc, display_order ); CREATE TABLE languages (lang); CREATE TABLE groups (id, name, desc, def, uservisible, langonly, packagelist); CREATE TABLE grouplist (groupid, category_id);
|
63
|
+
" |sqlite3 $sqlitedb
|
64
|
+
|
65
|
+
# beginning the loop for each xml file
|
66
|
+
|
67
|
+
for xmlfile in $(ls $destdir/*.xml);
|
68
|
+
|
69
|
+
do
|
70
|
+
|
71
|
+
# just do that once
|
72
|
+
if [ "$aretableready" = "1" ] ; then
|
73
|
+
echo Tables are already there
|
74
|
+
else
|
75
|
+
echo Detecting languages and preparing - altering the tables ...
|
76
|
+
for lang in $(grep 'description xml:lang=' $xmlfile|sed s/@/_arobas_/g|cut -f 1 -d '>'|cut -f 2 -d "'"|sort|uniq);do echo "insert into languages values ('$lang') ;"|sqlite3 $sqlitedb;done
|
77
|
+
for lang in $(echo "select * from languages;" |sqlite3 $sqlitedb);do echo "alter table categories add desc_$lang ; alter table categories add name_$lang ; "|sqlite3 $sqlitedb;done
|
78
|
+
for lang in $(echo "select * from languages;" |sqlite3 $sqlitedb);do echo "alter table groups add desc_$lang ; alter table groups add name_$lang ; "|sqlite3 $sqlitedb;done
|
79
|
+
export aretableready='1'
|
80
|
+
fi
|
81
|
+
|
82
|
+
|
83
|
+
echo Processing now $xmlfile
|
84
|
+
|
85
|
+
echo Detecting categories and filling the tables ...
|
86
|
+
# categories/id
|
87
|
+
for id in $(xmlstarlet sel -t -m "//comps/category" -v id -n $xmlfile);do isindb=$(echo "select id from categories where id='$id';"|sqlite3 $sqlitedb ) ;test "$isindb" = "$id" || (echo "insert into categories (id) values ('$id');"|sqlite3 $sqlitedb);done
|
88
|
+
# categories/name
|
89
|
+
for id in $(xmlstarlet sel -t -m "//comps/category" -v id -n $xmlfile); do name=$(xmlstarlet sel -t -m "//comps/category[id='$id']" -v name $xmlfile);isindb=$(echo "select name from categories where id='$id';"|sqlite3 $sqlitedb ) ; test "$isindb" = "$name" || (echo "update categories set name='$name' where id='$id' ;"|sqlite3 $sqlitedb ); done
|
90
|
+
# categories/description
|
91
|
+
for id in $(xmlstarlet sel -t -m "//comps/category" -v id -n $xmlfile); do desc=$(xmlstarlet sel -t -m "//comps/category[id='$id']" -v description $xmlfile);echo "update categories set desc='$desc' where id='$id' ;"|sqlite3 $sqlitedb; done
|
92
|
+
# categories/display_order
|
93
|
+
for id in $(xmlstarlet sel -t -m "//comps/category" -v id -n $xmlfile); do display_order=$(xmlstarlet sel -t -m "//comps/category[id='$id']" -v display_order $xmlfile); isindb=$(echo "select display_order from categories where id='$id';"|sqlite3 $sqlitedb ) ; test "$isindb" = "$display_order" || (echo "update categories set display_order='$display_order' where id='$id' ;"|sqlite3 $sqlitedb); done
|
94
|
+
# categories/name_$lang
|
95
|
+
for lang in $(echo "select * from languages;" |sqlite3 $sqlitedb|sed s/_arobas_/@/g);do for id in $(xmlstarlet sel -t -m "//comps/category" -v id -n $xmlfile);do namelang=$(xmlstarlet sel -t -m "//comps/category[id='$id']" -v "name[@xml:lang='$lang']" $xmlfile); langsql=$(echo $lang|sed s/@/_arobas_/g) ; isindb=$(echo "select name_$langsql from categories where id='$id';"|sqlite3 $sqlitedb ) ; test "$isindb" = "$namelang" || (namelangsql=$(echo $namelang|sed s/"'"/"''"/g) ;echo "update categories set name_$langsql='$namelangsql' where id='$id';"|sqlite3 $sqlitedb) ; done ; done
|
96
|
+
# categories/description_$lang
|
97
|
+
for lang in $(echo "select * from languages;" |sqlite3 $sqlitedb|sed s/_arobas_/@/g);do for id in $(xmlstarlet sel -t -m "//comps/category" -v id -n $xmlfile);do desclang=$(xmlstarlet sel -t -m "//comps/category[id='$id']" -v "description[@xml:lang='$lang']" $xmlfile); langsql=$(echo $lang|sed s/@/_arobas_/g) ; isindb=$(echo "select desc_$langsql from categories where id='$id';"|sqlite3 $sqlitedb ) ; test "$isindb" = "$desclang" || (desclangsql=$(echo $desclang|sed s/"'"/"''"/g) ;echo "update categories set desc_$langsql='$desclangsql' where id='$id';"|sqlite3 $sqlitedb) ; done ; done
|
98
|
+
# categories/grouplist
|
99
|
+
for id in $(xmlstarlet sel -t -m "//comps/category" -v id -n $xmlfile); do for groupid in $(xmlstarlet sel -t -m "//comps/category[id='$id']" -v grouplist $xmlfile); do isindb=$(echo "select groupid from grouplist where category_id='$id' and groupid='$groupid';"|sqlite3 $sqlitedb ) ; test "$isindb" = "$groupid" || (echo "insert into grouplist (groupid, category_id) values ('$groupid','$id');"|sqlite3 $sqlitedb); done ; done
|
100
|
+
|
101
|
+
echo Detecting groups and filling the tables ...
|
102
|
+
# groups/id
|
103
|
+
for id in $(xmlstarlet sel -t -m "//comps/group" -v id -n $xmlfile);do isindb=$(echo "select id from groups where id='$id';"|sqlite3 $sqlitedb ) ;test "$isindb" = "$id" || (echo "insert into groups (id) values ('$id');"|sqlite3 $sqlitedb);done
|
104
|
+
# groups/name
|
105
|
+
for id in $(xmlstarlet sel -t -m "//comps/group" -v id -n $xmlfile); do name=$(xmlstarlet sel -t -m "//comps/group[id='$id']" -v name $xmlfile);isindb=$(echo "select name from groups where id='$id';"|sqlite3 $sqlitedb ) ; test "$isindb" = "$name" || (echo "update groups set name='$name' where id='$id' ;"|sqlite3 $sqlitedb ); done
|
106
|
+
# groups/default
|
107
|
+
for id in $(xmlstarlet sel -t -m "//comps/group" -v id -n $xmlfile); do def=$(xmlstarlet sel -t -m "//comps/group[id='$id']" -v default $xmlfile);isindb=$(echo "select def from groups where id='$id';"|sqlite3 $sqlitedb ) ; test "$isindb" = "$def" || (echo "update groups set def='$def' where id='$id' ;"|sqlite3 $sqlitedb ); done
|
108
|
+
# groups/description
|
109
|
+
for id in $(xmlstarlet sel -t -m "//comps/group" -v id -n $xmlfile); do desc=$(xmlstarlet sel -t -m "//comps/group[id='$id']" -v description $xmlfile);isindb=$(echo "select desc from groups where id='$id';"|sqlite3 $sqlitedb ) ; test "$isindb" = "$desc" || (descsql=$(echo $desc|sed s/"'"/"''"/g) ; echo "update groups set desc='$descsql' where id='$id' ;"|sqlite3 $sqlitedb ); done
|
110
|
+
# groups/uservisible
|
111
|
+
for id in $(xmlstarlet sel -t -m "//comps/group" -v id -n $xmlfile); do uservisible=$(xmlstarlet sel -t -m "//comps/group[id='$id']" -v uservisible $xmlfile);isindb=$(echo "select uservisible from groups where id='$id';"|sqlite3 $sqlitedb ) ; test "$isindb" = "$uservisible" || (echo "update groups set uservisible='$uservisible' where id='$id' ;"|sqlite3 $sqlitedb ); done
|
112
|
+
# groups/langonly
|
113
|
+
for id in $(xmlstarlet sel -t -m "//comps/group" -v id -n $xmlfile); do langonly=$(xmlstarlet sel -t -m "//comps/group[id='$id']" -v langonly $xmlfile);isindb=$(echo "select langonly from groups where id='$id';"|sqlite3 $sqlitedb ) ; test "$isindb" = "$langonly" || (echo "update groups set langonly='$langonly' where id='$id' ;"|sqlite3 $sqlitedb ); done
|
114
|
+
# groups/name_$lang
|
115
|
+
for lang in $(echo "select * from languages;" |sqlite3 $sqlitedb|sed s/_arobas_/@/g);do for id in $(xmlstarlet sel -t -m "//comps/group" -v id -n $xmlfile);do namelang=$(xmlstarlet sel -t -m "//comps/group[id='$id']" -v "name[@xml:lang='$lang']" $xmlfile); langsql=$(echo $lang|sed s/@/_arobas_/g) ; isindb=$(echo "select name_$langsql from groups where id='$id';"|sqlite3 $sqlitedb ) ; test "$isindb" = "$namelang" || (namelangsql=$(echo $namelang|sed s/"'"/"''"/g) ; echo "update groups set name_$langsql='$namelangsql' where id='$id';"|sqlite3 $sqlitedb) ; done ; done
|
116
|
+
# groups/desc_$lang
|
117
|
+
for lang in $(echo "select * from languages;" |sqlite3 $sqlitedb|sed s/_arobas_/@/g);do for id in $(xmlstarlet sel -t -m "//comps/group" -v id -n $xmlfile);do desclang=$(xmlstarlet sel -t -m "//comps/group[id='$id']" -v "description[@xml:lang='$lang']" $xmlfile); langsql=$(echo $lang|sed s/@/_arobas_/g) ; isindb=$(echo "select desc_$langsql from groups where id='$id';"|sqlite3 $sqlitedb ) ; test "$isindb" = "$desclang" || (desclangsql=$(echo $desclang|sed s/"'"/"''"/g) ; echo "update groups set desc_$langsql='$desclangsql' where id='$id';"|sqlite3 $sqlitedb) ; done ; done
|
118
|
+
# groups/packagelist
|
119
|
+
for id in $(xmlstarlet sel -t -m "//comps/group" -v id -n $xmlfile); do packagelist=$(xmlstarlet sel -t -m "//comps/group[id='$id']" -c packagelist $xmlfile);isindb=$(echo "select packagelist from groups where id='$id';"|sqlite3 $sqlitedb ) ; test "$isindb" = "$packagelist" || (echo "update groups set packagelist='$packagelist' where id='$id' ;"|sqlite3 $sqlitedb ); done
|
120
|
+
|
121
|
+
|
122
|
+
# Fixing some groups that are by default active but have to be deselected on a CentOS install
|
123
|
+
|
124
|
+
for groupid in ha ha-management load-balancer resilient-storage scalable-file-systems ;do
|
125
|
+
echo "update groups set def='false' where id='$groupid';"|sqlite3 $sqlitedb
|
126
|
+
done
|
127
|
+
|
128
|
+
|
129
|
+
#final done for the xmlfile loop
|
130
|
+
done
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
compsxmlout() {
|
135
|
+
echo Generating the $outputxml file ...
|
136
|
+
echo "<?xml version='1.0' encoding='UTF-8'?>" >$outputxml
|
137
|
+
echo "<!DOCTYPE comps PUBLIC \"-//CentOS//DTD Comps info//EN\" \"comps.dtd\">" >> $outputxml
|
138
|
+
echo "<comps>" >> $outputxml
|
139
|
+
|
140
|
+
#group
|
141
|
+
|
142
|
+
for id in $(echo "select id from groups;"|sqlite3 $sqlitedb);do
|
143
|
+
echo " <group>" >>$outputxml
|
144
|
+
|
145
|
+
echo " <id>$id</id>" >> $outputxml
|
146
|
+
|
147
|
+
name=$(echo "select name from groups where id='$id';"|sqlite3 $sqlitedb)
|
148
|
+
echo " <name>$name</name>" >> $outputxml
|
149
|
+
|
150
|
+
for lang in $(echo "select * from languages;" |sqlite3 $sqlitedb) ;do
|
151
|
+
namelang=$(echo "select name_$lang from groups where id='$id';"|sqlite3 $sqlitedb )
|
152
|
+
if [ -n "$namelang" ] ; then
|
153
|
+
langxml=$(echo $lang|sed s/_arobas_/@/g)
|
154
|
+
echo " <name xml:lang='$langxml'>$namelang</name>" >> $outputxml
|
155
|
+
fi
|
156
|
+
done
|
157
|
+
|
158
|
+
desc=$(echo "select desc from groups where id='$id';"|sqlite3 $sqlitedb)
|
159
|
+
if [ -n "$desc" ] ; then
|
160
|
+
echo " <description>$desc</description>" >> $outputxml
|
161
|
+
for lang in $(echo "select * from languages;" |sqlite3 $sqlitedb) ;do
|
162
|
+
desclang=$(echo "select desc_$lang from groups where id='$id';"|sqlite3 $sqlitedb )
|
163
|
+
if [ -n "$desclang" ] ; then
|
164
|
+
langxml=$(echo $lang|sed s/_arobas_/@/g)
|
165
|
+
echo " <description xml:lang='$langxml'>$desclang</description>" >> $outputxml
|
166
|
+
fi
|
167
|
+
done
|
168
|
+
else
|
169
|
+
echo " <description/>" >> $outputxml
|
170
|
+
fi
|
171
|
+
|
172
|
+
def=$(echo "select def from groups where id='$id';"|sqlite3 $sqlitedb)
|
173
|
+
echo " <default>$def</default>" >> $outputxml
|
174
|
+
|
175
|
+
uservisible=$(echo "select uservisible from groups where id='$id';"|sqlite3 $sqlitedb)
|
176
|
+
echo " <uservisible>$uservisible</uservisible>" >> $outputxml
|
177
|
+
|
178
|
+
langonly=$(echo "select langonly from groups where id='$id';"|sqlite3 $sqlitedb)
|
179
|
+
if [ -n "$langonly" ] ; then
|
180
|
+
echo " <langonly>$langonly</langonly>" >> $outputxml
|
181
|
+
fi
|
182
|
+
|
183
|
+
plist=$(echo "select packagelist from groups where id='$id';"|sqlite3 $sqlitedb )
|
184
|
+
echo " $plist" >>$outputxml
|
185
|
+
|
186
|
+
echo " </group>" >>$outputxml
|
187
|
+
done
|
188
|
+
|
189
|
+
#category
|
190
|
+
|
191
|
+
for id in $(echo "select id from categories;"|sqlite3 $sqlitedb);do
|
192
|
+
echo " <category>" >>$outputxml
|
193
|
+
|
194
|
+
echo " <id>$id</id>" >> $outputxml
|
195
|
+
|
196
|
+
name=$(echo "select name from categories where id='$id';"|sqlite3 $sqlitedb)
|
197
|
+
echo " <name>$name</name>" >> $outputxml
|
198
|
+
|
199
|
+
for lang in $(echo "select * from languages;" |sqlite3 $sqlitedb) ;do
|
200
|
+
namelang=$(echo "select name_$lang from categories where id='$id';"|sqlite3 $sqlitedb )
|
201
|
+
if [ -n "$namelang" ] ; then
|
202
|
+
langxml=$(echo $lang|sed s/_arobas_/@/g)
|
203
|
+
echo " <name xml:lang='$langxml'>$namelang</name>" >> $outputxml
|
204
|
+
fi
|
205
|
+
done
|
206
|
+
|
207
|
+
desc=$(echo "select desc from categories where id='$id';"|sqlite3 $sqlitedb)
|
208
|
+
echo " <description>$desc</description>" >> $outputxml
|
209
|
+
|
210
|
+
for lang in $(echo "select * from languages;" |sqlite3 $sqlitedb) ;do
|
211
|
+
desclang=$(echo "select desc_$lang from categories where id='$id';"|sqlite3 $sqlitedb )
|
212
|
+
if [ -n "$desclang" ] ; then
|
213
|
+
langxml=$(echo $lang|sed s/_arobas_/@/g)
|
214
|
+
echo " <description xml:lang='$langxml'>$desclang</description>" >> $outputxml
|
215
|
+
fi
|
216
|
+
done
|
217
|
+
|
218
|
+
echo " <grouplist>" >>$outputxml
|
219
|
+
for groupid in $(echo "select groupid from grouplist where category_id='$id';"|sqlite3 $sqlitedb) ; do
|
220
|
+
echo " <groupid>$groupid</groupid>" >>$outputxml
|
221
|
+
done
|
222
|
+
echo " </grouplist>" >>$outputxml
|
223
|
+
|
224
|
+
echo " </category>" >>$outputxml
|
225
|
+
|
226
|
+
done
|
227
|
+
echo "" >> $outputxml
|
228
|
+
echo "</comps>" >> $outputxml
|
229
|
+
|
230
|
+
# Now fixing some well-known branding issues (as the new comps.xml is still generated from upstream xml files)
|
231
|
+
sed -i s/"Red Hat Enterprise Linux"/"CentOS Linux"/g $outputxml
|
232
|
+
sed -i s/"redhat-indexhtml"/"centos-indexhtml"/g $outputxml
|
233
|
+
sed -i '/Red_Hat_Enterprise_Linux-Release_Notes/d' $outputxml
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
sqlitedb="/dev/shm/comps-$release-$arch.db"
|
240
|
+
outputxml="c$release-$arch-comps.xml"
|
241
|
+
|
242
|
+
|
243
|
+
# and now the real processing ...
|
244
|
+
varcheck $arch
|
245
|
+
varcheck $destdir
|
246
|
+
varcheck $release
|
247
|
+
|
248
|
+
for binary in sqlite3 xmlstarlet;do
|
249
|
+
which $binary > /dev/null 2>&1
|
250
|
+
if [ "$?" = "1" ] ;then
|
251
|
+
echo "Binary $binary not found ... exiting"
|
252
|
+
exit 1
|
253
|
+
fi
|
254
|
+
|
255
|
+
done
|
256
|
+
|
257
|
+
if [ -e $sqlitedb ] ;then
|
258
|
+
echo "$sqlitedb file already existing - not overwriting by default ..."
|
259
|
+
exit 1
|
260
|
+
fi
|
261
|
+
|
262
|
+
echo sqlite file = $sqlitedb
|
263
|
+
echo Generated comps xml file = $outputxml
|
264
|
+
|
265
|
+
time compsxmlin
|
266
|
+
time compsxmlout
|
267
|
+
|