Debian Codegraph @

debian/bamfdaemon.postinst

raw
1 #! /bin/sh
2 set -e
3
4 BAMF_INDEX_NAME="bamf-2.index"
5
6 if [ "$1" = "configure" ] || [ "$1" = "triggered" ]; then
7 if [ -d /usr/share/applications ]; then
8 # remove deprecated index files
9 if [ -f /usr/share/applications/bamf.index ]; then
10 rm -f /usr/share/applications/bamf.index
11 fi
12 # rebuild index
13 I=/usr/share/applications/$BAMF_INDEX_NAME
14 echo "Rebuilding $I..."
15 rm -f $I
16 perl -e '
17 use File::Find;
18 my $dir_name;
19
20 sub strip_exec
21 {
22 my $f = $_;
23 return unless $f =~ /\.desktop$/;
24 return unless ("$File::Find::dir" eq "$dir_name");
25 my @lines;
26 open F, $f;
27 @lines = <F>;
28 close F;
29 my $in_desktop_entry = 0;
30 my $exec = "";
31 my $class = "";
32 my $no_display = "false";
33 my $only_show_in = "";
34
35 foreach (@lines)
36 {
37 if (/^\[\s*(.+)\s*\]/)
38 {
39 $was_in_desktop = $in_desktop_entry;
40 $in_desktop_entry = ($1 eq "Desktop Entry");
41
42 if ($was_in_desktop and !$in_desktop_entry)
43 {
44 last;
45 }
46 }
47
48 if ($in_desktop_entry)
49 {
50 if (/^Exec=(.+)$/)
51 {
52 $exec = $1;
53 $exec =~ s/^\s+|\s+$//g;
54 }
55
56 if (/^NoDisplay=(.+)$/)
57 {
58 $no_display = $1;
59 $no_display =~ s/^\s+|\s+$//g;
60 }
61
62 if (/^OnlyShowIn=(.+)$/)
63 {
64 $only_show_in = $1;
65 $only_show_in =~ s/^\s+|\s+$//g;
66 }
67
68 if (/^StartupWMClass=(.+)$/)
69 {
70 $class = $1;
71 $class =~ s/^\s+|\s+$//g;
72 }
73 }
74 }
75
76 if ($exec ne "")
77 {
78 print "$f\t$exec\t$class\t$only_show_in\t$no_display\n";
79 }
80 };
81
82 $dir_name = $ARGV[-1];
83 $dir_name = $1 if($dir_name=~/(.*)\/$/);
84 find(\&strip_exec, $dir_name);' /usr/share/applications \
85 > $I.new || rm -f $I.new
86
87 [ -e $I.new ] && mv $I.new $I || true
88 fi
89 fi
90
91 #DEBHELPER#