#!/usr/bin/perl
# Filename: grml-quickconfig
# Purpose: get fast access to some basic grml-scripts
-# Authors: Michael Schierl <schierlm-public@gmx.de>
+# Authors: Michael Schierl <schierlm-public@gmx.de>, Alexander Wirt <formorer@grml.org>
# Bug-Reports: see http://grml.org/bugs/
# License: This file is licensed under the GPL v2.
# Latest change: Sam Mär 17 12:42:50 CET 2007 [mika]
# menu with quick config options
+use Term::ReadKey;
+
# enable alternate charset support (needed for screen)
print "\e(B\e)0";
+open (my $fh, '/proc/cmdline');
+my $cmdline = <$fh>;
+close($fh);
+
+my $color = 1 unless $cmdline =~ /nocolor/;
+
# variables for nice display
-$W = "\e[0;32;1m"; # White
-$N = "\x0f\e[0m"; # Normal
-$M = "\e[0;35;1m"; # Magenta (for commands)
-$B = "\e[0;34;1m\x0e"; # Blue, line drawing characters
+if ($color) {
+ $W = "\e[0;32;1m"; # White
+ $N = "\x0f\e[0m"; # Normal
+ $M = "\e[0;35;1m"; # Magenta (for commands)
+ $B = "\e[0;34;1m\x0e"; # Blue, line drawing characters
+} else {
+ $B = "\x0e";
+ $N = "\x0f";
+}
+
$HLINE=$B."x".$N; # A single horizontal line drawing character
# menu options
%menu_commands = (
- d => 'grml-lang de',
- a => 'grml-lang at',
- c => 'grml-lang ch',
- n => 'grml-network',
- e => 'netcardconfig',
- i => 'grml-info',
- h => 'grml2hd',
- m => 'pdmenu -c',
- q => 'exit',
+ d => 'grml-lang de',
+ a => 'grml-lang at',
+ c => 'grml-lang ch',
+ u => 'grml-lang us',
+ n => 'grml-network',
+ e => 'netcardconfig',
+ i => 'grml-info',
+ h => 'grml2hd',
+ m => 'pdmenu -c',
+ q => 'exit',
# x and Return are handled manually
);
# window managers
%windowmanagers = (
- d => 'dwm',
- e => 'evilwm',
- f => 'fluxbox',
- i => 'ion3',
- j => 'jwm',
- k => 'pekwm',
- p => 'pwm3',
- t => 'twm',
- v => 'fvwm',
- 2 => 'fvwm2',
- c => 'fvwm-crystal',
- r => 'ratpoison',
- 9 => 'w9wm',
- w => 'windowlab',
- m => 'wmi',
- i => 'wmii',
- n => 'wm-ng',
+ d => 'dwm',
+ e => 'evilwm',
+ f => 'fluxbox',
+ i => 'ion3',
+ j => 'jwm',
+ k => 'pekwm',
+ p => 'pwm3',
+ t => 'twm',
+ v => 'fvwm',
+ 2 => 'fvwm2',
+ c => 'fvwm-crystal',
+ r => 'ratpoison',
+ 9 => 'w9wm',
+ w => 'windowlab',
+ m => 'wmi',
+ i => 'wmii',
+ n => 'wm-ng',
);
# main loop
# disable input buffering, see
# man perlfunc | less '+/ getc'
# for details
-system "stty", '-icanon', 'eol', "\001";
+ system "stty", '-icanon', 'eol', "\001";
# main loop
-$command="";
-while($command eq "") {
-print <<"EOF";
+ $command="";
+ while($command eq "") {
+ print <<"EOF";
${B}lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk${N}
$HLINE Welcome to ${M}grml-quickconfig${M} $HLINE
$HLINE Press a highlighted key to perform an action, or press $HLINE
$HLINE ${W}Return${N} or ${W}q${N} to go back to the shell. $HLINE
${B}tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu${N}
- $HLINE Set keyboard layout (${M}grml-lang${N}): ${W}d${N}e ${W}a${N}t ${W}c${N}h $HLINE
+ $HLINE Set keyboard layout (${M}grml-lang${N}): ${W}d${N}e ${W}a${N}t ${W}c${N}h ${W}u${N}s $HLINE
$HLINE Configure ${W}n${N}etwork (${M}grml-network${N}) $HLINE
$HLINE -> Configure ${W}e${N}thernet card directly (${M}netcardconfig${N}) $HLINE
${B}tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu${N}
${B}mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj${N}
EOF
-print "Press a key: ".$M;
-$x = getc;
-print $N.$/.$/;
-if (defined($menu_commands{$x})) {
- $command = $menu_commands{$x};
-} elsif ($x eq "\n") {
- $command= 'exit';
-} elsif ($x eq "x") {
- print <<"EOF";
+ print "Press a key: ".$M;
+ ReadMode 4; # Turn off controls keys
+ while (not defined ($x = ReadKey(-1))) {
+ # No key yet
+ }
+ ReadMode 0; # Reset tty mode before exiting
+
+ print $N.$/.$/;
+ if (defined($menu_commands{$x})) {
+ $command = $menu_commands{$x};
+ } elsif ($x eq "\n") {
+ $command= 'exit';
+ } elsif ($x eq "x") {
+ print <<"EOF";
${B}lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk${N}
$HLINE Select a window manager (unsorted list): $HLINE
${B}mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj${N}
EOF
- print "Press a key: ".$M;
- $x = getc;
- print $N.$/.$/;
- if (defined($windowmanagers{$x})) {
+ print "Press a key: ".$M;
+ ReadMode 4; # Turn off controls keys
+ while (not defined ($x = ReadKey(-1))) {
+ # No key yet
+ }
+ ReadMode 0; # Reset tty mode before exiting
+
+ print $N.$/.$/;
+ if (defined($windowmanagers{$x})) {
$command = "su - grml -c 'grml-x ".$windowmanagers{$x}."'";
- } else {
+ } else {
print "Unknown key.\n";
+ }
+ } else {
+ print "Unknown key.\n";
}
-} else {
- print "Unknown key.\n";
-}
-}
+ }
# reenable input buffering
-system "stty", 'icanon', 'eol', '^@';
+ system "stty", 'icanon', 'eol', '^@';
-if ($command eq "exit") {
+ if ($command eq "exit") {
last;
-}
-print $W . "Running command: " . $M . $command . $N . $/;
-system($command);
-print $/;
+ }
+ print $W . "Running command: " . $M . $command . $N . $/;
+ system($command);
+ print $/;
}
print "Happy hacking!\n";