#!/bin/bash
if [ $# -ne 1 ]
then
>&2 echo "Verwendung: neuesPerlPaket cpan-Name"
exit 1
fi
substituiere() {
erg="$(
cat "$(dirname "${me}")/perlSubstitutionen" | \
sed 's|#.*$||' | \
grep "\s$1\(\s\|\$\)" | \
cut -d ':' -f 1
)"
[ -z "${erg}" ] && erg="$1"
key="${erg}"
}
cpanName="$(echo "$1" | sed 's|::|-|g')"
url="https://metacpan.org/release/${cpanName}"
pkgname="perl-${cpanName,,}"
me="$(readlink -f "$0")"
cd "$(dirname "${me}")"
if [[ "$1" == "perl-"* ]]
then
>&2 echo "${1} beginnt mit 'perl-', sollte es aber nicht"
exit 1
fi
if [ -e "${pkgname}" ] || pacman -Ss "${pkgname}" > /dev/null
then
>&2 echo "${cpanName} gibt es womöglich schon"
exit 1
fi
seitenInhalt="$(curl -o - "${url}" 2> /dev/null)"
pkgver="$(
echo "${seitenInhalt}" | \
grep "
${cpanName}-" | \
sed "s|^.*${cpanName}-\([0-9.-]\+\)\s.*|\1|"
)"
pkgdesc="$(
echo "${seitenInhalt}" | \
grep "${cpanName}-" | \
sed "s|^.*${cpanName}-[0-9.-]\+\s\+-\s\+\(\S.*\S\)\s\+-\s\+metacpan\.org.*|\1|" | \
sed "s|'|'\"'\"'|g"
)"
dlUrl="$(
echo "${seitenInhalt}" | \
grep "href=\"https://cpan.metacpan.org/authors/id/[^/]/[^/]\{2\}/[^/]\+/${cpanName}-[0-9.]\+\.tar\.gz\">" | \
sed "s|^.*href=\"\(https://cpan.metacpan.org/authors/id/[^/]/[^/]\{2\}/[^/]\+/${cpanName}-[0-9.]\+\.tar\.gz\)\">.*\$|\1|" | \
tail -n1
)"
dlUrlForPKGBUILD="$(
echo "${dlUrl}" | \
sed "s|/${cpanName}-[0-9.]\+\.tar\.gz|/\${_distdir}.tar.gz|"
)"
mkdir "${pkgname}"
cd "${pkgname}"
wget -nd "${dlUrl}"
sha512sum="$(
sha512sum "${cpanName}-${pkgver}.tar.gz" | \
cut -d " " -f 1
)"
oifs="${IFS}"
IFS=''
wasSammeln=''
unset makedepends
unset conflicts
unset depends
unset provides
while read s
do
if [[ "${s}" == " "* ]]
then
key="$(
echo "${s}" | \
sed "s|^\s*\(\S\+\):\s\+'\?\([^']\+\)'\?\$|\1|" | \
sed "s|::|-|g" | \
tr "[[:upper:]]" "[[:lower:]]"
)"
substituiere "${key}"
[ "${key}" == "%skip" ] && continue
key="perl-${key}"
value="$(
echo "${s}" | \
sed "s|^\s*\(\S\+:\)\s\+'\?\([^']\+\)'\?\$|\2|" | \
sed "s|\s||g"
)"
if [ "${value}" == "0" ]
then
value=""
else
echo "${value}" | \
grep -q "<=" ||
value=">=${value}"
fi
case "${wasSammeln}" in
"build_requires:"|"configure_requires:")
makedepends="${makedepends} '${key}${value}'"
;;
"conflicts:")
conflicts="${conflicts} '${key}${value}'"
;;
"provides:")
echo "${s}" | \
grep -q "^ \S" && \
provides="${provides} '${key}'"
;;
"recommends:"|"requires:")
depends="${depends} '${key}${value}'"
;;
esac
else
case "${s}" in
"build_requires:"|"configure_requires:"|"conflicts:"|"recommends:"|"requires:"|"provides:")
wasSammeln="${s}"
;;
*)
wasSammeln=''
;;
esac
fi
done < <(tar -Oxzf "${cpanName}-${pkgver}.tar.gz" "${cpanName}-${pkgver}/META.yml")
IFS="${oifs}"
makedepends="${makedepends# }"
conflicts="${conflicts# }"
depends="${depends# }"
[ -z "${depends}" ] && depends="'perl'"
(
echo '# Maintainer: Erich Eckner '
echo '# Generator : neuesPerlPaket ('"$(sha512sum "${me}" | cut -d " " -f 1)"')'
echo ''
echo "pkgname='${pkgname}'"
echo "pkgver='${pkgver}'"
echo "pkgrel='1'"
echo "pkgdesc='${pkgdesc}'"
echo "arch=('x86_64' 'i686')"
echo "license=('PerlArtistic' 'GPL')"
echo "options=('!emptydirs')"
echo "depends=(${depends})"
[ -n "${makedepends}" ] && \
echo "makedepends=(${makedepends})"
[ -n "${conflicts}" ] && \
echo "conflicts=(${conflicts})"
echo "url='${url}'"
echo "_distdir=\"${cpanName}-\${pkgver}\""
echo "source=(\"${dlUrlForPKGBUILD}\")"
echo "sha512sums=('${sha512sum}')"
echo ''
echo 'build(){'
echo ' cd "${srcdir}/${_distdir}"'
echo ' '
echo " # Setting these env variables overwrites any command-line-options we don't want..."
echo ' export PERL_MM_USE_DEFAULT=1 PERL_AUTOINSTALL=--skipdeps \'
echo " PERL_MM_OPT=\"INSTALLDIRS=vendor DESTDIR='\${pkgdir}'\" \\"
echo " PERL_MB_OPT=\"--installdirs vendor --destdir '\${pkgdir}'\" \\"
echo ' MODULEBUILDRC=/dev/null'
echo ''
echo ' # If using Makefile.PL'
echo ' if [ -r Makefile.PL ]; then'
echo ' perl Makefile.PL'
echo ' make'
echo ' # If using Build.PL'
echo ' elif [ -r Build.PL ]; then'
echo ' perl Build.PL'
echo ' perl Build'
echo ' fi'
echo '}'
echo ''
echo 'check(){'
echo ' cd "${srcdir}/${_distdir}"'
echo ''
echo ' # If using Makefile.PL'
echo ' if [ -r Makefile.PL ]; then'
echo ' make test'
echo ' # If using Build.PL'
echo ' elif [ -r Build.PL ]; then'
echo ' perl Build test'
echo ' fi'
echo '}'
echo ''
echo 'package(){'
echo ' cd "${srcdir}/${_distdir}"'
echo ' '
echo ' # If using Makefile.PL'
echo ' if [ -r Makefile.PL ]; then'
echo ' make install'
echo ' # If using Build.PL'
echo ' elif [ -r Build.PL ]; then'
echo ' perl Build install'
echo ' fi'
echo ''
echo ' # remove perllocal.pod and .packlist'
echo ' find "${pkgdir}" -name .packlist -o -name perllocal.pod -delete'
echo '}'
) > PKGBUILD
makepkg -fcrs || exit 1
echo ''
echo 'sieht soweit erst mal gut aus, oder?'
read antwort
if [ -n "${antwort}" ]
then
echo 'ok, dann nicht ...'
exit 1
fi
pacman -Qlp ${pkgname}-*.pkg.tar.xz
echo ''
echo 'auch hier alles in Ordnung, oder?'
read antwort
if [ -n "${antwort}" ]
then
echo 'ok, dann nicht ...'
exit 1
fi
git add PKGBUILD
git commit -m "${pkgname} neu"