#!/usr/bin/perl -w # make sure you change the first line to point to # your perl executable. use strict; use File::Copy "cp"; use File::Basename; sub GlobDir; sub DoMirror; sub RunQuake; # this is the subdirectory of the users home directory to stick the quake stuff in $main::dir = ".quake"; # this is where to find the quake stuff - binaries should reside in this directory # and any subdirectories will be assumed to be the game and any extra levels # Make sure this has a trailing slash '/' on it. $main::quake_dir = "/usr/local/lib/quake/"; # This is the X binary to execute $main::X_bin = "quake.x11"; # This is the SVGA binary to execute $main::SVGA_bin = "squake"; # You shouldn't need to change anything below here. $main::local_dir = $ENV{"HOME"}.'/'.$main::dir.'/'; @main::Configs = ('config.cfg','autoexec.cfg'); @main::DIRS = ('progs/','maps/'); if(!(-d $main::dir)) { mkdir($main::dir,0777) || die "Cannot create $main::dir directory. $!\n"; } GlobDir($main::local_dir,\@main::games); Do_menu(\@main::games,\@main::gameopts); RunQuake($main::local_dir,@main::gameopts); sub Do_menu { my $games = shift; my $ret = shift; my ($i,$num,$sel); foreach $i (@$games) { printf "[%u] %s\n",++$num,$i; } print "Enter selection: "; chop ($sel = ); while(!(defined($sel) &&($sel =~ /\d+/)&&($sel>0) &&(defined ((@$games)[$sel-1])))) { print "Invalid Selection\nEnter selection: "; chop ($sel = ); } @$ret = ('-game',((@$games)[$sel-1])); printf "Playing game %s\n", (@$games)[$sel-1]; } sub GlobDir { my $dir = shift; my $ret = shift; my (@dirs,$i,$local_i); chdir $dir; foreach $i (glob("$main::quake_dir*")) { $local_i = basename($i); if((-d $i) && (-x $i) && (-r $i)) { push @dirs, $local_i; DoMirror($i,$dir.$local_i); } elsif((-f $i) && (-r $i) && (-x $i)) { if(!(-l $local_i)) { symlink($i, $dir.$local_i) || warn "Cannot symlink $i -> $local_i. $!\n"; } } } @$ret = @dirs; } sub DoMirror { my ($from,$to) = @_; my (@paks,@dat,@mdl,$i,$file); unless(-d $to) { mkdir($to,0777) || (warn "Cannot create quake subdirectory $to. $!\n" && return(1)) } @paks = glob($from.'/'."*.pak"); @dat = glob($from.'/'."*.dat"); foreach $i (@paks,@dat,@main::DIRS) { $file = basename($i); unless((-l $to.'/'.$file)||(!-e $i)) { symlink($i,$to.'/'.$file) || warn "Cannot symlink $i -> $file. $!\n"; } } foreach $i (@main::Configs) { if(-r $from.'/'.$i) { cp($from.'/'.$i,$to.'/'.$i) || warn "Cannot copy $i for subdirectory $to. $!\n"; } } } sub RunQuake { my $dir = shift; my ($bin); print "Opts: @ARGV @_\n"; chdir $dir; if($ENV{DISPLAY}) { $bin = './'.$main::X_bin; (exec $bin, @ARGV, @_) || die "Cannot execute $main::X_bin. $!\n"; } elsif($ENV{TERM} eq "linux") { $bin = './'.$main::SVGA_bin; (exec $bin, @ARGV, @_) || die "Cannot execute $main::SVGA_bin. $!\n"; } else { die "You do not appear to be running X ". "or be on a virtual console.\n"."Please check your DISPLAY and ". "TERM enviroment variables and try again.\n"; } }