summaryrefslogtreecommitdiff
path: root/update.sh
blob: 10fbca20116cab60bb55b6cffac6c39f65a04a39 (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
#!/bin/bash

if [ $# -eq 0 ]; then
  /usr/src/ports/lastVersion.sh \
  | sed -n '
    s@ \(upstream verfügbar, bei mir\|vs\.\) \(\S\+\)$@@
    T
    p
  ' \
  | while read package new_version old_version; do
    printf '%s\n' "${old_version}" "${new_version}" \
    | sort -V \
    | tail -n1 \
    | grep -qxF "${new_version}" \
    || continue
    printf '%s\n' "${package}" "${new_version}"
  done \
  | parallel -j2 --max-args 2 "$0" {} \;
  exit $?
fi

if [ $# -ne 2 ]; then
  >&2 echo 'usage:'
  >&2 echo '  update.sh'
  >&2 echo '    update all packages'
  >&2 echo '  update.sh $package $version'
  >&2 echo '    update package $package to version $version'
  exit 1
fi

set -e

pkg="${1%:}"
version="$2"

cd /usr/src/ports/*/${pkg}
oldVer=$(
  sed '
    s/^version=//
    t
    d
  ' Pkgfile
)
if [ -z "${version}" ]; then
  version="${oldVer}"
fi
if [ "${oldVer}" = "${version}" ]; then
  release=$((
    1+$(
      sed '
        s/^release=//
        t
        d
      ' Pkgfile
    )
  ))
  sed -i '
    /^release=/ s/=.*$/='"${release}"'/
  ' Pkgfile
else
  sed -i '
    /^version=/ s/=.*$/='"${version}"'/
    /^release=/ s/=.*$/=1/
  ' Pkgfile
fi
sudo -u pkgmk fakeroot pkgmk -if -im -is -d
pkgmk -uf
pkgmk -um
pkgmk -us -sk /etc/ports/deepthought.sec
if [ "${oldVer}" = "${version}" ]; then
  git commit . -m "${pkg}: rebuild"
else
  git commit . -m "${pkg}: ${oldVer} -> ${version}"
fi

echo 'Erfolg!'