stow/tdw-experimental/gnu-install

102 lines
3.5 KiB
Text
Raw Permalink Normal View History

2009-07-04 21:09:33 -04:00
#!/usr/bin/env perl
use strict;
use warnings;
use DBI;
#### Begin Section: Useful webpages
# http://directory.fsf.org/GNU/ Directory of GNU software
# http://sql-info.de/mysql/examples/Perl-DBI-examples.html
# http://mailliststock.wordpress.com/2007/03/01/sqlite-examples-with-bash-perl-and-python/
#### End Section: Useful webpages
2009-07-17 00:14:10 -04:00
my $TAR_COMMAND = 'tar --verbose --extract --file';
my $DATABASE = 'gnu.db';
2009-07-04 21:09:33 -04:00
2009-07-17 00:14:10 -04:00
my $dbh = DBI->connect("dbi:SQLite:$DATABASE", "", "", {RaiseError => 1, AutoCommit => 1});
2009-07-04 21:09:33 -04:00
# su -c 'aptitude install libdbd-sqlite3-perl' on a Debian system TDW 2009-04-19
&print_software;
2009-07-05 18:52:34 -04:00
if ( defined($ARGV[0])) {
&stow_gnu_software($ARGV[0]);
}
2009-07-04 21:09:33 -04:00
################################################ Subroutines only below this line ############################
sub stow_gnu_software {
my ( $software ) = @_;
print "\t$software\n";
# $dbh->do("CREATE TABLE gnu_software (id INTEGER PRIMARY KEY, short_name TEXT UNIQUE, name TEXT, latest_version TEXT, date_checked DATE )");
my $sth_id = $dbh->prepare("SELECT id, latest_version FROM gnu_software WHERE short_name = \'$software\'");
$sth_id->execute();
my ($software_id, $version) = $sth_id->fetchrow_array();
print "$software => $version\n";
# Given software short name, get id
# Given id, get version
my $all = $dbh->selectall_arrayref("SELECT * FROM mirror_url");
foreach my $row (@$all) {
my ($software_id, $country_id, $region_id, $url, $date_checked ) = @$row;
}
my $sth = $dbh->prepare('SELECT url FROM mirror_url WHERE id = ?');
$sth->execute(1);
my $url = $sth->fetchrow_array();
my $sth2 = $dbh->prepare('SELECT directory, latest_tarball FROM latest_tarball WHERE gnu_software_id = ?');
$sth2->execute($software_id);
my ( $directory, $tarball ) = $sth2->fetchrow_array;
2009-07-10 00:37:31 -04:00
&download_tarball( $directory, $tarball, $url );
2009-07-10 00:19:38 -04:00
sub download_tarball {
2009-07-10 00:37:31 -04:00
my ( $directory, $tarball, $url ) = @_;
my $download_command = '';
2009-07-10 00:19:38 -04:00
if ( $tarball ne 'OVERRIDE' ) {
2009-07-10 00:37:31 -04:00
$download_command = "wget --no-clobber ${url}${directory}/$tarball";
2009-07-10 00:19:38 -04:00
} else {
2009-07-10 00:37:31 -04:00
$download_command = "wget --no-clobber http://www.mpfr.org/mpfr-current/mpfr-2.4.1.tar.bz2";
2009-07-10 00:19:38 -04:00
}
2009-07-10 00:37:31 -04:00
print "==== $download_command ====\n";
2009-07-10 00:19:38 -04:00
system ("$download_command");
2009-07-17 00:14:10 -04:00
system ("$TAR_COMMAND $tarball");
2009-07-10 00:19:38 -04:00
}
2009-07-10 00:37:31 -04:00
2009-07-04 21:09:33 -04:00
chdir ("$software-$version");
2009-07-17 00:14:10 -04:00
open(OUT, ">stow-$software-$version.sh");
system("./configure --help=short > stow.$software-$version.help.short");
print OUT <<"END";
#!/bin/bash
set -o errexit
VERSION=\'$version\'
do_configure () {
./configure --prefix=/usr/local
}
do_build () {
make
sudo make DESTDIR=/stow/$software-\$\{VERSION\} install
}
do_package () {
cd /stow
sudo tar -cjvf $software-\$\{VERSION\}.stow.tar.bz2 $software-\$\{VERSION\}
sudo mkdir --parent STOWBALLS
sudo mv --verbose $software-\$\{VERSION\}.stow.tar.bz2 STOWBALLS
echo "Remember to stow and /sbin/ldconfig"
}
do_configure
do_build
do_package
END
2009-07-04 21:09:33 -04:00
close(OUT);
}
sub print_software {
print "=================================== Table gnu_software =================================\n";
# $dbh->do("CREATE TABLE gnu_software (id INTEGER PRIMARY KEY, short_name TEXT UNIQUE, name TEXT, latest_version TEXT, date_checked DATE )");
my $all = $dbh->selectall_arrayref("SELECT * FROM gnu_software ORDER BY short_name");
foreach my $row (@$all) {
my ($id, $short_name, $name, $latest_version, $date_checked ) = @$row;
print "$short_name\t$latest_version v.$latest_version\t$name\n";
}
}