#!/usr/bin/perl use strict; use File::Copy; do{ print "usage:\t$0 [path-to-heroes3-installation]\n"; exit 1 } unless( $ARGV[0] ); my $install_dir = $ARGV[0]; my $VERSION='0.2'; my $patchname = 'heroes3-1.3.1a-unified-x86.run'; my $skip = 176; # at the moment i can only localize one *good* mirror: my %url_patches = ( 'Sunsite Denmark' => 'ftp://sunsite.auc.dk/pub/os/linux/loki/updates/heroes3', ); my %url_lokipatch = ( 'icculus' => 'http://icculus.org/~msphil/loki/x86', 'step-n-up' => 'http://step-n-up.com/downloads' ); print "heroes3_x86 autoupdater... v$VERSION by Alex Linke.\n"; print "\n\t* working in '$ENV{PWD}'...\n"; print "\t* making tempdir 'heroes3_up'... "; mkdir "$ENV{PWD}/heroes3_up" || _exit($!); chdir "$ENV{PWD}/heroes3_up" || _exit($!); unless ( -e "../$patchname" ) { print "\n\t* retrieving patch '$patchname'..."; foreach( keys %url_patches ) { print "\n\t\t* trying '$_'...\n"; last if ( system( "wget $url_patches{$_}/$patchname" ) == 0 ); } } else { print "\n\t* copying local patchfile to cwd... "; copy( "../$patchname", "./$patchname" ) || _exit($!); } _exit("no copy of '$patchname' retieved. try manually and save to this dir.") unless ( -e $patchname ); print "\n\t* creating helper 'skip.pl'... "; open FH, "> ./skip.pl" or _exit($!); foreach( ) { print FH $_ } close FH; close DATA; chmod ( 0755, "./skip.pl" ); print "\n\t* unpacking files...\n"; _exit('cannot unpack files!') unless( system("./skip.pl $patchname $skip | gzip -cd | tar xv") || -e "patch.dat" ); unless ( -e "../loki_patch" ) { print "\n\t* retrieving sane 'loki_patch'-file... "; foreach( sort keys %url_lokipatch ) { print "\n\t\t* trying '$_'...\n"; last if ( system("wget $url_lokipatch{$_}/loki_patch") == 0 ); } } else { print "\n\t* copying local 'loki_patch'-file to cwd... "; copy( "../loki_patch", "./loki_patch" ); } _exit("no copy of 'loki_patch' retrieved. try manually and save to this dir.") unless ( -e "loki_patch" ); chmod ( 0755, "./loki_patch" ); print "\n\t* checking if '$install_dir' contains a valid Heroes3 installation... "; _exit("no Heroes3-installation found in '$install_dir'!") unless( -e "$install_dir/heroes3" ); print "\n\t* creating a rescue-binary... "; copy("$install_dir/heroes3", "$install_dir/heroes3.orig") || _exit("cannot create rescue binary 'heroes3.orig'."); print "\n\t* patching...\n"; _exit("Errors during patching!") unless ( system("./loki_patch patch.dat $install_dir") == 0 ); print "\n\noutput of 'heroes3 --version':\n", "=-" x 40, "\n"; system("$install_dir/heroes3 --version"); print "=-" x 40, "\n\n"; print "Wuha! You're done. Have fun with it!\n"; # ----------------------------------------------------------------- # sub _exit { # ----------------------------------------------------------------- # print "\n[FATAL]: $_[0]\n"; exit 1; } __DATA__ #!/usr/bin/perl use strict; my $count = 0; open FH, "$ARGV[0]" or die "$!"; foreach( ) { print if (++$count > $ARGV[1]); }