summaryrefslogtreecommitdiff
path: root/perlFunktionen
blob: 5e631dc55af86f088cce78728dd926d57a780006 (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
#!/bin/bash

set -e

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}"
}

versionsUniq() {
  tr ' ' '\n' | \
  sed 's|^perl$|perl>=0|' | \
  sort -rV | \
  sed 's@^\([^<=>]*\)\(\(>=\|=\|<\)[0-9.]*\)$@\1\2 \1@' | \
  sed 's|^\(\S*\)$|\1 \1|' | \
  uniq -f1 "$@" | \
  awk '{print $1}' | \
  sed 's|^perl>=0$|perl|' | \
  sort | \
  grep -v '^\s*$'
}

ladePkgbuild() {
  paket="$1"

  if [[ "${paket}" != "perl-"* ]]
  then
    return 1
  fi

  cd "$(dirname "${me}")"
  cd "${paket}"

  makepkg -f --verifysource

  . PKGBUILD
}

versteheMetaYml() {
  archiv="${_distdir}.tar.gz"
  [ -r "${archiv}" ] || archiv="${_distdir}.tgz"

  if [ ! -r "${archiv}" ]
  then
    >&2 echo "Kann Quelldatei nicht finden!"
    return 2
  fi

  if ! tar -tzf "${archiv}" "${_distdir}/META.yml"
  then

    unset meta

  else

    echo "META.yml lesen ..."

    meta="$(
      tar -Oxzf "${archiv}" "${_distdir}/META.yml" | \
        tr '\r' ' ' | \
        grep -v "^\s*file:" | \
        grep -v "^version:" | \
        sed '
          :begin;
            $!N;
            s@^\(\S.*\)\n\s\+\(\S.*\)$@\1 \2@;
          tbegin;
          P;
          D
        ' | \
        sed "/^provides: /s@\(\s\S\+\):\s\+version:\s\+'\?v\?\([0-9.]\+\)'\?@\L\1=\2@g" | \
        sed "/^provides: /s@\s@  @g" | \
        sed "/^provides: /s@\(\s[^= ]\+\):\+\(\s\|\$\)@\L\1=${pkgver}\2@g" | \
        sed "s@\(\sperl:\s\+\)'\?\([[:digit:]]\+\)\.\([[:digit:]]\{3\}\)'\?\(\s\|\$\)@\1\2.\3.0\4@" | \
        sed "s@\(\sperl:\s\+\)'\?\([[:digit:]]\+\)\.\([[:digit:]]\{3\}\)\([[:digit:]]\+\)'\?\(\s\|\$\)@\1\2.\3.\4\5@" | \
        sed "s@\(\sperl:\s\+\)'\?\([[:digit:]]\+\)[._]0*\([1-9][[:digit:]]*\)[._]0*\([1-9][[:digit:]]*\)'\?\(\s\|\$\)@\1\2.\3.\4\5@" | \
        sed "s@\(\sperl:\s\+\)'\?\([[:digit:]]\+\)[._]0*\([1-9][[:digit:]]*\)[._]0\+'\?\(\s\|\$\)@\1\2.\3.0\4@"
    )"

    echo -n "... fertig, "

  fi

  echo "verarbeiten ..."

  set +e

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

  err=false

  for wasAusgeben in "${!metaRegexe[@]}"
  do
    eval tmp=( '"${'${wasAusgeben}'[@]}"' )
    pkgBuild["${wasAusgeben}"]="$(
      echo "${tmp[@]}" | \
        tr " '" '\n\n' | \
        grep -v '^$' | \
        sort -u
    )"
    if [ -z "${pkgBuild["${wasAusgeben}"]}" ] && \
      [ "${wasAusgeben}" == "depends" ]
    then
      pkgBuild["${wasAusgeben}"]="perl"
    fi

    metaYml["${wasAusgeben}"]="$(
      (
        echo "${metaInfos["${wasAusgeben}"]}" | \
          grep -v '^$' | \
          grep '^\s*perl'
        echo "${pkgBuild["${wasAusgeben}"]}" | \
          grep -v '^\s*perl'
      ) | \
        versionsUniq
    )"
    if [ -z "${metaYml["${wasAusgeben}"]}" ] && \
      [ "${wasAusgeben}" == "depends" ]
    then
      metaYml["${wasAusgeben}"]="perl"
    fi
    if [ "${wasAusgeben}" == "makedepends" ]
    then
      metaYml["${wasAusgeben}"]="$(
        (
          (
            (
              echo "${metaYml["${wasAusgeben}"]}"
              echo "${metaYml["depends"]}"
            ) | \
              versionsUniq
            echo "${metaYml["depends"]}"
          ) | \
            sort | \
            uniq -d | \
            sed 'p'
          echo "${metaYml["${wasAusgeben}"]}"
        ) | \
          versionsUniq -u
      )"
    fi
  done
  echo "... fertig"
}

mangle_versions() {
  local pre
  local post
  if [ $# -eq 1 ]; then
    pre="s|^|$1=|"
    post='s|^[^=]*=||'
  fi
  sed "${pre}"'
    /^perl-extutils-makemaker[<>=]/{
      s|\.\([0-9][0-9]\)\([0-9]\+\)|.\1.\2|
    }
  '"${post}"
}

declare -A metaInfos
declare -A metaRegexe
declare -A metaSubst
declare -A metaYml
declare -A pkgBuild

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