/*
 * tardy - a tar post-processor
 * Copyright (C) 2012, 2013 Peter Miller
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

dpkg-arch = [collect dpkg-architecture -qDEB_BUILD_ARCH];
apt-package-list = ;

function apt-get-package =
{
    if [matches lib%-dev [@1]] then
    {
        local vp = [fromto lib%-dev lib%-.*-dev [@1]];
        if [not [collect dpkg -l | grep "'^ii  "[vp]" '" |
            wc -l || true]] then
        if [not [collect dpkg -l | grep "'^ii  "[vp]":"[dpkg-arch]" '" |
            wc -l || true]] then
        if [not [collect dpkg -l | grep "'^ii  "[@1]" '" |
            wc -l || true]] then
        if [not [collect dpkg -l | grep "'^ii  "[@1]":"[dpkg-arch]" '" |
            wc -l || true]] then
        apt-package-list += [@1];
    }
    else
    {
        if [not [collect dpkg -l | grep "'^ii  "[@1]" '" | wc -l || true]] then
            apt-package-list += [@1];
    }
}

/*
 * Make sure the packages we need are present.
 */
if [matches %1C%2 [version]] then
{
    if [find_command apt-get] then
    {
        function apt-get-package autoconf;
        function apt-get-package automake;
        function apt-get-package build-essential;
        function apt-get-package coreutils; /* ptx, md5sum */
        function apt-get-package cpio;
        function apt-get-package debhelper;
        function apt-get-package devscripts; /* debuild cmd */
        function apt-get-package doxygen;
        function apt-get-package dpkg-dev; /* dpkg-buildpackage cmd */
        function apt-get-package exuberant-ctags; /* ctags cmd */
        function apt-get-package gawk;
        function apt-get-package ghostscript; /* ps2pdf */
        function apt-get-package groff;
        function apt-get-package libboost-dev;
        function apt-get-package libbz2-dev;
        function apt-get-package libexplain-dev;
        function apt-get-package liblzma-dev;
        function apt-get-package lintian;
        function apt-get-package tar;
        function apt-get-package zlib1g-dev;

        if [count [apt-package-list]] then
        {
            sudo apt-get install -y --allow-unauthenticated
            [apt-package-list] < /dev/tty > /dev/tty 2>&1
                || true                                           set no-silent;
        }
    }
}


/* vim: set ts=8 sw=4 et : */
