#!/usr/bin/perl -w

use strict;

# from http://hyperstruct.net/projects/spock
my $spockexe = `/usr/bin/which spock 2>/dev/null` || "/opt/spock/spock";
chomp ($spockexe);

# directory that contains key3.db
my $keydirectory = "/home/www/libxprivatekey";
my $xpiguid = "{d75de36c-af0d-4dc2-b63a-0d482d4b9815}";
my $libxextid = "urn:mozilla:extension:" . $xpiguid;

# directory to which built files are output
my $fs_base_dir = "/home/www/libx.org/releases/";
my $updatepath = $fs_base_dir . "ff";

my $src_xpifile = $ARGV[0];
my $src_update_rdf = $ARGV[1];

-f $src_xpifile || die "arg1: xpi file $src_xpifile does not exist";
-f $src_update_rdf || die "arg2: source update.rdf $src_update_rdf does not exist";

-x $spockexe || die "$spockexe does not exist or is not executable.";
my $cmd = "$spockexe -d $keydirectory -i \"$libxextid\"" 
    . " -f $src_xpifile"
    . " $src_update_rdf > $updatepath/update.rdf";

print $cmd . "\n";

system($cmd) == 0 || die "could not run spock to sign update.rdf: $!";
