Files
obs-service-cpanspec/cpanspec

111 lines
2.2 KiB
Bash

#!/bin/bash
# A wrapper around cpanspec
#
# (C) 2010 by Stephan Kulow <coolo@suse.de>
#
# 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 2
# of the License, or (at your option) any later version.
# See http://www.gnu.org/licenses/gpl-2.0.html for full license text.
#defaults
SOURCE=""
FILTER_REQUIRES=""
FILTER_PROVIDES=""
ADD_REQUIRES=""
ADD_PROVIDES=""
ADD_BUILDREQUIRES=""
while test $# -gt 0; do
case $1 in
*-source)
if test -n "$SOURCE"; then
echo Source is defined twiced.
exit 1
fi
SOURCE="$2"
shift
;;
*-filter-requires)
FILTER_REQUIRES="$2"
shift
;;
*-filter-provides)
FILTER_PROVIDES="$2"
shift
;;
*-add-requires)
ADD_REQUIRES="$2"
shift
;;
*-add-provides)
ADD_PROVIDES="$2"
shift
;;
*-add-buildrequires)
ADD_BUILDREQUIRES="$2"
shift
;;
*-outdir)
MYOUTDIR="$2"
shift
;;
*)
echo Unknown parameter $1.
echo 'Usage: cpanspec --source $SOURCE --outdir $OUT'
exit 1
;;
esac
shift
done
if [ -z "$SOURCE" ]; then
SOURCE="*.tar.bz2"
fi
if [ -z "$MYOUTDIR" ]; then
echo "ERROR: no output directory is given via --outdir parameter!"
exit 1
fi
set -e
FILE=`readlink -f $SOURCE`
if test -z "$FILE"; then
echo There is no unique filename.
fi
BASENAME=`basename $FILE | sed -e 's,.*:\([^:]*\)$,\1,'`
TMPOUT=`mktemp -d`
ln -s $FILE $TMPOUT/$BASENAME
cdir=$PWD
cd $TMPOUT
call=cpanspec
if test -n "$FILTER_REQUIRES"; then
call="$call --filter-requires '$FILTER_REQUIRES'"
fi
if test -n "$FILTER_PROVIDES"; then
call="$call --filter-provides '$FILTER_PROVIDES'"
fi
if test -n "$ADD_REQUIRES"; then
call="$call --add-requires '$ADD_REQUIRES'"
fi
if test -n "$ADD_PROVIDES"; then
call="$call --add-provides '$ADD_PROVIDES'"
fi
if test -n "$ADD_BUILDREQUIRES"; then
call="$call --add-buildrequires '$ADD_BUILDREQUIRES'"
fi
$call -f -- "$BASENAME"
cd $cdir
# do not copy stub
rm -f -- $TMPOUT/*.changes
rm -- "$TMPOUT/$BASENAME"
# copy the rest
mv -- $TMPOUT/* "$MYOUTDIR"
exit 0