1 | #!/bin/bash |
---|
2 | #Script that generates xml info file from a desktop file |
---|
3 | #Usage: |
---|
4 | #Download lliurex-artwork-default from svn |
---|
5 | #Download the sources of the package(s) |
---|
6 | #Execute this script adding the dirs of sources to analyze as parameters |
---|
7 | #Profit |
---|
8 | |
---|
9 | msg_need_svn="In order to add the right icons you need to download lliurex-artwork-default from svn to the same dir as the source packages" |
---|
10 | msg_dir_not_found="dir not found" |
---|
11 | msg_icons_dir_error="Can't access %s or %s.\nSome icons may be missing.\n" |
---|
12 | msg_select_file="Select one install file:\n" |
---|
13 | msg_selected_file="\nSelected file: %s\n\n" |
---|
14 | msg_select_dir="\nSelect the dir containing the desktop file:\n" |
---|
15 | msg_gen_metainfo="Generating metainfo data path\n" |
---|
16 | msg_parsing_desktop="Parsing %s\n" |
---|
17 | msg_metainfo_generated="\nMetainfo file generated.\n" |
---|
18 | msg_desktop_updated="\nDesktop file updated.\n" |
---|
19 | msg_icon_found="Icon %s found.\nGenerating llx-resources dir\n" |
---|
20 | msg_icon_not_found="\nNo icon named %s found on dirs %s, %s or %s\n" |
---|
21 | msg_icon_location_info="\nPlease add %s as svg to %s and relaunch this program or use the llxsrc debhelper. Until then the app will not be included in our software store.\n" |
---|
22 | msg_icon_exists="\nIcon package found on the right location. Assuming llxsrc helper exists in rules\n" |
---|
23 | msg_work_done="\n----------\n\nWork done. If the process has no errors please check that the appfile.xml is right and that the rules file has the llxsrc helper. Also check that the icon is present in llx-resources.\nIn other case correct the errors and relaunch the script.\n\nRemember that the generated appfile.xml isn't a full one and is missing some fields like the screenshots. Take a cup of coffee and fulfill the empty fields following the specs at https://www.freedesktop.org/software/appstream/docs/sect-Metadata-Application.html\n\n" |
---|
24 | msg_install_not_found="Install file not found in debian dir. Aborting.\n" |
---|
25 | msg_select_workdir="Select the workdir\n" |
---|
26 | msg_debhelper_enabled="package type llxsrc detected. Setting llx-resources as workdir\n" |
---|
27 | function usage_help |
---|
28 | { |
---|
29 | printf "Usage:\n" |
---|
30 | printf "$0 [svn_package_dir1] [svn_package_dir2]\n\n" |
---|
31 | printf "$msg_need_svn\n\n" |
---|
32 | exit 1 |
---|
33 | } |
---|
34 | |
---|
35 | function analyze_dir |
---|
36 | { |
---|
37 | printf "Analyzing $1\n" |
---|
38 | rootDir=$PWD |
---|
39 | svnDir=`dirname $1` |
---|
40 | pkgDir=$1 |
---|
41 | srcDir=${1}"/trunk/fuentes" |
---|
42 | debianDir=${1}"/trunk/fuentes/debian" |
---|
43 | |
---|
44 | lliurexArtworkDir=${svnDir}"/vibrancy-colors/trunk/fuentes/vibrancy-lliurex/apps" |
---|
45 | #vibrancyArtworkDir=${svnDir}"/vibrancy-colors/trunk/fuentes/vibrancy-colors/Vibrancy-Dark-Orange/apps/scalable" |
---|
46 | if [ ! -d $lliurexArtworkDir ] || [ ! -d $vibrancyArtworkDir ] |
---|
47 | then |
---|
48 | printf "$msg_icons_dir_error" $lliurexArtworkDir $vibrancyArtworkDir |
---|
49 | fi |
---|
50 | |
---|
51 | #Get the install file. If there're many choose one... |
---|
52 | cd $debianDir |
---|
53 | declare -a installFiles |
---|
54 | count=0 |
---|
55 | for i in *install |
---|
56 | do |
---|
57 | installFiles[$count]=$i |
---|
58 | let count++ |
---|
59 | done |
---|
60 | index=0 |
---|
61 | let count-- |
---|
62 | if [[ ${installFiles[0]} = '*install' ]] |
---|
63 | then |
---|
64 | printf "$msg_install_not_found" |
---|
65 | get_workdir |
---|
66 | debhelper_mode=1 |
---|
67 | else |
---|
68 | if [ $count -gt 0 ] |
---|
69 | then |
---|
70 | printf "$msg_select_file" |
---|
71 | for i in `seq 0 ${count}` |
---|
72 | do |
---|
73 | printf "${i}) ${installFiles[$i]}\n" |
---|
74 | done |
---|
75 | printf "Select file [0]: " |
---|
76 | read index |
---|
77 | [ -z $index ] && index=0 |
---|
78 | installFile=${installFiles[$index]} |
---|
79 | else |
---|
80 | installFile=${installFiles[0]} |
---|
81 | fi |
---|
82 | printf "$msg_selected_file" $installFile |
---|
83 | process_installFile ${installFile} |
---|
84 | fi |
---|
85 | } |
---|
86 | |
---|
87 | function get_workdir |
---|
88 | { |
---|
89 | cd $rootDir |
---|
90 | cd $srcDir |
---|
91 | if [ -d llx-resources ] |
---|
92 | then |
---|
93 | printf "$msg_debhelper_enabled" |
---|
94 | installDir="llx-resources" |
---|
95 | else |
---|
96 | printf "$msg_select_workdir" |
---|
97 | count=0 |
---|
98 | declare -a dirArray |
---|
99 | for directory in * |
---|
100 | do |
---|
101 | printf "${count}) $directory\n" |
---|
102 | dirArray[$count]=$directory |
---|
103 | let count++ |
---|
104 | done |
---|
105 | printf "Selected Dir [0]: " |
---|
106 | read index |
---|
107 | installDir=${dirArray[$index]} |
---|
108 | fi |
---|
109 | process_pkg $installDir |
---|
110 | } |
---|
111 | |
---|
112 | function process_installFile |
---|
113 | { |
---|
114 | installFile=$1 |
---|
115 | wc -l $installFile |
---|
116 | if [ `wc -l $installFile | cut -f1 -d ' '` -gt 1 ] |
---|
117 | then |
---|
118 | printf "$msg_select_dir" |
---|
119 | count=0 |
---|
120 | declare -a fileLines |
---|
121 | while read -r dirLine |
---|
122 | do |
---|
123 | fileLines[$count]=$dirLine |
---|
124 | printf "$count) $dirLine\n" |
---|
125 | let count++ |
---|
126 | done < ${installFile} |
---|
127 | printf "Selected file [0]: " |
---|
128 | read index |
---|
129 | installDir=${fileLines[$index]} |
---|
130 | else |
---|
131 | installDir=`head -n1 $installFile` |
---|
132 | fi |
---|
133 | [ -z $index ] && index=0 |
---|
134 | installDir=${installDir/\**/} |
---|
135 | process_pkg $installDir |
---|
136 | } |
---|
137 | |
---|
138 | function process_pkg |
---|
139 | { |
---|
140 | cd $rootDir"/"$srcDir |
---|
141 | wrkDir=$1 |
---|
142 | printf "Entering $wrkDir\n" |
---|
143 | if [ -d wrkDir ] |
---|
144 | then |
---|
145 | cd $wrkDir |
---|
146 | else |
---|
147 | wrkDir=`dirname $wrkDir` |
---|
148 | cd $wrkDir |
---|
149 | fi |
---|
150 | |
---|
151 | #Find the desktop file of the application |
---|
152 | desktopFiles=$(find . -name "*.desktop") |
---|
153 | printf "$msg_gen_metainfo" |
---|
154 | for desktopFile in $desktopFiles |
---|
155 | do |
---|
156 | cd $rootDir"/"$srcDir |
---|
157 | printf "Entering $wrkDir\n" |
---|
158 | cd $wrkDir |
---|
159 | #If workdir != $1 then it means that the install file has a file and not a dir |
---|
160 | #In this case we assume that the install is putting the desktop file so metainfoDir becames llx-resources directly |
---|
161 | if [[ $wrkDir != $1 ]] |
---|
162 | then |
---|
163 | appName=$(basename $pkgDir) |
---|
164 | metainfoDir=${rootDir}"/"${srcDir}"/llx-resources/"${appName} |
---|
165 | else |
---|
166 | metainfoDir=`dirname $desktopFile` |
---|
167 | metainfoDir=`dirname $metainfoDir` |
---|
168 | fi |
---|
169 | metainfoDir=$metainfoDir"/metainfo" |
---|
170 | mkdir $metainfoDir -p |
---|
171 | parse_desktop $metainfoDir $desktopFile |
---|
172 | iconName=$(grep ^Icon= $desktopFile) |
---|
173 | iconName=${iconName/*=/} |
---|
174 | iconName=${iconName/.*/} |
---|
175 | get_icon $iconName |
---|
176 | done |
---|
177 | } |
---|
178 | |
---|
179 | function parse_desktop |
---|
180 | { |
---|
181 | metainfoDir=$1 |
---|
182 | shift |
---|
183 | for desktopFile in $@ |
---|
184 | do |
---|
185 | printf "$msg_parsing_desktop" $desktopFile |
---|
186 | item=`basename $desktopFile` |
---|
187 | awk -v processFile=$item -v metainfoDir=$metainfoDir -F '=' ' |
---|
188 | BEGIN{ |
---|
189 | split(processFile,array,".",seps) |
---|
190 | # revDomainName="net.lliurex."array[1] |
---|
191 | outFile="/tmp/"processFile |
---|
192 | printf("") > outFile |
---|
193 | xmlFile=metainfoDir"/"array[1]".appdata.xml" |
---|
194 | print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > xmlFile |
---|
195 | print "<component type=\"desktop-application\">" >> xmlFile |
---|
196 | # print "<id>"revDomainName"</id>" >> xmlFile |
---|
197 | print "<id>"array[1]"</id>" >> xmlFile |
---|
198 | print "<metadata_license>CC0-1.0</metadata_license>" >> xmlFile |
---|
199 | execPrinted=0 |
---|
200 | commentArrayIndex=1 |
---|
201 | nameArrayIndex=1 |
---|
202 | } |
---|
203 | { |
---|
204 | if ($1~"^Name") |
---|
205 | { |
---|
206 | if ($1=="Name") |
---|
207 | { |
---|
208 | tagName="<name>" |
---|
209 | } else { |
---|
210 | lang=$1 |
---|
211 | split(lang,array,"[",seps) |
---|
212 | lang=substr(array[2], 1, length(array[2])-1) |
---|
213 | tagName="<name xml:lang=\""lang"\">" |
---|
214 | } |
---|
215 | tagName=tagName""$2"</name>" |
---|
216 | nameArray[nameArrayIndex]=tagName |
---|
217 | nameArrayIndex++; |
---|
218 | } else if ($1~"Comment") { |
---|
219 | if ($1=="Comment") |
---|
220 | { |
---|
221 | tagSum="<summary>" |
---|
222 | tagDes="<p>" |
---|
223 | } else { |
---|
224 | lang=$1 |
---|
225 | split(lang,array,"[",seps) |
---|
226 | lang=substr(array[2], 1, length(array[2])-1) |
---|
227 | tagSum="<summary xml:lang=\""lang"\">" |
---|
228 | tagDes="<p xml:lang=\""lang"\">" |
---|
229 | } |
---|
230 | sumario=$2 |
---|
231 | split(sumario,array,".",seps) |
---|
232 | $0=$1"="array[1] |
---|
233 | summaryArray[commentArrayIndex]=tagSum""array[1]"</summary>" |
---|
234 | descriptionArray[commentArrayIndex]=tagDes""sumario"</p>" |
---|
235 | commentArrayIndex++ |
---|
236 | } else if ($1=="Categories") { |
---|
237 | split($2,array,";",seps) |
---|
238 | for (catIndex in array) |
---|
239 | { |
---|
240 | if (array[catIndex]!="") |
---|
241 | { |
---|
242 | if (array[catIndex]~"LliureX-") |
---|
243 | { |
---|
244 | split(array[catIndex],lliurexCats,"-",seps) |
---|
245 | for (lliurexCatIndex in lliurexCats) |
---|
246 | { |
---|
247 | lliurexCat="<category>"lliurexCats[lliurexCatIndex]"</category>\n"lliurexCat |
---|
248 | } |
---|
249 | categoryArray[catIndex]=lliurexCat |
---|
250 | } else { |
---|
251 | categoryArray[catIndex]="<category>"array[catIndex]"</category>" |
---|
252 | } |
---|
253 | } |
---|
254 | } |
---|
255 | } else if ($1=="Icon") { |
---|
256 | arrayItemNames=split($2,array,"/",seps) |
---|
257 | arrayItems=split(array[arrayItemNames],array,".",seps) |
---|
258 | iconBaseName=array[1] |
---|
259 | $0=$1"="iconBaseName |
---|
260 | # split(iconBaseName,array,".",seps) |
---|
261 | tagIcon="<icon type=\"cached\">"iconBaseName"</icon>"; |
---|
262 | } else if ($1=="Exec") { |
---|
263 | if (execPrinted==0) |
---|
264 | { |
---|
265 | split($2,array," ",seps) |
---|
266 | tagExec="<provides><binary>"array[1]"</binary></provides>" |
---|
267 | execPrinted=1 |
---|
268 | } |
---|
269 | } |
---|
270 | print $0>>outFile |
---|
271 | } |
---|
272 | END{ |
---|
273 | for (nameIndex in nameArray) |
---|
274 | print nameArray[nameIndex] >> xmlFile |
---|
275 | for (summaryIndex in summaryArray) |
---|
276 | print summaryArray[summaryIndex] >> xmlFile; |
---|
277 | print "<description>" >> xmlFile |
---|
278 | for (descriptionIndex in descriptionArray) |
---|
279 | print descriptionArray[descriptionIndex] >> xmlFile; |
---|
280 | print "</description>" >> xmlFile |
---|
281 | print "<categories>" >> xmlFile |
---|
282 | for (categoryIndex in categoryArray) |
---|
283 | print categoryArray[categoryIndex] >> xmlFile; |
---|
284 | print "</categories>" >> xmlFile |
---|
285 | print tagIcon >> xmlFile |
---|
286 | print tagExec >> xmlFile |
---|
287 | print "<developer_name>Lliurex Team</developer_name>" >> xmlFile |
---|
288 | print "</component>" >> xmlFile |
---|
289 | } |
---|
290 | ' $desktopFile |
---|
291 | printf "$msg_metainfo_generated" |
---|
292 | cp /tmp/${item} $desktopFile |
---|
293 | printf "$msg_desktop_updated" |
---|
294 | done |
---|
295 | } |
---|
296 | |
---|
297 | function get_icon |
---|
298 | { |
---|
299 | iconName=$1 |
---|
300 | #Check if a svg icon exists |
---|
301 | workDir=$PWD |
---|
302 | printf "\nSearching for icon ${iconName}.svg in our package\n" |
---|
303 | #First we'll check the dir for resources |
---|
304 | resourcesDir=llx-resources/ |
---|
305 | cd $rootDir |
---|
306 | cd $srcDir |
---|
307 | iconFile=$(find ${resourcesDir} -name "$iconName.svg" | grep icons) |
---|
308 | if [[ ! $iconFile ]] |
---|
309 | then |
---|
310 | cd $workDir |
---|
311 | printf "Entering $workDir\n" |
---|
312 | iconPath=${srcDir}"/"${installDir} |
---|
313 | iconFile=$(find . -name "$iconName.svg") |
---|
314 | if [[ ! $iconFile ]] |
---|
315 | then |
---|
316 | printf "Accesing $lliurexArtworkDir\n" |
---|
317 | #Look for the svg in lliurex-theme |
---|
318 | cd $rootDir |
---|
319 | iconPath=$lliurexArtworkDir |
---|
320 | cd $lliurexArtworkDir |
---|
321 | iconFile=$(find . -name "${iconName}.svg") |
---|
322 | fi |
---|
323 | if [[ $iconFile ]] |
---|
324 | then |
---|
325 | cd $rootDir |
---|
326 | printf "$msg_icon_found" $iconFile |
---|
327 | cd $srcDir |
---|
328 | appName=$(basename $pkgDir) |
---|
329 | resourcesDir="llx-resources/"${appName}"/icons/apps/" |
---|
330 | mkdir $resourcesDir -p |
---|
331 | cd $OLDPWD |
---|
332 | cp ${iconPath}"/"${iconFile} ${srcDir}"/"${resourcesDir} |
---|
333 | cd $OLDPWD |
---|
334 | add_llxsrc_helper |
---|
335 | else |
---|
336 | printf "$msg_icon_not_found" ${iconName} $lliurexArtworkDir $resourcesDir $installDir |
---|
337 | printf "$msg_icon_location_info" ${iconName} $lliurexArtworkDir |
---|
338 | fi |
---|
339 | else |
---|
340 | printf "$msg_icon_exists" |
---|
341 | fi |
---|
342 | } |
---|
343 | |
---|
344 | function add_llxsrc_helper |
---|
345 | { |
---|
346 | cd $rootDir |
---|
347 | cd $debianDir |
---|
348 | printf "Adding llxsrc to rules" |
---|
349 | if [[ ! `grep 'llxsrc' rules` ]] |
---|
350 | then |
---|
351 | if [[ `grep '\-\-with' rules` ]] |
---|
352 | then |
---|
353 | sed -i 's/\(dh $@\ --with\ \)/\0llxsrc,/' rules |
---|
354 | else |
---|
355 | sed -i 's/\(dh $@\ \)/\0 --with\ llxsrc\ /' rules |
---|
356 | fi |
---|
357 | fi |
---|
358 | } |
---|
359 | |
---|
360 | |
---|
361 | [[ $@ ]] || usage_help |
---|
362 | |
---|
363 | for parm in $@ |
---|
364 | do |
---|
365 | if [ ! -d $parm ] |
---|
366 | then |
---|
367 | printf "\n${parm}: $msg_dir_not_found\n" |
---|
368 | usage_help |
---|
369 | exit 1 |
---|
370 | fi |
---|
371 | done |
---|
372 | |
---|
373 | for parm in $@ |
---|
374 | do |
---|
375 | debhelper_mode=0 |
---|
376 | analyze_dir $parm |
---|
377 | done |
---|
378 | |
---|
379 | printf "$msg_work_done" |
---|
380 | |
---|
381 | exit 0 |
---|
382 | |
---|