123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- my $version = "2.0";
- use strict;
- use FindBin;
- my $args = set_overrides();
- my $cwd = $FindBin::RealBin;
- my $scriptname = $FindBin::Script;
- my $HOME = $ENV{"HOME"};
- if ("@ARGV" =~ /(-|--)install/)
- {
- install();
- }
- elsif ("@ARGV" =~ /(-|--)reinstall/)
- {
- reinstall();
- }
- elsif ("@ARGV" =~ /(-|--)uninstall/)
- {
- uninstall();
- }
- elsif ("@ARGV" =~ /(-|--)help/)
- {
- help();
- }
- elsif ("@ARGV" =~ /(-|--)update/)
- {
- update();
- }
- else
- {
- main();
- }
- sub main
- {
-
- my $java_binary = "$cwd/java-bin";
-
-
- my $ldpath = unix_findlibrarypath("$java_binary");
-
-
- my $clientmodecheck = `"$java_binary" -help 2>&1`;
-
-
- my $prms = "";
-
-
- if ($clientmodecheck =~ /-client/)
- {
-
- $prms = "-client";
- }
-
-
- if ("@ARGV" =~ /-version/)
- {
-
- system "$ldpath $java_binary $prms @ARGV";
-
-
- print "\nExecuted with the Environment Variable\n$ldpath\nThrough java-wrapper version: $version\nParameters were: $args\n";
-
-
- exit
- }
-
- system "$ldpath $java_binary $prms $args && exit";
- }
- sub unix_findlibrarypath
- {
-
- my ($binary) = "@_";
-
-
- my $lddresult = `ldd $binary | grep libjli.so`;
-
-
-
- $lddresult =~ s/\s*libjli\.so\s*=>\s+(.*)jli\/libjli\.so\s+\(\S+\)\s*$/$1/;
-
-
- return "LD_LIBRARY_PATH=$lddresult";
- }
- sub install
- {
-
- my ($location, $binary) = locate_java_installs();
-
-
- my $alreadyinstalledcheck = `ls $location`;
-
-
- if ($alreadyinstalledcheck =~ /java-bin/)
- {
- die "The wrapper is possibly already installed in this java directory!\nPlease run java-wrapper --uninstall first or java-wrapper --reinstall\n\n";
- }
-
-
- configure_wrapper($location, $binary);
- }
- sub locate_java_installs
- {
-
- print "Trying to find all java binaries on the computer\nThis MAY take some time\n";
-
-
- my $java_binaries = `find / -name "libjli.so" 2>&1 | grep -v Permission`;
-
-
- $java_binaries =~ s/\/lib\/(i386|amd64)\/jli\/libjli.so/\/bin\/java/g;
-
-
- my @binaries = split (/\n/, $java_binaries);
-
-
- print "Please enter the number for the java binary you want this script to use.\n\n";
-
-
- my $counter = 0;
-
- foreach (@binaries)
- {
-
- print " [$counter] $binaries[$counter]\n";
-
-
- $counter += 1;
- }
-
-
- print "\nType in the number for the java binary this script shall use,\nEnter the number and press Enter/Return:";
-
-
- my $choosen_binary = <STDIN>;
-
-
- my $location = $binaries[$choosen_binary];
-
-
- $location =~ s/\/java$//;
-
-
- return ($location, $binaries[$choosen_binary]);
- }
- sub configure_wrapper
- {
- my ($location, $binary) = @_;
-
-
- print "Renaming the real binary to java-bin\n";
- system "mv -v \"$binary\" \"$location/java-bin\"";
-
-
- print "\nCopying the wrapper to $location/java\n";
- system "cp -v \"$cwd/$scriptname\" \"$binary\"";
- }
- sub reinstall
- {
-
- my ($location, $binary) = locate_java_installs();
-
-
- my $alreadyinstalledcheck = `ldd $location/java`;
-
-
- if ($alreadyinstalledcheck =~ /libjli.so/)
- {
-
- configure_wrapper($location, $binary)
- }
- else
- {
-
- print "\nCopying the wrapper to $location/java\n";
- system "cp -v \"$cwd/$scriptname\" \"$binary\"";
- }
- }
- sub uninstall
- {
- print "Preparing uninstall\n";
-
-
- my ($location, $binary) = locate_java_installs();
-
-
- my $alreadyinstalledcheck = `ldd $location/java`;
-
-
- if ($alreadyinstalledcheck !~ /libjli.so/)
- {
-
- print "Uninstalling the java-wrapper from $location.\n";
- system "mv -v \"$location/java-bin\" \"$binary\"";
- }
- else
- {
- print "Nothing to uninstall!\n";
- }
-
- }
- sub activate_overrides
- {
- my ($args, $overrides) = @_;
-
-
- foreach my $hashkey (keys $overrides)
- {
-
- if ($hashkey =~ /^_set_/i)
- {
-
- next;
- }
- else
- {
-
- my $setkey = $hashkey;
-
-
- $setkey =~ s/_if_/_set_/i;
-
-
- $args =~ s/$overrides->{$hashkey}/$overrides->{$setkey}/ig;
- }
- }
-
- return $args;
- }
- sub set_overrides
- {
-
-
- my $overrides = {
- _if_maxmem => "-Xmx256m",
- _set_maxmem => "-Xmx512m",
- _if_stacksize => "-Xss1m",
- _set_stacksize => "-Xss2m",
- };
-
-
- system "mkdir -p ".$ENV{"HOME"}."/.config/java-wrapper";
-
- my $module_exists = `ls $ENV{"HOME"}/.config/java-wrapper`;
- if ($module_exists =~ /overrides.pm/)
- {
- require $ENV{"HOME"}."/.config/java-wrapper/overrides.pm";
- $overrides = overrides::get_overrides();
- }
- elsif ($module_exists !~ /overrides.pm/)
- {
- print $module_exists;
- WriteFile('package overrides;
- # This is a collection of programmable overrides for the java parameters
- # _if_overridename is set to(=>) "value",
- # _set_overridename set it to(=>) "value",
- # NOTE: you can add any if statements if you follow the method above!
- $overrides = {
- _if_maxmem => "-Xmx256m",
- _set_maxmem => "-Xmx512m",
- _if_stacksize => "-Xss1m",
- _set_stacksize => "-Xss2m",
- };
- ## END OF OVERRIDES
- #
- #---------------------------------------- *** ----------------------------------------
- #
- # Callback, DO NOT TOUCH!
- sub get_overrides
- {
- return $overrides;
- }
- ', ">", $ENV{"HOME"}."/.config/java-wrapper/overrides.pm");
- }
-
-
- my $args = "@ARGV";
-
- $args = activate_overrides($args, $overrides);
- }
- sub WriteFile
- {
-
- my ($content, $writemode, $outfile) = @_;
-
-
- open (my $FILE, "$writemode$outfile");
-
- print $FILE "$content\n";
- }
- sub update
- {
-
- print "Updating script from $cwd/$scriptname http://dl.dropbox.com/u/11631899/opensource/Perl/java-wrapper/java-wrapper\n";
-
-
- system "wget -O $cwd/$scriptname http://dl.dropbox.com/u/11631899/opensource/Perl/java-wrapper/java-wrapper";
- }
- sub help
- {
-
- system "$cwd/java-bin -help";
-
-
- print "\njava-wrapper help:\n\t-install\n\t\tFinds all java locations and installs the wrapper in the\n\t\tJava location of your choice.\n\t-reinstall\n\t\tFinds all Java locations and reinstalls the wrapper in the\n\t\tJava location of your choice.\n\t-uninstall\n\t\tFinds all Java locations and uninstalls the wrapper from the\n\t\tJava location of your choice.\n\t-update\n\t\tDownload and overwrite the script with the newest\n\t\tversion of the wrapper.\n\t-help\n\t\tShows this help text\n";
- }
|