summarylogtreecommitdiffstats
path: root/update
blob: 9ed1ee0a62529a4a2223e9c0cdaed1c6bbfe2d15 (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
#!/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 ~ /^md5sums/ {i = 1; system("makepkg -g 2>/dev/null")}; !i {print}; $0 ~ /\)/ {i = 0}' > PKGBUILD; } < PKGBUILD
  makepkg
  if ! ls *.zst &> /dev/null ; then
    echo "Package creation failure"
    exit 2
  fi
  makepkg --printsrcinfo > .SRCINFO
  echo "$SCRIPT_HOME/PKGBUILD updated for TWS ${VER}"
  exit 1
fi