summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 39745b1aee1183bd11a7d83ad43818cbe5c316f8 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Maintainer:

## options
if [ -z "$_srcinfo" ] && [ -z "$_pkgver" ]; then
  : ${_autoupdate:=true}
fi

# basic info
_pkgname='pcsx2'
pkgname="$_pkgname-latest-bin"
pkgver=2.3.10
pkgrel=1
pkgdesc='Sony PlayStation 2 emulator'
url="https://github.com/PCSX2/pcsx2"
license=('GPL-3.0-only')
arch=('x86_64')

makedepends=(
  'patchelf'
)

provides=("$_pkgname")
conflicts=("$_pkgname")

options=('!strip' '!debug')
install="$_pkgname.install"

_source_main() {
  _appimage="pcsx2-v$_pkgver-linux-appimage-x64-Qt.AppImage"
  source+=("$url/releases/download/v$_pkgver/$_appimage")
  sha256sums+=('SKIP')
}

build() {
  # extract appimage
  chmod +x "$_appimage"
  "./$_appimage" --appimage-extract

  (
    # fix desktop file name
    cd "$srcdir/squashfs-root"
    if [ ! -e "PCSX2.desktop" ]; then
      for i in *.desktop; do
        [ -f "$i" ] && mv "$i" PCSX2.desktop && break
      done
    fi
  )

  # update script
  sed -Ei \
    's@^this_dir=".*\breadlink\b.*\bdirname\b.*"$@this_dir="/opt/pcsx2"@' \
    "$srcdir/squashfs-root/AppRun"
}

package() {
  # main files
  install -dm755 "$pkgdir/opt/$_pkgname"
  mv "$srcdir"/squashfs-root/* "$pkgdir/opt/$_pkgname/"

  # rpath
  patchelf --force-rpath --set-rpath "/opt/$_pkgname/usr/lib" "$pkgdir/opt/$_pkgname/usr/bin/pcsx2-qt"

  # script
  install -dm755 "$pkgdir/usr/bin"
  ln -sf "/opt/$_pkgname/AppRun" "$pkgdir/usr/bin/pcsx2-qt"

  # icon
  install -Dm644 "$pkgdir/opt/$_pkgname/PCSX2.png" -t "$pkgdir/usr/share/pixmaps"

  # launcher
  install -Dm644 "$pkgdir/opt/$_pkgname/PCSX2.desktop" -t "$pkgdir/usr/share/applications"

  # permissions
  chmod -R u+rwX,go+rX,go-w "$pkgdir/"
}

_update_version() {
  : ${_pkgver:=${pkgver%%.r*}}

  if [[ "${_autoupdate::1}" != "t" ]]; then
    return
  fi

  local _response=$(curl -Ssf "$url/releases.atom")

  local _pkgver_new=$(
    printf '%s' "$_response" \
      | grep '/releases/tag/' \
      | sed -E 's@^.*/releases/tag/(.*)".*$@\1@; s@^v@@' \
      | grep -Ev '[a-z]{2}' | sort -V | tail -1
  )

  # update _pkgver
  if [ "$_pkgver" != "${_pkgver_new:?}" ]; then
    _pkgver="${_pkgver_new:?}"
  fi

  pkgver() {
    printf '%s' "${_pkgver:?}"
  }
}

_update_version
_source_main