From 290a99cef54edfd8b54349cfe658450f14d69134 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 30 Oct 2008 13:51:08 +0100 Subject: bin/pkg: check_prereqs: Added require() for less redundancy --- bin/pkg | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/pkg b/bin/pkg index 3816b4c..427f13f 100755 --- a/bin/pkg +++ b/bin/pkg @@ -295,22 +295,35 @@ function check_prereqs { cd $PDIR/$package info "checking prerequisites\n" typeset -a install + typeset warn - is_installed () { + function is_installed { [[ -d $PDIR/$1 ]] } - perlmodule () { + function perlmodule { perl -M$1 < /dev/null 2> /dev/null } - file_in_path () { + function file_in_path { which $1 > /dev/null } - offer_install () { + function offer_install { install+=$1 } + function require { + if [[ $1 == 'package' ]] { + is_installed $2 || offer_install $2 + } else { + $* || warn+="Requirement failed: $*\n" + } + } source prereqs + if [[ -n $warn ]] { + warn $warn + read -q + } + if [[ -n $install ]] { info "$1 requires the following packages: $install\n" if (confirm_yes "Install them?") { -- cgit v1.2.3