Debian Codegraph @

bin/fvwm-crystal.generate-menu

raw
1 #!/bin/bash
2 #
3 # Generate FVWM-Crystal menu from desktop and icons files provided by the applications.
4 #
5 # Author: Dominique Michel <[email protected]>, 2007-2014
6 #
7 # Provided as it without any garanty of any kind.
8 # Released under the GPL version 3+ license.
9 #
10 # Usage:
11 # fvwm-crystal.generate-menu : will search for all the desktop files in the system and
12 # generate the corresponding entries and icons if they don't already exist. Make asumption
13 # based on the install Prefix to find the existing FVWM-Crystal files.
14 #
15 # fvwm-crystal.generate-menu <name> : will search only for <name>.desktop and
16 # generate the corresponding entry and icons if they don't already exist.
17 #
18 # When running this script as user, the files will be generated in FVWM_USERDIR,
19 # as root, in FVWM_SYSTEMDIR
20 #
21 # Syntax from fvwm-crystal:
22 # fvwm-crystal.generate-menu $[FVWM_SYSTEMDIR] $[FVWM_USERDIR]
23 #
24 # For a detailled view of the algorhythm, open generate_menu.png in your favorite
25 # picture viewer.
26 #
27 # # # # # # # # # # # # # # # # # # # # # # # # # # #
28
29 # Your real id
30 your_id="$(id -un)"
31
32 # If run from a shell
33 if [ $# -lt 2 ]; then
34 echo "Running $0 from the shell"
35 # Where are the Fvwm-Crystal menu files:
36 FC_MENUBASEROOT="/usr/share/fvwm-crystal/fvwm/Applications"
37 FC_MENUBASEUSER="/.fvwm-crystal/Applications"
38 # Where are the Fvwm-Crystal icons files:
39 FC_ICONBASEROOT="/usr/share/fvwm-crystal/fvwm/icons/Default"
40 FC_ICONBASEUSER="/.fvwm-crystal/icons/Default"
41 # Test which user run the script. Ir root, install in FVWM-SYSTEMDIR,
42 # otherwise in FVWM_USERDIR. If ROOT, existing entry will be searched
43 # only in FVWM_SYSTEMDIR, otherwise in both FVWM_DIR.
44 if [[ "${your_id}" == root ]]; then
45 FC_MENUBASE="${FC_MENUBASEROOT}"
46 FC_ICONBASE="${FC_ICONBASEROOT}"
47 FC_MENUEXIST="${FC_MENUBASEROOT}"
48 FC_ICONEXIST="${FC_ICONBASEROOT}"
49 else
50 FC_MENUBASE="/home/${your_id}${FC_MENUBASEUSER}"
51 FC_ICONBASE="/home/${your_id}${FC_ICONBASEUSER}"
52 FC_MENUEXIST="${FC_MENUBASEROOT} /home/${your_id}${FC_MENUBASEUSER}"
53 FC_ICONEXIST="${FC_ICONBASEROOT} /home/${your_id}${FC_ICONBASEUSER}"
54 fi
55 else
56 FC_MENUBASEROOT="$1/Applications"
57 FC_ICONBASEROOT="$1/icons/Default"
58 FC_MENUBASE="$2/Applications"
59 FC_ICONBASE="$2/icons/Default"
60 FC_MENUEXIST="${FC_MENUBASEROOT} ${FC_MENUBASE}"
61 FC_ICONEXIST="${FC_ICONBASEROOT} ${FC_ICONBASE}"
62 fi
63 SIZES="22x22 32x32 48x48"
64
65 #
66 #
67 # # # # # # # # # # # # # # # # # # # # # # # # # # #
68 # Don't change anything past this line
69 # # # # # # # # # # # # # # # # # # # # # # # # # # #
70
71 # The locale in use
72 LOC="$(echo $LANG|cut -d "_" -f 1)"
73 case "$LOC" in
74 en)
75 LOC=""
76 echo "Using English"
77 ;;
78 C)
79 LOC=""
80 echo "Using English"
81 ;;
82 POSIX)
83 LOC=""
84 echo "Using English"
85 ;;
86 *)
87 echo "Using $LOC"
88 ;;
89 esac
90
91 # Type of .desktop files to search for
92 DESKTYPE="Type=Application"
93
94 # Where are the preferences:
95 if [ $# -lt 2 ]; then
96 SYSPREFS="/usr/share/fvwm-crystal/fvwm/preferences"
97 USERPREFS="/home/$your_id/.fvwm-crystal/preferences"
98 else
99 SYSPREFS="$1/preferences"
100 USERPREFS="$2/preferences"
101 fi
102
103 loadpref() {
104 # Copy default user prefs if they don't exist.
105 if [ ! -e $USERPREFS/$1 ]; then
106 cp $SYSPREFS/$1 $USERPREFS
107 fi
108
109 eval "$2=\"$(cat $USERPREFS/$1|grep -Ev ^#)\""
110 }
111
112 # Load the icon files preference:
113 loadpref IconDirs SYSTEM_ICONDIRS
114 # Load the desktop files preference:
115 loadpref DesktopDirs DesktopDir
116
117 # Info screen
118 echo "You are running $0 as user ${your_id}."
119 echo " "
120 echo "FVWM-Crystal menu entries will be installed in"
121 echo "$FC_MENUBASE and the icons in $FC_ICONBASE."
122 echo " "
123 echo "The program will search for existing menu entries in $FC_MENUEXIST and for existing"
124 echo " icons in $FC_ICONEXIST."
125 echo "It will look for desktop file into $DesktopDir and for original icons into $SYSTEM_ICONDIRS"
126 echo " "
127 echo "Installing the menu entrie in $FC_MENUBASE and the icons in $FC_ICONBASE"
128
129 # Parameter test
130 if [ $# -lt 2 ]; then
131 if [[ $1 == "" ]]; then
132 echo "- Searching for all the desktop files in $DesktopDir"
133 echo ""
134 echo "This will go fast..."
135 searchdesktop="searchallappdesktop"
136 else
137 echo "- Searching for $1.desktop in $DesktopDir"
138 searchdesktop="searchoneappdesktop"
139 fi
140 else
141 searchdesktop="searchallappdesktop"
142 fi
143
144 # Remove the temp files if the user press Ctrl-C
145 USER_INTERRUPT=13
146 trap 'rm -f filelist filelist1; exit $USER_INTERRUPT' TERM INT
147
148 # # # # # # # # # # # # # # # # # # # # # # # # # # #
149 # Some functions
150
151 # Create icons
152 # createicon <commandname> <iconfile>
153 createicon() {
154 RETVAL="no"; for j in ${FC_ICONEXIST}; do
155 if [[ ! -z "`find ${j}/22x22 -name "$1.png"`" ]] && [[ ! -z "`find ${j}/32x32 -name "$1.png"`" ]] && [[ ! -z "`find ${j}/48x48 -name "$1.png"`" ]] ; then
156 # icons found
157 RETVAL="yes"
158 fi; done
159 if [[ $RETVAL == "yes" ]]; then
160 # fvwm-crystal icon exists, nothing to do (1)
161 echo "Icon for $1 exist, skip"
162 else
163 if [[ "$2" != "$1" ]]; then
164 # use file hint pointed to by menu entry
165 # test if file don't exist
166 if [ ! -e "$2" ]; then
167 ICONSRCFILE=`find $SYSTEM_ICONDIRS -type f -iname "$2"`
168 else
169 ICONSRCFILE="$2"
170 fi
171 if [ -z "$ICONSRCFILE" ]; then
172 ICONSRCFILE=`find $SYSTEM_ICONDIRS -type f -iname "$2.png" -or -iname "$2.xpm" -or -iname "$2.ico" -or -iname "svg" -or -iname "$2.bmp" -or -iname "$2.gif" -or -iname "$2.jpg" -or -iname "$2.pcx" -or -iname "$2.ppm" -or -iname "$2.tga"`
173 fi
174 else
175 # try to find a suitable icon in the system directories
176 ICONSRCFILE=`find $SYSTEM_ICONDIRS -type f -iname "$1.png" -or -iname "$1.xpm" -or -iname "$1.ico" -or -iname "$1.svg" -or -iname "$2.bmp" -or -iname "$2.gif" -or -iname "$2.jpg" -or -iname "$2.pcx" -or -iname "$2.ppm" -or -iname "$2.tga"`
177 fi
178
179 if [[ "$ICONSRCFILE" != "" ]]; then
180 for i in $ICONSRCFILE; do
181 # convert the first found file to png of required sizes
182 for size in ${SIZES}; do
183 mkdir -p "${FC_ICONBASE}/${size}/apps"
184 convert -resize ${size} "$i" "${FC_ICONBASE}/${size}/apps/$1.png"
185 # if an icon file contain several pictures, several files are generated. Use the first one.
186 if [ -e "${FC_ICONBASE}/${size}/apps/$1-0.png" ]; then
187 mv "${FC_ICONBASE}/${size}/apps/$1-0.png" "${FC_ICONBASE}/${size}/apps/$1.png"
188 fi
189
190 # fix the gAMA value; this remove warninngs and spped up fvwm
191 # fix the sRGB profile; this remove warninngs and spped up fvwm
192 convert "${FC_ICONBASE}/${size}/apps/$1.png" -strip -resize ${size} "${FC_ICONBASE}/${size}/apps/$1.png"
193 convert "${FC_ICONBASE}/${size}/apps/$1.png" -resize ${size} "${FC_ICONBASE}/${size}/apps/$1.png"
194 convert "${FC_ICONBASE}/${size}/apps/$1.png" -resize ${size} "${FC_ICONBASE}/${size}/apps/$1.png"
195 echo "Icon for $1 created as ${FC_ICONBASE}/${size}/apps/$1.png"
196 done
197 break
198 done
199 else
200 echo "Original icon for $1 don't exist, skip."
201 fi
202 fi
203 }
204
205 # Search desktop files new format
206 echo -n "" > filelist
207 # Search for application type desktop file
208 searchallappdesktop() {
209 echo -n "" > filelist1
210 DesktopFile="$(find ${DesktopDir} -iname ?*.desktop -type f)"
211 echo "$DesktopFile" >> filelist1
212 echo "Sorting out non application type desktop files."
213 echo "This will take a while..."
214 while read myline ; do
215 if [[ -n "${myline}" ]]; then
216 TestDeskType="$(grep -h '\<Type\>' "${myline}")"
217 OnlyShowIn="$(grep -h '\<OnlyShowIn\>' "${myline}")"
218 NotShowIn="$(grep -h '\<NotShowIn\>' "${myline}")"
219 NoDisplay="$(grep -h '\<NoDisplay\>' "${myline}")"
220 Hidden="$(grep -h '\<Hidden\>' "${myline}")"
221 if [[ "${TestDeskType}" == "${DESKTYPE}" ]] && [[ "${OnlyShowIn}" == "" ]] && [[ "${NotShowIn}" == "" ]] && [[ "${NoDisplay}" == "" ]] && [[ "${Hidden}" == "" ]]; then
222 echo "${myline}" >> filelist
223 fi
224 fi
225 done < filelist1
226 rm filelist1
227 }
228
229 searchoneappdesktop() {
230 echo -n "" > filelist1
231 DesktopFile="$(find ${DesktopDir} -iname $1.desktop -type f)"
232 echo "$DesktopFile" >> filelist1
233
234 while read myline ; do
235 if [[ -n "${myline}" ]]; then
236 TestDeskType="$(grep -h '\<Type\>' "${myline}")"
237 OnlyShowIn="$(grep -h '\<OnlyShowIn\>' "${myline}")"
238 NotShowIn="$(grep -h '\<NotShowIn\>' "${myline}")"
239 NoDisplay="$(grep -h '\<NoDisplay\>' "${myline}")"
240 Hidden="$(grep -h '\<Hidden\>' "${myline}")"
241 if [[ "${TestDeskType}" == "${DESKTYPE}" ]] && [[ "${OnlyShowIn}" == "" ]] && [[ "${NotShowIn}" == "" ]] && [[ "${NoDisplay}" == "" ]] && [[ "${Hidden}" == "" ]]; then
242 echo "${myline}" >> filelist
243 fi
244 fi
245 break
246 done < filelist1
247 rm filelist1
248 }
249
250 # Search TryExec in desktop file, Exec if not found
251 searchexecname() {
252 EXEC="$(cat ${1} | sed -e '/Desktop Entry/,/Desktop Action/ !d' -e '/^\Exec=/!d' -e 's:^.\{0,3\}Exec=\([^ ]*\).*:\1:' -e 's:.*/::')"
253 export EXEC
254 }
255
256 # Search for icon name in desktop file
257 searchiconname() {
258 ICONNAME="$(cat ${1} | sed -e '/Icon=/!d' -e 's/Icon=//')"
259 export ICONNAME
260 }
261
262 # Search for key strings in desktop file
263 searchkeystrings() {
264 CATNAME="$(cat ${1} | sed -e '/Desktop Entry/,/Desktop Action/ !d' -e '/Categories=/!d' -e 's/Categories=//' -e 's/;/ /g')"
265 export CATNAME
266 # echo "CATNAME = $CATNAME"
267 SOFTNAME=""
268 if [[ "$LOC" != "" ]]; then
269 SOFTNAME="$(cat ${1} | grep -m 1 ^Name.${LOC}. | sed -e '/^\Name....=/!d' -e 's/Name....=//' -e 's/ /_/g' -e 's:/:-:')"
270 export SOFTNAME
271 # else
272 fi
273 if [[ "$SOFTNAME" == "" ]]; then
274 SOFTNAME="$(cat ${1} | sed -e '/Desktop Entry/,/Desktop Action/ !d' -e '/^\Name=/!d' -e 's/Name=//' -e 's/ /_/g' -e 's:/:-:')"
275 export SOFTNAME
276 fi
277
278 COMMANDF="$(cat ${1} | sed -e '/Desktop Entry/,/Desktop Action/ !d' -e '/^\Exec=/!d' -e 's/Exec=//' -e 's:.%.*::' -e 's/ -caption//')"
279 export COMMANDF
280
281 TERMINAL="$(cat ${1} | sed -e '/Terminal=true/!d' -e 's/Terminal=//')"
282 export TERMINAL
283 }
284
285 # Search for existing menu entry
286 searchexist() {
287 EntryExist="$(find ${FC_MENUEXIST} -iname *${2}~?* -type f)"
288 if [[ "${EntryExist}" != "" ]]; then
289 echo "${EntryExist} exist, skip"
290 EXIST="true"
291 export EXIST
292 createicon $EXEC $ICONNAME
293 else
294 echo "${EntryExist} dont exist"
295 EXIST="false"
296 export EXIST
297 createicon $EXEC $ICONNAME
298 fi
299 }
300
301 # Generate the category path for the menu
302 # 1) search for main category
303 # 2) search for sub-category
304 # special cases: if both audio and audiovideo are in the desktop file,
305 # audio will be preferred; if both audiovideo are in the desktop file,
306 # video will be preferred.
307 #
308 # main categories
309 maincategory() {
310 MAINCAT=""
311 export MAINCAT
312 case "$1" in
313 Audio)
314 MAINCAT="/Multimedia/Audio"
315 export MAINCAT
316 ;;
317 AudioVideo | Multimedia)
318 MAINCAT="/Multimedia/Audio-Video"
319 export MAINCAT
320 ;;
321 Development)
322 MAINCAT="/Development"
323 export MAINCAT
324 ;;
325 Education)
326 MAINCAT="/Knowledge"
327 export MAINCAT
328 ;;
329 Games | Game)
330 MAINCAT="/20~Games"
331 export MAINCAT
332 ;;
333 Graphics)
334 MAINCAT="/Graphics"
335 export MAINCAT
336 ;;
337 Internet | Network)
338 MAINCAT="/Network"
339 export MAINCAT
340 ;;
341 Office)
342 MAINCAT="/Office"
343 export MAINCAT
344 ;;
345 Settings)
346 MAINCAT="/Settings"
347 export MAINCAT
348 ;;
349 System)
350 MAINCAT="/System"
351 export MAINCAT
352 ;;
353 Utilities | Utility)
354 MAINCAT="/Utilities"
355 export MAINCAT
356 ;;
357 Video)
358 MAINCAT="/Multimedia/Video"
359 export MAINCAT
360 ;;
361 # *)
362 # MAINCAT="/Utilities"
363 # export MAINCAT
364 # ;;
365 esac
366 }
367 # sub categories
368 category() {
369 SUBCAT=""
370 export SUBCAT
371 case "$1" in
372 2DGraphics)
373 SUBCAT="/2D_Graphics"
374 export SUBCAT
375 ;;
376 3DGraphics)
377 SUBCAT="/3D_Graphics"
378 export SUBCAT
379 ;;
380 Accessibility)
381 SUBCAT="/Accessibility"
382 export SUBCAT
383 ;;
384 ActionGame)
385 SUBCAT="/20~Action_Games"
386 export SUBCAT
387 ;;
388 AdventureGame)
389 SUBCAT="/Adventure_Games"
390 export SUBCAT
391 ;;
392 Adult)
393 SUBCAT="/Adult"
394 export SUBCAT
395 ;;
396 ArcadeGame)
397 SUBCAT="/Arcade_Games"
398 export SUBCAT
399 ;;
400 Amusement)
401 SUBCAT="/Amusement"
402 export SUBCAT
403 ;;
404 Archiving)
405 SUBCAT="/Archiving"
406 export SUBCAT
407 ;;
408 Art)
409 SUBCAT="/Art"
410 export SUBCAT
411 ;;
412 ArtificialIntelligence)
413 SUBCAT="/Artificial_Intelligence"
414 export SUBCAT
415 ;;
416 Astronomy)
417 SUBCAT="/Astronomy"
418 export SUBCAT
419 ;;
420 AudioVideoEditing)
421 SUBCAT="/Audio-Video_Editing"
422 export SUBCAT
423 ;;
424 Biology)
425 SUBCAT="/Biology"
426 export SUBCAT
427 ;;
428 BlocksGame)
429 SUBCAT="/20~Blocks_Games"
430 export SUBCAT
431 ;;
432 BoardGame)
433 SUBCAT="/Board_Games"
434 export SUBCAT
435 ;;
436 Building)
437 SUBCAT="/Building"
438 export SUBCAT
439 ;;
440 Calculator)
441 SUBCAT="/Calculators"
442 export SUBCAT
443 ;;
444 Calendar)
445 SUBCAT="/Calendars"
446 export SUBCAT
447 ;;
448 CardGame)
449 SUBCAT="/Card_Games"
450 export SUBCAT
451 ;;
452 Chart)
453 SUBCAT="/Charts"
454 export SUBCAT
455 ;;
456 Chat)
457 SUBCAT="/Chat"
458 export SUBCAT
459 ;;
460 Chemistry)
461 SUBCAT="/Chemistry"
462 export SUBCAT
463 ;;
464 Clock)
465 SUBCAT="/Clocks"
466 export SUBCAT
467 ;;
468 Compression)
469 SUBCAT="/Compression"
470 export SUBCAT
471 ;;
472 ComputerScience)
473 SUBCAT="/Computer_Science"
474 export SUBCAT
475 ;;
476 ConsoleOnly)
477 SUBCAT="/Console_Only"
478 export SUBCAT
479 ;;
480 Construction)
481 SUBCAT="/Construction"
482 export SUBCAT
483 ;;
484 ContactManagement)
485 SUBCAT="/Contact_Management"
486 export SUBCAT
487 ;;
488 Core)
489 SUBCAT="/Core"
490 export SUBCAT
491 ;;
492 DataVisualization)
493 SUBCAT="/Data_Visualization"
494 export SUBCAT
495 ;;
496 Database)
497 SUBCAT="/Databases"
498 export SUBCAT
499 ;;
500 Dialup)
501 SUBCAT="/Dial-up"
502 export SUBCAT
503 ;;
504 Debugger)
505 SUBCAT="/Debuggers"
506 export SUBCAT
507 ;;
508 DesktopSettings)
509 SUBCAT="/Desktop_Settings"
510 export SUBCAT
511 ;;
512 Dialup)
513 SUBCAT="/Dialup"
514 export SUBCAT
515 ;;
516 Dictionary)
517 SUBCAT="/Dictionaries"
518 export SUBCAT
519 ;;
520 DiscBurning)
521 SUBCAT="/Disc_Burning"
522 export SUBCAT
523 ;;
524 Documentation)
525 SUBCAT="/Documentation"
526 export SUBCAT
527 ;;
528 Economy)
529 SUBCAT="/Economy"
530 export SUBCAT
531 ;;
532 Electricity)
533 SUBCAT="/Electricity"
534 export SUBCAT
535 ;;
536 Electronics)
537 SUBCAT="/Electronics"
538 export SUBCAT
539 ;;
540 Email)
541 SUBCAT="/13~Email"
542 export SUBCAT
543 ;;
544 Emulator)
545 SUBCAT="/Emulators"
546 export SUBCAT
547 ;;
548 Engineering)
549 SUBCAT="/Engineering"
550 export SUBCAT
551 ;;
552 Feed)
553 SUBCAT="/Feed"
554 export SUBCAT
555 ;;
556 FileManager)
557 SUBCAT="/File_Managers"
558 export SUBCAT
559 ;;
560 FileSystem)
561 SUBCAT="/File_Systems"
562 export SUBCAT
563 ;;
564 FileTools)
565 SUBCAT="/File_Tools"
566 export SUBCAT
567 ;;
568 FileTransfer)
569 SUBCAT="/File_Transfer"
570 export SUBCAT
571 ;;
572 Finance)
573 SUBCAT="/Finance"
574 export SUBCAT
575 ;;
576 FlowChart)
577 SUBCAT="/Flow_Charts"
578 export SUBCAT
579 ;;
580 Geography)
581 SUBCAT="/Geography"
582 export SUBCAT
583 ;;
584 Geology)
585 SUBCAT="/Geology"
586 export SUBCAT
587 ;;
588 Geoscience)
589 SUBCAT="/Geoscience"
590 export SUBCAT
591 ;;
592 GNOME)
593 SUBCAT=""
594 export SUBCAT
595 ;;
596 GTK)
597 SUBCAT=""
598 export SUBCAT
599 ;;
600 GUIDesigner)
601 SUBCAT="/GUI_Designers"
602 export SUBCAT
603 ;;
604 HamRadio)
605 SUBCAT="/Ham_Radio"
606 export SUBCAT
607 ;;
608 HardwareSettings)
609 SUBCAT="/Hardware_Settings"
610 export SUBCAT
611 ;;
612 History)
613 SUBCAT="/History"
614 export SUBCAT
615 ;;
616 Humanities)
617 SUBCAT="/Humanities"
618 export SUBCAT
619 ;;
620 IDE)
621 SUBCAT="/IDE"
622 export SUBCAT
623 ;;
624 ImageProcessing)
625 SUBCAT="/Image_Processing"
626 export SUBCAT
627 ;;
628 IRCClient)
629 SUBCAT="/IRC_Clients"
630 export SUBCAT
631 ;;
632 InstantMessaging)
633 SUBCAT="/Instant_Messaging"
634 export SUBCAT
635 ;;
636 Java)
637 SUBCAT="/Java"
638 export SUBCAT
639 ;;
640 KDE)
641 SUBCAT=""
642 export SUBCAT
643 ;;
644 KDE-settins-hardware)
645 SUBCAT=""
646 export SUBCAT
647 ;;
648 KidsGame)
649 SUBCAT="/Kids_Games"
650 export SUBCAT
651 ;;
652 Languages)
653 SUBCAT="/Languages"
654 export SUBCAT
655 ;;
656 Literature)
657 SUBCAT="/Literature"
658 export SUBCAT
659 ;;
660 LogicGame)
661 SUBCAT="/Logic_Games"
662 export SUBCAT
663 ;;
664 Maps)
665 SUBCAT="/Maps"
666 export SUBCAT
667 ;;
668 Math)
669 SUBCAT="/Math"
670 export SUBCAT
671 ;;
672 MedicalSoftware)
673 SUBCAT="/Medical_Softwares"
674 export SUBCAT
675 ;;
676 Midi)
677 SUBCAT="/MIDI"
678 export SUBCAT
679 ;;
680 Mixer)
681 SUBCAT="/10~Mixers"
682 export SUBCAT
683 ;;
684 Monitor)
685 SUBCAT="/Monitors"
686 export SUBCAT
687 ;;
688 Motif)
689 SUBCAT="/Motif"
690 export SUBCAT
691 ;;
692 Music)
693 SUBCAT="/Music"
694 export SUBCAT
695 ;;
696 News)
697 SUBCAT="/7~News"
698 export SUBCAT
699 ;;
700 NumericalAnalysis)
701 SUBCAT="/Numerical_Analysis"
702 export SUBCAT
703 ;;
704 OCR)
705 SUBCAT="/OCR"
706 export SUBCAT
707 ;;
708 P2P)
709 SUBCAT="/P2P"
710 export SUBCAT
711 ;;
712 PackageManager)
713 SUBCAT="/Package_Managers"
714 export SUBCAT
715 ;;
716 ParallelComputing)
717 SUBCAT="/Parallel_Computing"
718 export SUBCAT
719 ;;
720 PDA)
721 SUBCAT="/PDA"
722 export SUBCAT
723 ;;
724 Photography)
725 SUBCAT="/Photography"
726 export SUBCAT
727 ;;
728 Physics)
729 SUBCAT="/Physics"
730 export SUBCAT
731 ;;
732 Player)
733 SUBCAT="/Players"
734 export SUBCAT
735 ;;
736 Presentation)
737 SUBCAT="/Presentations"
738 export SUBCAT
739 ;;
740 Printing)
741 SUBCAT="/Printing"
742 export SUBCAT
743 ;;
744 Profiling)
745 SUBCAT="/Profiling"
746 export SUBCAT
747 ;;
748 ProjectManagement)
749 SUBCAT="/Project_Management"
750 export SUBCAT
751 ;;
752 Publishing)
753 SUBCAT="/Publishing"
754 export SUBCAT
755 ;;
756 QT)
757 SUBCAT=""
758 export SUBCAT
759 ;;
760 RasterGraphics)
761 SUBCAT="/Raster_Graphics"
762 export SUBCAT
763 ;;
764 Recorder)
765 SUBCAT="/Recorders"
766 export SUBCAT
767 ;;
768 RemoteAccess)
769 SUBCAT="/Remote_Access"
770 export SUBCAT
771 ;;
772 RevisionControl)
773 SUBCAT="/Revision_Control"
774 export SUBCAT
775 ;;
776 Robotics)
777 SUBCAT="/Robotics"
778 export SUBCAT
779 ;;
780 RolePlaying)
781 SUBCAT="/Role_Playing"
782 export SUBCAT
783 ;;
784 Scanning)
785 SUBCAT="/Scanning"
786 export SUBCAT
787 ;;
788 Science)
789 SUBCAT="/Science"
790 export SUBCAT
791 ;;
792 Security)
793 SUBCAT="/Security"
794 export SUBCAT
795 ;;
796 Sequencer)
797 SUBCAT="/Sequencers"
798 export SUBCAT
799 ;;
800 Shooter)
801 SUBCAT="/Shooter"
802 export SUBCAT
803 ;;
804 Simulation)
805 SUBCAT="/Simulation"
806 export SUBCAT
807 ;;
808 Spirituality)
809 SUBCAT="/Spirituality"
810 export SUBCAT
811 ;;
812 Sports)
813 SUBCAT="/Sports"
814 export SUBCAT
815 ;;
816 SportsGame)
817 SUBCAT="/Sports_Games"
818 export SUBCAT
819 ;;
820 Spreadsheet)
821 SUBCAT="/Spreadsheets"
822 export SUBCAT
823 ;;
824 StrategyGame)
825 SUBCAT="/Strategy_Games"
826 export SUBCAT
827 ;;
828 Sun-Supported)
829 SUBCAT=""
830 export SUBCAT
831 ;;
832 Telephony)
833 SUBCAT="/5~Telephony"
834 export SUBCAT
835 ;;
836 TelephonyTools)
837 SUBCAT="/Telephony_Tools"
838 export SUBCAT
839 ;;
840 TerminalEmulator)
841 SUBCAT="/Terminals"
842 export SUBCAT
843 ;;
844 TextEditor)
845 SUBCAT="/Text_Editors"
846 export SUBCAT
847 ;;
848 TextTools)
849 SUBCAT="/Text_Tools"
850 export SUBCAT
851 ;;
852 Translation)
853 SUBCAT="/Translation"
854 export SUBCAT
855 ;;
856 Tuner)
857 SUBCAT="/Tuners"
858 export SUBCAT
859 ;;
860 TV)
861 SUBCAT="/TV"
862 export SUBCAT
863 ;;
864 VectorGraphics)
865 SUBCAT="/Vector_Graphics"
866 export SUBCAT
867 ;;
868 VideoConference)
869 SUBCAT="/Webcam"
870 export SUBCAT
871 ;;
872 Viewer)
873 SUBCAT="/Viewers"
874 export SUBCAT
875 ;;
876 WebBrowser)
877 SUBCAT="/10~Web_Browsers"
878 export SUBCAT
879 ;;
880 WebDevelopment)
881 SUBCAT="/Web_Development"
882 export SUBCAT
883 ;;
884 WordProcessor)
885 SUBCAT="/Word_Processors"
886 export SUBCAT
887 ;;
888 XFCE)
889 SUBCAT=""
890 export SUBCAT
891 ;;
892 X-KDE*)
893 SUBCAT=""
894 export SUBCAT
895 ;;
896 X-Red-Hat*)
897 SUBCAT=""
898 export SUBCAT
899 ;;
900 X-"$2")
901 SUBCAT="/$2"
902 export SUBCAT
903 ;;
904 *)
905 SUBCAT=""
906 export SUBCAT
907 ;;
908 esac
909 }
910
911 gen_category() {
912 # Test for X-Category
913 MAIN_CAT=""
914 SUB_CAT=""
915 if [[ "$1" != "" ]]; then
916 for i in $1; do
917 XEXIST="$(echo "$i" | sed -e 's/.*X-.*/X-/')"
918 if [[ "$XEXIST" == "X-" ]]
919 then XCAT="$(echo "$i" | sed -e 's/X-//')"
920 category "$i" "$XCAT"
921 SUB_CAT="${SUB_CAT} ${SUBCAT}"
922 export SUB_CAT
923 else
924 maincategory "$i"
925 MAIN_CAT="${MAIN_CAT} ${MAINCAT}"
926 export MAIN_CAT
927 category "$i"
928 SUB_CAT="${SUB_CAT} ${SUBCAT}"
929 export SUB_CAT
930 fi
931 done
932 else
933 case "$2" in
934 /usr/share/applnk*)
935 CATNAME="$(echo ${2} | sed -e 's:/usr/share/applnk::' -e 's:/: :g')"
936 ;;
937 /usr/share/gnome/apps*)
938 CATNAME="$(echo ${2} | sed -e 's:/usr/share/gnome/apps::' -e 's:/: :g')"
939 ;;
940 /usr/kde/3.5/share/applnk*)
941 CATNAME="$(echo ${2} | sed -e 's:/usr/kde/3.5/share/applnk::' -e 's:/: :g')"
942 ;;
943 /usr/kde/3.5/share/apps/kappfinder/apps*)
944 CATNAME="$(echo ${2} | sed -e 's:/usr/kde/3.5/share/apps/kappfinder/apps::' -e 's:/: :g')"
945 ;;
946 *)
947 CATNAME=""
948 ;;
949 esac
950 for i in $CATNAME; do
951 XEXIST="$(echo "$i" | sed -e 's/.*X-.*/X-/')"
952 if [[ "$XEXIST" == "X-" ]]
953 then XCAT="$(echo "$i" | sed -e 's/X-//')"
954 category "$i" "$XCAT"
955 SUB_CAT="${SUB_CAT} ${SUBCAT}"
956 export SUB_CAT
957 else
958 maincategory "$i"
959 MAIN_CAT="${MAIN_CAT} ${MAINCAT}"
960 export MAIN_CAT
961 category "$i"
962 SUB_CAT="${SUB_CAT} ${SUBCAT}"
963 export SUB_CAT
964 fi
965 done
966 fi
967 }
968
969 echo -n "" > non_valid_cat.log
970 check_category() {
971 # Check at it is only one main cat in the menu
972 TMP_CAT="$(echo $1 | sed -e 's/ //g')"
973 MAIN__CAT="${MAIN_CAT}"
974 if [[ "$TMP_CAT" != "" ]]; then
975 AV=""
976 A=""
977 V=""
978 for i in $1; do
979 if [[ "$i" == "/Multimedia/Audio-Video" ]]; then
980 AV="AV"
981 fi
982 if [[ "$i" == "/Multimedia/Audio" ]]; then
983 A="A"
984 fi
985 if [[ "$i" == "/Multimedia/Video" ]]; then
986 V="V"
987 fi
988 done
989
990 if [[ "${AV}" == "AV" ]] && [[ "${A}" == "A" ]] && [[ "${V}" == "V" ]]; then
991 MAIN__CAT=""
992 echo "$2" >> non_valid_cat.log
993 else
994 if [[ "${AV}" == "AV" ]] && [[ "${A}" == "A" ]]; then
995 MAIN__CAT="/Multimedia/Audio"
996 fi
997 if [[ "${AV}" == "AV" ]] && [[ "${V}" == "V" ]]; then
998 MAIN__CAT="/Multimedia/Video"
999 fi
1000 fi
1001
1002 else
1003 MAIN__CAT=""
1004 echo "$2" >> non_valid_cat.log
1005 fi
1006 CATEGORY=""
1007 for i in $MAIN__CAT; do
1008 if [[ "$MAIN__CAT" != "" ]]; then
1009 SUB_CAT2="$(echo $3 | sed -e 's/ //g')"
1010 CATEGORY="$i$SUB_CAT2"
1011 fi
1012 break
1013 done
1014
1015 export CATEGORY
1016 }
1017
1018 # Write a FVWM-Crystal menu entry
1019 # Usage: gen_entry <exec_name> <entry_name> <category> <command>
1020 # Usage: gen_consoleentry <exec_name> <entry_name> <category> <command>
1021 gen_entry() {
1022 mkdir -p "${FC_MENUBASE}${3}"
1023 FNAME="${FC_MENUBASE}$3/~$1~$2"
1024 (
1025 echo "#!/bin/sh"
1026 echo
1027 echo "exec $4 \$@"
1028 ) > "${FNAME}"
1029 chmod +x "${FNAME}"
1030 }
1031 gen_consoleentry() {
1032 mkdir -p "${FC_MENUBASE}${3}"
1033 FNAME="${FC_MENUBASE}$3/~$1~$2"
1034 (
1035 echo "#!/bin/sh"
1036 echo
1037 echo "exec FvwmCommand 'A $4 \$@'"
1038 ) > "${FNAME}"
1039 chmod +x "${FNAME}"
1040 }
1041
1042 # # # # # # # # # # # # # # # # # # # # # # # # # # #
1043 # Do something now
1044
1045 $searchdesktop $1
1046
1047 # Main loop
1048 while read myline ; do
1049 searchexecname "${myline}"
1050 searchiconname "${myline}"
1051 searchexist "${myline}" $EXEC
1052 if [[ "$EXIST" == "false" ]]; then
1053 searchkeystrings "${myline}" $USERLOC
1054 gen_category "$CATNAME" "${myline}"
1055 check_category "$MAIN_CAT" "${myline}" "$SUB_CAT"
1056 if [[ "$MAIN__CAT" != "" ]]; then
1057 echo "Generation of menu entry for ${EXEC}"
1058 if [[ "$TERMINAL" == "true" ]]; then
1059 gen_consoleentry "$EXEC" "$SOFTNAME" "$CATEGORY" "$COMMANDF"
1060 else
1061 gen_entry "$EXEC" "$SOFTNAME" "$CATEGORY" "$COMMANDF"
1062 fi
1063 fi
1064 fi
1065 done < filelist
1066 rm filelist
1067
1068 echo ""
1069 echo "All is done"
1070 echo ""
1071
1072 if [ $# -ge 2 ]; then
1073 rm non_valid_cat.log
1074 DesktopDir=`awk -v ORS="" '!/(#|^$)/{print $0"/* "}' $USERPREFS/DesktopDirs`
1075 echo "Saving the date of the last installed desktop file in ${FVWM_USERDIR}/preferences/DateLastApp"
1076 echo "Reloading the menu..."
1077 echo "SetEnv DateLastApp \"`stat --printf="%y\n" ${DesktopDir} | sort -n -r | head -1`\"" > ${FVWM_USERDIR}/preferences/DateLastApp
1078 FvwmCommand 'ReloadRecipe'
1079 else
1080 echo "You will find the list of the desktop files with non valid Main Category in non_valid_cat.log"
1081 fi