omap3-pandora-kernel2: update
[openpandora.oe.git] / recipes / slim / slim / update_slim_wmlist
1 #!/usr/bin/perl -w
2 #
3 # update_slim_wmlist, based on:
4 # update_wdm_wmlist, (c) 1998 Marcelo Magallón <mmagallo@debian.org>
5 # rewriten to use the x-window-manager alternative
6 # modified to also use the x-session-manager alternative by Arthur Korn
7 # Copyright 2000 Wichert Akkerman <wakkerma@debian.org>
8 # Modified to use the freedesktop.org .desktop like kdm and gdm
9 #
10 # This script will read the list of installed window managers from
11 # the freedesktop .desktop files in <etc>/X11/sessions/:<etc>/dm/Sessions/:
12 # <share>/xsessions/
13 # and update the sessions line in /etc/slim.conf.
14 # BEWARE: It doesn't ask any questions about this. It just does it. It
15 # takes an optional list of window managers.
16
17 use strict;
18 use File::DesktopEntry;
19
20 my $wm_list='';
21 my %desktop_files;
22
23 unless (@ARGV) {
24     #my @wm_list = ('default');
25     my @wm_list;
26     foreach my $dir ('/etc/X11/sessions/','/etc/dm/Sessions/','/usr/share/xsessions/') {
27             next unless (opendir DIR, $dir);
28             my @files;
29             @files = grep { /\.desktop$/ && -r "$dir/$_" } readdir(DIR);
30             foreach my $file (@files) {
31                    push @{$desktop_files{$file}}, "$dir/$file";
32             }
33     }
34     DESKTOP: foreach my $desktop_file (keys(%desktop_files)) {
35             foreach my $file (@{$desktop_files{$desktop_file}}) {
36                     my $entry = File::DesktopEntry->new_from_file($file);
37                     next DESKTOP if (defined($entry->get_value('Hidden'))
38                         and $entry->get_value('Hidden') eq 'true');
39                     if ($entry->get_value('Name') =~ /^gnome$/i) {
40                             push (@wm_list, 'gnome');
41                     }
42                     elsif ($entry->get_value('Name') =~ /^kde$/i) {
43                             push (@wm_list, 'kde');
44                     }
45                     elsif (defined($entry->get_value('Exec'))) {
46                             push (@wm_list, $entry->get_value('Exec'));
47                     }
48                     else { # not found, go to next file
49                             next;
50                     }
51                     # found, proceed to next destop file
52                     next DESKTOP;
53             }
54     }
55    $wm_list = join (',', sort @wm_list) . ',custom';
56 } else {
57     $wm_list = join (',', sort @ARGV);
58 }
59
60 open (SLIM_CONFIG_FILE, '</etc/slim.conf')
61     or die "Can't open /etc/slim.conf for reading: $!";
62 open (NEW_SLIM_CONFIG_FILE, '>/etc/slim.conf.new')
63     or die "Can't open /etc/slim.conf.new for writing: $!";
64
65 while (<SLIM_CONFIG_FILE>) {
66     s|^(sessions\s*).*|$1$wm_list|;
67     print NEW_SLIM_CONFIG_FILE;
68 }
69
70 close(SLIM_CONFIG_FILE);
71 close(NEW_SLIM_CONFIG_FILE);
72
73 rename '/etc/slim.conf.new', '/etc/slim.conf'
74     or die "Can't rename /etc/slim.conf.new: $!";
75
76 exit 0;