summarylogtreecommitdiffstats
path: root/upgrade.sh
blob: 0d51737f1d6e071ff2549a99ccdd7ae3ac130210 (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
#!/bin/bash

set -e
cd "$(dirname "$0")"

repo='KELiON/cerebro'
echo "Updating $repo"

git clean -fdx
git pull

newver=$(curl -s -N "https://github.com/$repo/releases.atom" | grep -m 1 -o '/releases/.*' | sed -e 's/\/releases\/tag\/\(.*\)"\/>/\1/');
oldver=$(grep -a 'pkgver=' PKGBUILD | sed 's/pkgver=//g')

oldpure=$(echo "$oldver" | sed -e 's/\.//g;s/-//g')
newpure=$(echo "$newver" | sed -e 's/\.//g;s/-//g')

echo "Comparing $oldpure and $newpure."
if [ "$newpure" -le "$oldpure" ]; then
  echo 'Nothing to upgrade.'
  exit 0
fi


echo "Upgrading: $oldver -> $newver"

# Update files
sed -i "s/^pkgver.*/pkgver=$newver/" PKGBUILD
sed -i 's/^pkgrel.*/pkgrel=1/' PKGBUILD
updpkgsums
makepkg --printsrcinfo > .SRCINFO

# Make sure package can build
makepkg --cleanbuild

# Cleanup install files
find . -name '*.tar.gz' -exec rm {} \;
rm -rf src pkg

# Install the package
pkg=$(find . -name '*.pkg.tar.xz')
expect <<EOF
  set send_slow {1 .1}
  proc send {ignore arg} {
    sleep .1
    exp_send -s -- \$arg
  }
  set timeout 120
  spawn sudo pacman -U $pkg
  expect {
    -exact " are in conflict. Remove " { send -- "y\r"; exp_continue }
    -exact "installation? \[Y/n\]" { send -- "y\r"; exp_continue }
  }
EOF

# Push changes
git add PKGBUILD
git add .SRCINFO
git commit -m 'Bump version'
git push

echo "Update completed."