#!/usr/bin/perl -w
#
# Author: George Sipos email: xvudpapa --AT-- savba --DOT-- sk
# Version: 1.0
#
# This is a Perl script that serves a similar function like Linux
# RedHat SWITCHDESK - so you can switch between X Window Managers.
#
# Pomocou tohto skriptu budete moct prepinat medzi roznymi X Window
# managermi Pod FreeBSD. Staci, ak spustite skript switchdesk.pl a napisete
# vas X Window Manager, ktory chcete pouzivat, napr. fvwm, kde, gnome atd.
# Tento program urobi zmeny v domovskom adresari aj neprivigilegovanych
# uzivatelov.
#
# This program is free; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. This software is distributed in 
# the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
# PURPOSE. See the GNU General Public License for more details.

# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

####
 $myhome = $ENV{"HOME"};
 print "\nDo you want to run 'gnome', 'fvwm2', 'wmaker', 'twm' or 'kde'? ";
 print "\nChcete spustat 'gnome', 'fvwm2', 'wmaker', 'twm' alebo 'kde'? ";
 print "\nNapiste to tak, ako to vidite tu: ";
 $run = <STDIN>;
 chomp($run);
 print "Is this what you typed and is it correct? - $run\n";
 print "Napisali ste to spravne? - $run\n";
 print "\nPo vykonani zmien spustite X Window prikazom startx\n";
 print "\nAnswer (y/n): ";
 $q = <STDIN>;
 chomp($q);
 $q =~ tr/A-Z/a-z/;
 if ($q eq "n") {
 print "Run the script again\n\a";
 print "Spustite skript este raz\n\a";
 exit;
 }
 if ($q eq "y") {
 print "Generating files\n";
 }
		
 $run =~ tr/A-Z/a-z/;
 if ($run eq "kde") {
 print "Creating files . . .\n";
 open(XINI,  ">$myhome/.xinitrc");
 print XINI  "exec startkde", "\n";
 close XINI; 
 open(XSES, ">$myhome/.xsession");
 print XSES  "exec startkde", "\n";
 close XSES;
 }
 if ($run eq "gnome") {
 print "Creating files . . . \n";
 open(XINI, ">$myhome/.xinitrc");
 print XINI "exec gnome-session", "\n";
 close XINI;
 open(XSES, ">$myhome/.xsession");
 print XSES "exec gnome-session", "\n";
 close XSES;
 }
 if ($run eq "fvwm2") {
 print "Creating files . . . \n";
 open(XINI, ">$myhome/.xinitrc");
 print XINI "exec fvwm2", "\n";
 close XINI;
 open(XSES, ">$myhome/.xsession");
 print XSES "exec fvwm2", "\n";
 close XSES;
  }
 if ($run eq "wmaker") {
 print "Creating files . . . \n";
 open(XINI, ">$myhome/.xinitrc");
 print XINI "exec wmaker", "\n";
 close XINI;
 open(XSES, ">$myhome/.xsession");
 print XSES "exec wmaker", "\n";
 close XSES;
  }
 if ($run eq "twm") {
 print "Creating files . . . \n";
 open(XINI, ">$myhome/.xinitrc");
 print XINI "exec twm", "\n";
 close XINI;
 open(XSES, ">$myhome/.xsession");
 print XSES "exec twm", "\n";
 close XSES;
  }
		    
 