Skip to content

Instantly share code, notes, and snippets.

@mshock
Created October 11, 2012 20:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshock/3875391 to your computer and use it in GitHub Desktop.
Save mshock/3875391 to your computer and use it in GitHub Desktop.
ppm install missing modules from exported csv
#! perl -w
# read exported ppm csv list and install all missing modules
use strict;
# first make sure everything is up to date
print "updating all installed modules...\n";
print `ppm upgrade --install`;
print "\ndone\n\n";
print "getting list of all installed modules...\n";
# get csv of all currently installed modules
my %local_mods = csv2hash(split "\n", `ppm list --csv --no-header`);
print "\ndone\n\n";
print "reading exported module csv...\n";
# read list of modules desired
open(CSV,'<', $ARGV[0] || 'ppm_list.csv');
my @remote_mods = <CSV>;
close CSV;
print "\ndone\n\n";
print "installing all missing modules...\n";
# check each module
for my $line (@remote_mods){
chomp $line;
my ($name,$version,$files,$area) = split ',', $line;
# install if not found
unless ($local_mods{$name}) {
$name =~ s/-/::/g;
print "\tinstalling $name\n";
print `ppm install $name`;
}
}
print "\ndone\n\n";
# convert ppm csv to hash of package_name => version #
sub csv2hash {
my @csv = shift;
my %hash;
for my $line (@csv) {
chomp $line;
my ($name,$version,$files,$area) = split ',', $line;
# if not site specific, skip it
next if $area ne 'site';
$hash{$name} = $version;
}
return %hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment