tools/update-packaging/unwrap_full_update.pl
author Mike Hommey <mh+mozilla@glandium.org>
Wed, 26 Nov 2014 16:04:25 +0900
changeset 217581 5f1b17ceebe48984dc35c0de46f8c325931479ab
parent 94475 f4157e8c410708d76703f19e4dfb61859bfe32d8
child 371966 f632eede0f19b8d81ee2bb0de48c2cc996d5906f
permissions -rwxr-xr-x
Bug 1094565 - Update sccache to e68dfc2. r=mshal

#!/usr/bin/perl -w
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

#
# This tool unpacks a full update package generated by make_full_update.sh
# Author: Benjamin Smedberg
#

# -----------------------------------------------------------------------------
# By default just assume that these tools exist on our path

use Getopt::Std;

my ($MAR, $BZIP2, $archive, @marentries, @marfiles);

if (defined($ENV{"MAR"})) {
    $MAR = $ENV{"MAR"};
}
else {
    $MAR = "mar";
}

if (defined($ENV{"BZIP2"})) {
    $BZIP2 = $ENV{"BZIP2"};
}
else {
    $BZIP2 = "bzip2";
}

sub print_usage
{
    print "Usage: unwrap_full_update.pl [OPTIONS] ARCHIVE\n\n";
    print "The contents of ARCHIVE will be unpacked into the current directory.\n\n";
    print "Options:\n";
    print "  -h show this help text\n";
}

my %opts;
getopts("h", \%opts);

if (defined($opts{'h'}) || scalar(@ARGV) != 1) {
    print_usage();
    exit 1;
}

$archive = $ARGV[0];
@marentries = `"$MAR" -t "$archive"`;

$? && die("Couldn't run \"$MAR\" -t");

shift @marentries;

system("$MAR -x \"$archive\"") == 0 || die "Couldn't run $MAR -x";

foreach (@marentries) {
    tr/\n\r//d;
    my @splits = split(/\t/,$_);
    my $file = $splits[2];

    system("mv \"$file\" \"$file.bz2\"") == 0 ||
      die "Couldn't mv \"$file\"";
    system("\"$BZIP2\" -d \"$file.bz2\"") == 0 ||
      die "Couldn't decompress \"$file\"";
}