Archive for the ‘scripts’ Category


January 25, 2013

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

The source is at


Path modifier script

January 2, 2013

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


in a Terminal window to


in an xterm.

The duplicate entries aren’t so bad, but moving the system directories in front of Fink’s is annoying.  Running 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=` --delete=X11R6`

I am able to restore the PATH settings to the xterm that I have in my Terminal window. The 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
# 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 (
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=$_;
 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";