aboutsummaryrefslogtreecommitdiffstats
path: root/trunk/sbin
diff options
context:
space:
mode:
Diffstat (limited to 'trunk/sbin')
-rw-r--r--trunk/sbin/chksession160
-rw-r--r--trunk/sbin/convertsession31
-rwxr-xr-xtrunk/sbin/fndSession29
-rwxr-xr-xtrunk/sbin/kdeDesktopCleanup30
4 files changed, 250 insertions, 0 deletions
diff --git a/trunk/sbin/chksession b/trunk/sbin/chksession
new file mode 100644
index 0000000..2d68860
--- /dev/null
+++ b/trunk/sbin/chksession
@@ -0,0 +1,160 @@
+#!/usr/bin/perl
+# (c) Mandriva, Chmouel Boudjnah <chmouel@mandriva.com>
+# Copyright under GPL blah blah blah.
+## For info, see "chksession --help" or "man chksession"
+
+# Modified by Bernard Lang on August 21, 2003.
+
+
+my @lf;
+
+sub usage {
+ my $e = shift @_;
+ $0 =~ s|.*/||;
+ print { $e ? STDERR : STDOUT } << "EOF";
+Usage: $0 [OPTION]...
+
+ -F --first: Print only first available entry.
+ -t, --test: Go in test mode.
+ -l, --list: List window-managers.
+ -L: List window-managers including the order number
+ -d=DIR, --dir=DIR: Specifies a directory of w-m configuration files.
+ Default is /etc/X11/wmsession.d/
+-x=ENTRY, --xsession=ENTRY: Produce window-managers script of ENTRY.
+ -k, --kdm: Produce window-managers list for kdm sessions.
+ -g, --gdm: Produce window-managers script for gdm sessions.
+ -h, --help: Produce this help.
+
+EOF
+ exit($e);
+}
+
+sub cat { # returns content of argument file as a single string
+ my ($f) = @_;
+ local *F;
+ open F, $f or die "Can't open $f\n";
+ local $/ = "";
+ <F>
+ }
+
+sub parse_file { # parse a session descriptor file
+ my ($fn) = @_;
+ $_ = cat ($fn);
+ ($n = $1) =~ s| ||g if /^NAME=(.*)/m;
+ $e = $1 if /^EXEC=(.*)/m;
+# $d = $1 if /^DESC=(.*)/m;
+# $i = $1 if /^ICON=(.*)/m;
+ $s = $1 while /SCRIPT:(.*?)$/gs; chomp $s;
+ if (-x $e) { $script{$n} = $s; $exe{$n} = $e; push @lf, $n; ($order{$n}) = $fn =~ m/(^[0-9][0-9])/; }
+# if (-x $e) { $script{$n} = $s; $exec{$n} = $e; $desc{$n} = $d; $icon{$n} = $i; push @lf, $n; }
+}
+
+sub gen_desktops {
+ my ($d, $usesession) = @_;
+ -d $d or system("mkdir -p $d");
+ system("rm -f $d/*");
+
+ for my $file (@lf) {
+ open FH, ">$d/$order{$file}$file.desktop" or die "Can't write to $d/$order{$file}.desktop\n";
+ print FH "[Desktop Entry]\n";
+ print FH "Encoding=UTF-8\n";
+ print FH "Name=$file\n";
+ print FH "Comment=$file\n";
+ print FH "TryExec=$exe{$file}\n" if $exe{$file};
+ if ($usesession) {
+ print FH "Exec=/etc/X11/xdm/Xsession $file\n";
+ } else {
+ print FH "Exec=$file\n";
+ }
+ print FH "Icon=\n";
+ print FH "Type=Application\n";
+ close FH;
+ chmod 0755, $file;
+ }
+}
+
+usage(1)
+ if @ARGV < 1;
+
+while ($ARGV[0] =~ /^--/ || $ARGV[0] =~ /^-/) {
+ $_ = shift;
+ if (/^--xsession=([^ ]+)/ || /^-x=([^ ]+)/) {
+ $xsession = $1;
+ } elsif (/^--first/ || /^-F/) {
+ $first++;
+ } elsif (/^--gdm/ || /^-g/) {
+ die "You should be root to build gdm session\n" if $< != 0;
+ $gdm++;
+ } elsif (/^--list/ || /^-l/) {
+ $list++;
+ } elsif (/^-L/) {
+ $list_order++;
+ } elsif (/^--kdmsess/ || /^-k/) {
+ $kdm++;
+ } elsif (/^--test/ || /^-t/) {
+ $test++;
+ } elsif (/^--dir=([^ ]+)/ || /^-d=([^ ]+)/) {
+ $dir = $1;
+ } elsif (/^--help/ || /^-h/ || /^-\?/) {
+ usage(0);
+ } else {
+ print STDERR "Unrecognized switch: $_\n";
+ usage(1);
+ }
+}
+
+# Parse all relevant files in session directory $dir
+$dir = $test ? './wmsession.d/' : '/etc/X11/wmsession.d/' unless $dir;
+chdir $dir;
+for (<*>) {
+ next if /.*~/;
+ next if /.*\.rpm(save|old)/;
+ parse_file ("$_");
+}
+
+my ($e) = eval {cat("/etc/sysconfig/desktop")} =~ /DESKTOP=(\S+)/;
+# The first string (without spaces) in the file is copied to $e.
+
+# If $e is one of the names in @lf, then it is placed first (leftmost).
+# Order of names in @lf is otherwise unchanged.
+@lf = sort { $b =~ /^$e$/i <=> $a =~ /^$e$/i } @lf;
+
+
+if ($kdm) {
+ gen_desktops('/usr/share/apps/kdm/sessions', 0);
+}
+
+if ($gdm) {
+ gen_desktops('/etc/X11/dm/Sessions', 1);
+}
+
+if ($xsession) {
+ if ($script{$xsession}) {
+ print "#!/bin/sh\n";
+ print $script{$xsession}
+ } else {
+ print "xterm -geometry 100x25+0+0 &\n";
+ if ( -x '/usr/X11R6/bin/icewm' ) {
+ print "icewm\n";
+ } elsif ( -x '/usr/X11R6/bin/twm' ) {
+ print "twm\n";
+ } else {
+ print "xterm -geometry 67x14+384+446\n";
+ }
+ }
+ exit (0);
+}
+
+@lf ? print shift @lf, "\n" : print "Default\n"
+ if $first;
+
+if ($list) {
+ if (@lf) {
+ print join(' ', @lf, 'Default', 'failsafe'), "\n";
+ } else {
+ print "Default\n";
+ }
+} elsif ($list_order) {
+ print join(' ', map { "$_=$order{$_}" } @lf), "\n";
+}
+
diff --git a/trunk/sbin/convertsession b/trunk/sbin/convertsession
new file mode 100644
index 0000000..05ea57e
--- /dev/null
+++ b/trunk/sbin/convertsession
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+# -*- Mode: cperl -*-
+# Copyright (C) 2000 by Chmouel Boudjnah <chmouel@mandriva.com>
+# Redistribution of this file is permitted under the terms of the GNU
+# Public License (GPL)
+## description: Convert a file /etc/X11/window-managers to a
+## /etc/X11/wmsession.d/ style files.
+
+my $dir = '/etc/X11/wmsession.d/';
+
+if ($ARGV[0] =~ /-f/ ) {
+ $file = $ARGV[1];
+} else {
+ $file = '/etc/X11/window-managers';
+}
+
+my $cnt = 0;
+
+open F, $file or die "Can't open $file\n";
+while (<F>) {
+ $/ = "--@@--";
+ s|--@@--||g;
+ if ($cnt != 0) {
+ $content = "$_";
+ $n = $1 if /^NAME=(.*)/m;
+ open C, ">$dir/$cnt$n" or die "Can't open $dir/$cnt$n\n";
+ print C $content;
+ close C;
+ }
+ $cnt++;
+}
diff --git a/trunk/sbin/fndSession b/trunk/sbin/fndSession
new file mode 100755
index 0000000..4fd7c7c
--- /dev/null
+++ b/trunk/sbin/fndSession
@@ -0,0 +1,29 @@
+#!/bin/sh
+#---------------------------------------------------------------
+# Project : Mandriva Linux
+# Module : sbin
+# File : fndSession
+# Version : $Id$
+# Author : Frederic Lepied
+# Created On : Mon May 30 10:43:12 2005
+# Purpose : find sessions for display managers
+#---------------------------------------------------------------
+
+umask 022
+
+FILES=`/bin/ls /etc/X11/dm.d/*.conf 2> /dev/null`
+
+if [ $? != 0 ]; then
+ exit 0
+fi
+
+for f in $FILES; do
+ EXEC=
+ FNDSESSION_EXEC=
+ eval `grep 'EXEC=' "$f"`
+ if [ -x "$EXEC" -a -n "$FNDSESSION_EXEC" ]; then
+ $FNDSESSION_EXEC
+ fi
+done
+
+# fndSession ends here
diff --git a/trunk/sbin/kdeDesktopCleanup b/trunk/sbin/kdeDesktopCleanup
new file mode 100755
index 0000000..323dcc5
--- /dev/null
+++ b/trunk/sbin/kdeDesktopCleanup
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+# (c) Mandriva, Pixel <pixel@mandriva.com>
+# Copyright under GPL
+
+@dirs = (qw(/etc/skel /root), glob("/home/*"));
+@path = split ":", "/sbin:/usr/sbin:/usr/X11R6/bin:/bin:/usr/bin";
+
+foreach $f (map { grep { /\.kdelnk$/ } eval { all("$_/Desktop") } } @dirs) {
+ open F, $f or next;
+ L: foreach (<F>) {
+ if (/^Exec=(?:kdesu\s+-c\s+)?"?(\S+)/) {
+ -x "$_/$1" and last L foreach '', @path;
+ } elsif (m|^URL=file:(/.*)|) {
+ -e $1 and last;
+ } else { next }
+ print STDERR "removing $f\n";
+ unlink $f;
+ last;
+ }
+}
+
+sub all {
+ my $d = shift;
+ local *F;
+ opendir F, $d or die "all: can't open dir $d: $!\n";
+ my @l = grep { $_ ne '.' && $_ ne '..' } readdir F;
+ closedir F;
+
+ map { "$d/$_" } @l;
+}