summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: bb90d378d52d652e95ae0a8879212d3377feb3a5 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# Maintainer:  dreieck (https://aur.archlinux.org/account/dreieck)

_gogname="riven"
#_downloadname="riven-remake"
pkgbase="riven-remake-gog-bin"
pkgname=(
  "riven-remake-data-gog-bin"
  "riven-remake-launcher"
)
pkgver="1.3.0+gog75237"
pkgrel=1
epoch=0
arch=(
  'x86_64'
)
pkgdesc="2024 remake of the game 'Riven', a puzzle adventure game with superb landscape immersion. It is different from the original also in content. You need a GOG account and have purchased the file through GOG; PKGBUILD might ask you for GOG login."
url=""
groups=(
  'games'
  'myst'
  'riven'
)
makedepends=(
  'imagemagick' # to extract icon
  'innoextract'
  'lgogdownloader'
  'libarchive' # for 'bsdtar'
  'optipng'
)
checkdepends=()
source=(
  "riven-remake.sh"
  "riven-remake.desktop"
  "license-note-proprietary.txt"
)
sha256sums=(
  '2372cbefb31a6811ca3e489258dc2c1cfad16b413a9eb02af20df9e34d9ba962'  # riven-remake.sh
  '7f5ef0faf1204ec08b1f3e08ab1fda185a9e4d9613e60ca5b42b6c0b2f36607f'  # riven-remake.desktop
  '505309383841e7007ee3177d6955a44005fdcdfd332ae88b03d1ff601512ef08'  # license-note-proprietary.txt
)

_get_gameversion() {
  ## Argumens:
  #  $1: Gamename

  if [ "$#" -lt 1 ]; then
    error "${FUNCNAME[0]}: Need to specify one argument: GOG Game name (e.g. '${_gogname}')."
    return 11
  fi

  _gamename="${1#*://}" # Strip away possibly leading '://'.

  /usr/bin/lgogdownloader --game "^${_gamename}$" --platform windows --list details | grep -E -m1 '^[[:space:]]*version:' | awk '{print $2}'
}

_get_gogversion() {
  ## Argumens:
  #  $1: Gamename

  if [ "$#" -lt 1 ]; then
    error "${FUNCNAME[0]}: Need to specify one argument: GOG Game name (e.g. '${_gogname}')."
    return 11
  fi

  _gamename="${1#*://}" # Strip away possibly leading '://'.

  /usr/bin/lgogdownloader --game "^${_gamename}$" --platform windows --list details | grep -E -m1 '^[[:space:]]*path:' | sed -E 's|^.*_\(([0-9]*)\)\..*|\1|'
}

_get_version() {
  ## Argumens:
  #  $1: Gamename

  if [ "$#" -lt 1 ]; then
    error "${FUNCNAME[0]}: Need to specify one argument: GOG Game name (e.g. '${_gogname}')."
    return 11
  fi

  printf '%s' "$(_get_gameversion "$1")+gog$(_get_gogversion "$1")"
}

_download_game() {
  ## Argumens:
  #  $1: Gamename
  #  $2: Output directory

  if [ "$#" -lt 2 ]; then
    error "${FUNCNAME[0]}: Need to specify two arguments: 1.: GOG Game name (e.g. '${_gogname}'), 2.: Output directory (use '\${SRCDEST}')."
    return 11
  fi

  local _gamename
  local _targetdir

  _gamename="${1#*://}" # Strip away possibly leading '://'.
  _targetdir="$2"

  /usr/bin/lgogdownloader --threads 2 --verbosity 2 --directory "${_targetdir}" --no-color --save-serials --save-logo --save-icon --save-game-details-json --save-product-json --include all --include-hidden-products --lowspeed-timeout 60 --lowspeed-rate 128 --progress-interval 2000 --platform windows --game "^${_gamename}$" --no-fast-status-check --download
}

