#!/usr/bin/perl # Copyright (C) Jeremiah C. Foster 2009, based on: # Lintian -- Debian package checker # Copyright (C) 1998 Christian Schwarz and Richard Braakman =head1 NAME minimae - Executes some tests on a gzipped tarball, looking for debian packaging files and conventions. minimae gets a json string as input and parses that string to do its checks and find resources. =cut =head1 VERSION This document describes minimae version 2.0 =head1 PURPOSE Maemian is the maemo version of lintian - a policy checker designed to assure the quality of a package uploaded into the maemo.org repositories. The goal of maemian is to improve quality by checking that the maemo packaging policy is followed. In order to do that it reads files in the tarball that has been uploaded to the maemo repositories. =head1 SYNOPSIS # Check tarball minimae -i file.deb =cut use strict; use warnings; use Test::More tests => 8; use IPC::System::Simple qw/ capture /; use feature ":5.10"; use Control; use Archive::Tar; use Perl6::Slurp; use RepoUtils; use File::Basename; use Parson; # find our tarball my $json_object = Parson->new(); # parse json file my $dsc = $json_object->parse_json(); my $tarball = $ARGV[0]; # Orignal tarball my $repo = RepoUtils->new(); $repo->copy_file($tarball, "lab/"); # copy the tarball to the lab my $package_name = basename $tarball; my $tar = Archive::Tar->new; $tar->read("lab/$package_name",1); if ($package_name =~ /orig.tar.gz/) { $package_name =~ s/.orig.tar.gz$//; # Remove suffixes } else { $package_name =~ s/.tar.gz$//; # Remove suffixes } $package_name =~ tr/_/-/; # translate underscore into dash $package_name =~ s/-[\d]$//; # trim package version $package_name =~ s/-.?maemo.$//; # trim maemo version chdir("lab/"); # We're in /lab now! $tar->extract(); # extracted tarball now in lab/ my $changelog_file = "$package_name/debian/changelog"; my $copyright_file = "$package_name/debian/copyright"; my $control_file = "$package_name/debian/control"; # Check control file my $file_type = capture("file -i $control_file"); ok(($file_type), "File type defined."); my ($name, $content, $charset) = split / /, $file_type; chomp($charset); given($charset) { when ("charset=us-ascii") { ok($charset, 'charset is ASCII.'); } when ("charset=utf-8") { ok($charset, 'charset is UTF-8'); } default { not_ok($charset, "$charset"); die qq(Unknown charset for $charset.); } } # Each chunk is a discreet package my @chunks = slurp $control_file, {irs => qr/\n\n/xms}; print map { $_ . "\n" } @chunks; my @fields = slurp $control_file, {irs => qr/\n\n/xms}; diag((grep /XB-Maemo-Icon/, split /\n/, $fields[-1]), ' Found icon in control file.'); my @arches = grep /Architecture/, split /\n/, $fields[-1]; ok((grep /Architecture/, split /\n/, $fields[-1]), "Arches: $arches[-1]"); ok((grep /XSBC/, @fields), 'Maemo specific maintainer field'); my $package = grep /Package:/, split /\n/, $fields[-1]; ok($package !~ /[M|m]aemo/, 'No potential copyright clash with maemo name'); # Check copyright file ok(-s $copyright_file, 'Copyright file exists and is non-empty'); @fields = slurp $copyright_file, {irs => qr/\n\n/xms}; my ($file_name, $type) = split / /, capture("file -i $copyright_file"); ok($file_type !~ /application\/x-gzip/, 'Copyright not compressed.'); my @copylines = map { $_ } grep /copyright|\(C\)/, @fields; ok((scalar @copylines > 1), 'Found copyright assignment.'); # check changelog 1; # Nothing to see here, move along.