aboutsummarylogtreecommitdiffstats
path: root/update
blob: 441e876190c34f0018ca47acf20e51d5520f0d96 (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 &> /dev/null
if [ "$?" -eq 2 ]; 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/tws-latest-standalone-linux-x64.sh" ] ; then
  echo "tws_check_update does not appear to have run"
  exit 2
fi

VER="`tws_get_version ${HOME}/.tws_scripts/tws-latest-standalone-linux-x64.sh`"
if [ "$?" -eq 1 ]; then echo "tws_get_version failed"; exit 2; fi

grep -q "pkgver=${VER}" $SCRIPT_HOME/PKGBUILD
if [ "$?" -eq 0 ]; then
  exit 0
else
  cd $SCRIPT_HOME
  rm -rf *.jar *.xz *.gz tws-latest-standalone-*.sh pkg src
  sed -i "s/pkgver=.*/pkgver=${VER}/" 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 *.xz &> /dev/null ; then
    echo "Package creation failure"
    exit 2
  fi
  mksrcinfo
  echo "$SCRIPT_HOME/PKGBUILD updated for TWS ${VER}"
  exit 1
fi