_get_archivename() {
  ## Argumens:
  #  $1: Gamename

  if [ "$#" -lt 1 ]; then
    error "${FUNCNAME[0]}: Need to specify one argument: GOG Game name (e.g. '${_gogname}')."
    return 11
  fi

  _gamename="${1#*://}" # Strip away possibly leading '://'.

  basename "$(/usr/bin/lgogdownloader --game "^${_gamename}$" --platform windows --list details | grep -E -m1 '^[[:space:]]*path:' | awk '{print $2}')"
}

_check_artofriven() {
  # Returns "0" if "The Art of Riven" is included in the download, "1" otherwise.
  if [ -d "${srcdir}/${_gogname}/dlc/the_art_of_riven" ]; then
    return 0
  else
    return 1
  fi
}

_check_rivencompanion() {
  # Returns "0" if "The Riven Companion" is included in the download, "1" otherwise.
  if [ -d "${srcdir}/${_gogname}/dlc/the_riven_companion" ]; then
    return 0
  else
    return 1
  fi
}

_get_artofrivenfile() {
  # Returns to stdout the path of the "The Art of Riven" download archive.
  if _check_artofriven; then
    ls -1 "${srcdir}/${_gogname}/dlc/the_art_of_riven/extras"/*.zip
  else
    return 1
  fi
}

_get_rivencompanionfile() {
  # Returns to stdout the path of the "The Riven Comanion" download archive.
  if _check_rivencompanion; then
    ls -1 "${srcdir}/${_gogname}/dlc/the_riven_companion/extras"/*.zip
  else
    return 1
  fi
}

_get_artofriven_version() {
  # Returns to stdout the version of "The Art of Riven", if it can be determined. Otherwise empty string. Exits with exitcode "1" if it is not present at all.
  if _check_artofriven; then
    basename "$(_get_artofrivenfile | tail -n1)" .zip | sed -En 's|^.*_v([^_]*)$|\1|p' | tr -d '\n'
  else
    printf '%s' ''
    return 1
  fi
}

_get_rivencompanion_version() {
  # Returns to stdout the version of "The Riven Companion", if it can be determined. Otherwise empty string. Exits with exitcode "1" if it is not present at all.
  if _check_rivencompanion; then
    basename "$(_get_rivencompanionfile | tail -n1)" .zip | sed -En 's|^.*_v([^_]*)$|\1|p' | tr -d '\n'
  else
    printf '%s' ''
    return 1
  fi
}

prepare() {
  cd "${srcdir}"
  if [ -e "${_gogname}" ]; then
    rm "${_gogname}"
  fi

  if [ -e "unpack" ]; then
    rm -Rf "unpack"
  fi

  msg2 "Downloading GOG game '${_gogname}' ..."
  _download_game "${_gogname}" "${SRCDEST}"
  ln -s "${SRCDEST}/${_gogname}" "${srcdir}/${_gogname}"

  local _archivename
  _archivename="$(_get_archivename "${_gogname}")"

  mkdir -p unpack/game

  msg2 "Extracting game data ..."
  innoextract --color off --progress --output-dir "${srcdir}/unpack/game" --extract "${srcdir}/${_gogname}/${_archivename}"

  if _check_artofriven; then
    msg2 "Extracting 'The Art of Riven' ..."
    bsdtar -C "${srcdir}/unpack" -xvf $(_get_artofrivenfile)
  fi

  if _check_rivencompanion; then
    msg2 "Extracting 'The Riven Companion' ..."
    bsdtar -C "${srcdir}/unpack" -xvf $(_get_rivencompanionfile)
  fi

  find "${srcdir}/unpack" -name '*.exe' -or -name '*.com' -or -name '*.bat' | while read _exe; do
    chmod a+x "${_exe}"
  done
}

pkgver() {
  _get_version "${_gogname}"
}

build() {
  ## 'icon.png' downloaded from GOG directly may be corrupt.
  if [ -e "${srcdir}/${_gogname}/icon.png" ]; then
    rm -f "${srcdir}/${_gogname}/icon.png"
  fi
  msg2 "Generating 'icon.png' ..."
  magick "${srcdir}/unpack/game/app"/goggame*.ico[6] "${srcdir}/${_gogname}/icon.png"
  optipng -o9 "${srcdir}/${_gogname}/icon.png"
}

package_riven-remake-data-gog-bin() {
  pkgdesc="2024 remake of the game 'Riven', a puzzle adventure game with superb landscape immersion. It is different from the original also in content. You need a GOG account and have purchased the file through GOG; PKGBUILD might ask you for GOG login."
  arch=('x86_64')
  license=(
    'LicenseRef-Proprietary'
    'LicenseRef-GOG_User_Agreement'
  )
  depends=()
  optdepends=(
    "riven-remake-launcher: To launch the game via wine by executing '/usr/bin/riven-remake'."
    'riven-remake-companion: For a strategy guide with hints and storytelling.'
    'the-art-of-riven-remake: For artwork and concept sketches.'
    "riven-original-data: To also play the original (1997) game 'Riven: The Sequel to Myst'."
  )
  provides=(
    "riven-remake-data=${pkgver}"
  )
  conflicts=(
    "riven-remake-data"
  )

  local _rivendir
  _rivendir='/usr/lib/riven-remake'

  install -dvm755 "${pkgdir}/${_rivendir}"
  cp -rv "${srcdir}/unpack/game"/{Engine,Riven} "${pkgdir}/${_rivendir}"/

  install -Dvm644 "${srcdir}/${_gogname}/icon.png" "${pkgdir}/usr/share/pixmaps/riven-remake.png"

  install -Dvm644 -t "${pkgdir}/usr/share/doc/riven-remake" "${srcdir}/${_gogname}"/{logo.jpg,game-details.json,product.json} "${srcdir}/unpack/game"/{version.txt,Manifest*.txt,goggame*.info}

  ### If extra material has been purchased, it got downloaded. Check if it is there, and if so, install it and add it to the 'provides' array.
  if _check_artofriven; then
    provides+=("the-art-of-riven-remake")
    conflicts+=("the-art-of-riven-remake")
    install -Dvm644 -t "${pkgdir}/usr/share/doc/riven-remake/the_art_of_riven" "${srcdir}/${_gogname}/dlc/the_art_of_riven"/{logo.jpg,product.json}
    install -Dvm644 -t "${pkgdir}/usr/share/doc/riven-remake/the_art_of_riven" "${srcdir}/unpack"/the_art_of_riven*/*
  fi
  if _check_rivencompanion; then
    provides+=("riven-remake-companion")
    conflicts+=("riven-remake-companion")
    install -Dvm644 -t "${pkgdir}/usr/share/doc/riven-remake/the_riven_companion" "${srcdir}/${_gogname}/dlc/the_riven_companion"/{logo.jpg,product.json}
    install -Dvm644 -t "${pkgdir}/usr/share/doc/riven-remake/the_riven_companion" "${srcdir}/unpack"/the_riven_companion*/*
  fi

  install -Dvm644 -t "${pkgdir}/usr/share/licenses/${pkgname}" "${srcdir}/license-note-proprietary.txt"
  install -Dvm644 "${srcdir}/unpack/game/tmp/EULA.txt" "${pkgdir}/usr/share/licenses/${pkgname}/GOG-EULA.txt"
}

package_riven-remake-launcher() {
  pkgdesc="Launcher script for the 2024 remake of the game 'Riven'."
  arch=('any')
  license=('GPL-3.0-or-later')
  depends=(
    "sh"
    "riven-remake-data"
    "wine"
  )
  optdepends=(
    "riven-original: To also play the original (1997) game 'Riven: The Sequel to Myst'."
  )
  provides=(
    "riven-remake=${pkgver}"
  )
  conflicts=()

  install -Dvm755 "${srcdir}/riven-remake.sh" "${pkgdir}/usr/bin/riven-remake"
  install -Dvm644 "${srcdir}/riven-remake.desktop" "${pkgdir}/usr/share/applications/riven-remake.desktop"

  install -dvm755 "${pkgdir}/usr/share/licenses/${pkgname}"
  cd "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -sv "/usr/share/licenses/spdx/GPL-3.0-or-later.txt" .
}