aboutsummarylogtreecommitdiffstats
path: root/update
blob: 69d3b9068a851411492ef44e658471a2be2fbbbb (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
#!/bin/bash

# Exit status codes:
#   0 =  PKGBUILD is already up-to-date
#   1 =  PKGBUILD has been updated
#   2 =  Error

./tws_check_update
if [ "$?" -ne 0 ]; then echo "tws_check_update failed"; exit 2; fi

PRG="$0"

while [ -h "$PRG" ]; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '.*-> \(.*\)$'`
    if expr "$link" : '/.*' > /dev/null; then
        PRG="$link"
    else
        PRG=`dirname "$PRG"`/"$link"
    fi
done
SCRIPT_HOME=`dirname "$PRG"`

if [ ! -e "$SCRIPT_HOME/PKGBUILD" ] ; then
  echo "$SCRIPT_HOME/PKGBUILD missing"
  exit 2
fi
if [ ! -e "$HOME/.tws_scripts/version.txt" ] ; then
  echo "tws_check_update does not appear to have run"
  exit 2
fi

VER="$(cat $HOME/.tws_scripts/version.txt)"

grep -q "pkgver=${VER}" $SCRIPT_HOME/PKGBUILD
if [ "$?" -eq 0 ]; then
  exit 0
else
  cd $SCRIPT_HOME
  rm -rf *.jar *.zst *.gz tws-latest-standalone-*.sh pkg src
  sed -i "s/pkgver=.*/pkgver=${VER}/" PKGBUILD
  sed -i "s/pkgrel=.*/pkgrel=1/" PKGBUILD
  # Next line from https://bugs.archlinux.org/task/15051
  { rm PKGBUILD; awk '$0 ~ /^sha256sums/ {i = 1; system("makepkg -g 2>/dev/null")}; !i {print}; $0 ~ /\)/ {i = 0}' > PKGBUILD; } < PKGBUILD
  makepkg -rs --sign
  if ! ls *.zst &> /dev/null ; then
    echo "Package creation failure"
    sed -i "s/pkgver=.*/pkgver=INVALID/" PKGBUILD
    exit 2
  fi
  makepkg --printsrcinfo > .SRCINFO
  echo "$SCRIPT_HOME/PKGBUILD updated for TWS ${VER}"
  exit 1
fi