Archive for the ‘scripts’ Category

fixpath-1.0.0

January 25, 2013

For all supported OS X.  This contains the path-fixing script that I mentioned earlier.

The source is at https://github.com/akhansen/fixpath

Path modifier script

January 2, 2013

I just discovered that XQuartz on Mountain Lion does some annoying things to my PATH, changing:

/sw/lib/perl5/ExtUtils:/sw/bin:/sw/sbin:
/usr/bin:/bin:/usr/sbin:/sbin:
/usr/local/bin:
/opt/X11/bin:/Users/hansen/bin

in a Terminal window to

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:
/opt/X11/bin:
/sw/lib/perl5/ExtUtils:/sw/bin:/sw/sbin:
/usr/X11R6/bin:
/Users/hansen/bin:/Users/hansen/bin:
/opt/X11/bin

in an xterm.

The duplicate entries aren’t so bad, but moving the system directories in front of Fink’s is annoying.  Running pathsetup.sh again doesn’t change this, unfortunately.  I came up with a script which lets me reorder the PATH by blocks and remove via a pattern match any items I don’t want.  As an afterthought, it removes duplicates, too.  By running

export PATH=`pathformat.pl --delete=X11R6`

I am able to restore the PATH settings to the xterm that I have in my Terminal window. The pathformat.pl script follows:

#!/usr/bin/env perl -w

# Read in the PATH environment variable and
# 1) Strip out duplicate entries
# 2) Delete entries matching a pattern given by instances of the --delete flag
# 3) Put the entries in the order Fink, system, user.
# This could certainly be extended.

use strict;
use List::MoreUtils qw { uniq };
use Getopt::Long;

my @delete_vals;
my $result=GetOptions ("delete=s" => \@delete_vals);

my (@finkpath, @userpath, @generalpath);

ENTRY: foreach my $entry (uniq (split /:/, $ENV{"PATH"})) {
     foreach (@delete_vals) {
          next ENTRY if $entry =~ /$_/;
     }
     if ($entry =~ m|^/sw|) {
          push @finkpath, ($entry);
     } elsif ($entry =~ m/$ENV{"HOME"}/) {
          push @userpath, ($entry);
     } else {
          push @generalpath, ($entry);
    }
}
print join(':', @finkpath, @generalpath, @userpath),"\n";

Handy migrator script

July 19, 2012

Tired of manually migrating your Fink Perl/Python/Octave … modules to match the latest Fink version of Perl/Python/Octave?

Hate having to check whether all of your installed modules are also available for the new version?

Have we got a script for you!  (I like it, anyway):

#!/usr/bin/env perl
# Copyright (c) 2012 Alexander Hansen
#
# This program is free software; 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 program 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.

use strict;
use Fink;
use Fink::SysState;
use Getopt::Long;
my ($lang,$old_vers,$new_vers);
my $options=GetOptions ( 'lang=s' => \$lang,
 'old=i' => \$old_vers,
 'new=i' => \$new_vers,
 );
my @supported_lang=qw (
 oct
 pm
 py
 rb
 r
 dummy
);
die "Usage:\n\nmodule-update.plx --lang=<oct|pm|py|rb|r> ".
"--old=<old value> --new=<new value>\n".
"\nExample:\n\tmodule-update.plx --lang=pm ".
"--old=5123 --new=5124\n" if !($lang && $old_vers && $new_vers);
foreach (@supported_lang) {
 last if $lang eq $_; 
} continue {
 die "$lang isn't a supported option.\n" if $_ eq 'dummy';
}
my $old_mod=$lang.$old_vers;
my $new_mod=$lang.$new_vers;
print "Converting $old_mod -> $new_mod\n";
my $state = Fink::SysState->new();
my @pkg_names = $state->list_packages();
# create list of installed matching packages
my @pkg_filtered;
foreach (@pkg_names) {
 if (m/$old_mod/) {
 push @pkg_filtered, ($_);
 } else {
 }
}
die "There are no currently installed $old_mod packages.\n" if !@pkg_filtered;
my @pkgs_to_update;
chomp(my @full_pkg_list=`fink listpackages`);
# check each of our filtered packages for a matching counterpart:
foreach (@pkg_filtered) {
 my $old_pkg=$_;
 s/$old_mod/$new_mod/;
 my $new_pkg=$_;
 next if $state->installed($new_pkg); # no need to install an already-installed package
 next if !grep(/$new_pkg/, @full_pkg_list); # Can't install a nonexistent package
 push @pkgs_to_update,($new_pkg);
}
print "Installing @pkgs_to_update\n.";
exec "fink install @pkgs_to_update";