summaryrefslogtreecommitdiff
path: root/neuesPerlPaket
blob: 0a7c1882181561cdab5ccca3c868a1a2ce9de1ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/bin/bash

if [ $# -ne 1 ]
then
  >&2 echo "Verwendung: neuesPerlPaket cpan-Name"
  exit 1
fi

substituiere() {
  dep="$1"
  name=${dep%>=*}
  dep=${dep#${name}}
  erg="$(
    cat "$(dirname "${me}")/perlSubstitutionen" | \
      sed 's|#.*$||' | \
      grep "\s${name}\(\s\|\$\)" | \
      sed "s|^\([^:]\+\):.*\$|perl-\1|" | \
      sed "s|^:.*\$|perl|"
  )"
  [ -z "${erg}" ] && erg="perl-${name}"
  if [ "${erg}" == "perl" ] && echo "${dep}" | grep -q "^[^.]*\.\(0[[:digit:]]\{2\}\)\{2\}"
  then
    dep="$(
      echo "${dep}" | \
        sed "s@^\([^.]*\....\)0\+@\1.@; s@^\([^.]*\.\)0\+@\1@"
    )"
  fi
  erg="${erg}${dep}"
}

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}" ]
then
  >&2 echo "${cpanName} gibt es von ewe schon"
  exit 1
fi

if cat $(ls /var/lib/pacman/sync/*.db | grep -v "/archlinuxewe\.db\$") | \
  tar -Oixz --wildcards "*/desc" | \
  sed '
    :begin;
      $!N;
      s@^\(%[^%]*%.*\)\n\(.\+\)$@\1 \2@;
    tbegin;
    P;
    D
  ' | \
  grep -q "^%\(NAME% ${pkgname}\|PROVIDES%.* ${pkgname}\([= ].*\)\?\)\$"
then
  >&2 echo "${cpanName} gibt es schon offiziell"
  exit 1
fi

seitenInhalt="$(curl -o - "${url}" 2> /dev/null)"

pkgver="$(
  echo "${seitenInhalt}" | \
    grep "<title>${cpanName}-" | \
    sed "s|^.*<title>${cpanName}-\([0-9.-]\+\)\s.*|\1|"
)"

pkgdesc="$(
  echo "${seitenInhalt}" | \
    grep "<title>${cpanName}-" | \
    sed "s|^.*<title>${cpanName}-[0-9.-]\+\s\+-\s\+\(\S.*\S\)\s\+-\s\+metacpan\.org</title>.*|\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
)"

echo "META.yml lesen ..."

oifs="${IFS}"

meta="$(
  tar -Oxzf "${cpanName}-${pkgver}.tar.gz" "${cpanName}-${pkgver}/META.yml" | \
    grep -v "^    file:" | \
    grep -v "^    version:" | \
    sed '
      :begin;
        $!N;
        s@^\(\S.*\)\n\s\+\(\S.*\)$@\1 \2@;
      tbegin;
      P;
      D
    ' | \
    sed "/^provides: /s@:\(\s\|\$\)@: '0'\1@g" | \
    sed "s|^provides: '0' |provides: |"
)"

echo "... fertig, verarbeiten ..."

declare -A metaInfos
declare -A metaRegexe
declare -A metaSubst

metaRegexe["makedepends"]="\(build\|configure\)_requires"
metaSubst["makedepends"]=true
metaRegexe["depends"]="requires"
metaSubst["depends"]=true
metaRegexe["optdepends"]="recommends"
metaSubst["optdepends"]=true
metaRegexe["conflicts"]="conflicts"
metaSubst["conflicts"]=true
metaRegexe["provides"]="provides"
metaSubst["provides"]=false

for sucheWonach in "${!metaRegexe[@]}"
do
  metaInfos["${sucheWonach}"]=""
  for was in $(
    echo "${meta}" | \
      grep "^${metaRegexe["${sucheWonach}"]}:" | \
      sed "s@^${metaRegexe["${sucheWonach}"]}:\s*@@" | \
      sed "s@\(\S\+\):\s\+'\?\([0-9.]*\)'\?\(\s\|\$\)@\L\1>=\L\2\n@g" | \
      sed "s@::@-@g" | \
      sed "s|>=0\$||" | \
      grep -v "^\({}\)\?$"
  )
  do
    if ${metaSubst["${sucheWonach}"]}
    then
      substituiere "${was}"
    else
      erg="perl-${was}"
    fi
    [[ "${erg}" == "perl-%skip"* ]] ||
      metaInfos["${sucheWonach}"]="${metaInfos["${sucheWonach}"]} '${erg}'"
  done
  metaInfos["${sucheWonach}"]="${metaInfos["${sucheWonach}"]# }"
done

echo "... fertig"

(
  echo '# Maintainer: Erich Eckner <arch at eckner dot net>'
  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')"
  for wasAusgeben in "${!metaRegexe[@]}"
  do
    if [ -n "${metaInfos["${wasAusgeben}"]}" ]
    then
      echo "${wasAusgeben}=("
      echo "${metaInfos["${wasAusgeben}"]})" | \
        tr " " "\n" | \
        sed "s|^|  |"
    fi
  done
  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"