Handy migrator script

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";
About these ads

One Response to “Handy migrator script”

  1. finkakh Says:

    Reblogged this on Finkers: a blog about Fink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: