summaryrefslogtreecommitdiff
path: root/bumpVersion
blob: d4b91df1607d8d688b3ee5fec7411762a05c411b (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
#!/bin/bash

me="$(readlink -f "$0")"
myDir="$(dirname "${me}")"

verwendung() {
  >&2 echo ''
  >&2 echo "$(basename "$0")"': aktualisiere Version von Paketen in archlinuxewe'
  >&2 echo ''
  >&2 echo 'mögliche Optionen:'
  >&2 echo '  -f|--force:            übergehe Cache'
  >&2 echo '  -h|--help:             zeige diese Hilfe'
  >&2 echo '  -n|--nicht $paket:     ignoriere Paket $paket'
  >&2 echo '  -p $tmpfile:           temporäre "provided"-Datei'
  [ -z "$1" ] && exit 1 || exit $1
}

check_version_cache_option=''

eval set -- "$(
  getopt -o fhn:p: \
    --long force \
    --long help \
    --long nicht: \
    -n "$(basename "$0")" -- "$@" || \
    echo verwendung
)"

unset nichtPakete
unset provided

while true; do
  case "$1" in
    -h|--help)
      verwendung 0
    ;;
    -f|--force)
      check_version_cache_option='--no-cache'
    ;;
    -n|--nicht)
      shift
      nichtPakete="$(printf '%s\n%s' "${nichtPakete}" "$1" | grep -v '^$')"
    ;;
    -p)
      shift
      provided="$1"
    ;;
    --)
      shift
      break
    ;;
    *)
      >&2 echo 'Hups, das sollte nicht passieren können, Option '"$1"' kenne ich doch nicht ...'
      exit -1
  esac
  shift
done

if [ $# -eq 0 ]; then
  >&2 echo 'bumping versions of all packages ...'
  pkgs="$(
    (
      "${myDir}/checkVersions" --noUpdate | \
        cut -d: -f1
      echo "${nichtPakete}"
      echo "${nichtPakete}"
    ) | \
      sort | \
      uniq -u
  )"
  [ -z "${pkgs}" ] && exit 0
  if [ -z "${provided}" ]; then
    provided=$("${myDir}/liste-verfuegbare-Versionen") || exit $?
    trap 'rm -f "${provided}"' EXIT
  fi
  "${me}" -p "${provided}" ${pkgs}
  exit $?
elif [ $# -gt 1 ]; then
  [ -n "${nichtPakete}" ] && verwendung
  if [ -z "${provided}" ]; then
    provided=$("${myDir}/liste-verfuegbare-Versionen") || exit $?
    trap 'rm -f "${provided}"' EXIT
  fi
  err=0
  for pkg in "$@"; do
    "${me}" -p "${provided}" "${pkg}"
    cErr=$?
    [ ${cErr} -gt ${err} ] && err=${cErr}
  done
  exit ${err}
fi
[ -n "${nichtPakete}" ] && verwendung

if [ -z "${provided}" ]; then
  provided=$("${myDir}/liste-verfuegbare-Versionen") || exit $?
  trap 'rm -f "${provided}"' EXIT
fi

paket="${1%/}"
>&2 echo "bumping '${paket}' ..."

cd "${myDir}"
[ -r "${paket}/PKGBUILD" ] || exit 1
if ! vers="$(./checkVersions -m "${paket}" ${check_version_cache_option})"; then
  >&2 echo 'checkVersion returned non-zero'
  exit 1
fi
[ -n "${remVer}" ] && vers="$(echo "${vers}" | grep -v 'remVer')"
eval ${vers}
if [ "${remVer}" == "${pkgver}" ]; then
  >&2 echo '... nothing to do here.'
  exit 0
fi

if [ -z "${remVer}" ]; then
  >&2 echo '... remote Version not determined.'
  exit 0
fi

cd "${paket}"

exec 9> "build.lock"
printf 'getting lock for bumpVersion %s\n' "$(pwd)"
flock 9
printf 'got lock for bumpVersion %s\n' "$(pwd)"

# Wir misbrauchen bumpPkgrel um _pinned_dependencies zu aktualisieren.
# $pkgrel wird nachher ohnehin wieder auf 1 gesetzt.
"${myDir}/bumpPkgrel" -n -p "${provided}" "${paket}"

auto_summen=true

if [ "${paket}" = 'local-certificates' ]; then
  sums=$(
    curl -Ss 'https://eckner.net/certs/sha512sums'
  )
  sed_extra='
    /^source=/ i source=(\
'"$(
      printf '%s\n' "${sums}" \
      | sed '
        s@^\S\+  @  '"'"'https://eckner.net/certs/@
        s/$/'"'"'\\/
      '
    )"'
)\
sha512sums=(\
'"$(
      printf '%s\n' "${sums}" \
      | sed '
        s/  .*$/'"'"'\\/
        s/^/  '"'"'/
      '
    )"'
)
    /^source=/,/)$/ d
    /^sha512sums=/,/)$/ d
  '
  auto_summen=false
elif [ "${paket}" = 'otf-grundschrift' ]; then
  md5sum=$(
    curl -LSs 'https://fontlibrary.org/en/font/grundschrift' \
    | sed '
      s@^.*<a href="/assets/downloads/grundschrift/\([0-9a-f]\{32\}\)/grundschrift\.zip" .*$@\1@
      t
      d
    '
  )
  sed_extra='
    s@^\s*md5sums=(\S\+).*$@md5sums=('"'${md5sum}'"')@
'
  auto_summen=false
fi

sed -i 's|^\(\s*\)pkgver=.*$|\1pkgver='"${remVer}"'|;
  s|^\(\s*\)pkgrel=.*$|\1pkgrel=1|;
  '"${sed_extra}"'
' PKGBUILD

if ${auto_summen}; then
  sed -i '
    s@^\s*\(sha[[:digit:]]\+sums\|md5sums\)=@sha512sums=@;
    /^\(sha[[:digit:]]\+\|md5\)sums_/d;
  ' PKGBUILD

  sed '
    :begin;
      $!N;
      s@^sha512sums=\([^)]*\)\n\(.*\)$@sha512sums=\1 \2@;
    tbegin;
    P;
    D
  ' -i PKGBUILD

  summen="$( \
    makepkg -g | \
      sed ':begin;
          $!N;
          s@^\(.*\)\n\(.*\)$@\1\\n\2@;
        tbegin;
        P;
        D
      ' \
  )"
  sed 's|sha512sums=.*$|'"${summen}"'|' -i PKGBUILD
fi

(
  if ! yes '' | "${myDir}/testeAbhaengigkeiten" "${paket}"; then
    was=''
    ec[0]='jJyY'
    ec[1]='nN'
    while [[ "${ec[0]}" != *"${was}"* ]] && [[ "${ec[1]}" != *"${was}"* ]] || [ -z "${was}" ]; do
      read -p 'Trotzdem weiter machen (j/y/n)? ' was
    done
    [[ "${ec[0]}" == *"${was}"* ]]
  fi
) || exit $?

rm -rf "src" "pkg"
sudo pacman -Sy
../addPkgbuildPatch add
makepkg -fcsr --noconfirm --asdeps || {
  err=$?
  tty -s || git checkout PKGBUILD
  exit ${err}
}
../addPkgbuildPatch del
../commit-package "${paket} ${pkgver}-${pkgrel} -> ${remVer}-1"

>&2 echo '... done'