You are not logged in.

#1 2019-08-23 16:14:47

jmjohnson
Member
Registered: 2019-08-23
Posts: 4

[REQUEST] XMage PKGBUILD Review

Hello Everyone,

My wife and I have been using XMage for testing Magic: The Gathering decks before buying the cards. I just converted one of my servers over to Arch and found the AUR package by Aidonius. I managed to get it installed and setup but I would prefer the install directory is not world writeable in /usr/share so I took a stab at updating the PKGBUILD. Before I submit it to Aidonius I wanted to run it through the forums to gather feedback. Thanks in advance and thanks to Aidonius for maintaining the package.

A couple of things to note:

  1. This is a java application that pretty much expects to run in one directory.

  2. I moved the install directory to /opt/xmage.

  3. I setup an 'xmage' user and group in the xmage.install script so users in the group can write to the xmage dirs.

  4. I made the necessary writeable directories owned by xmage:xmage and enabled setgid.

  5. I linked log files to /var/log/xmage (went back and forth on leaving them in /opt).

  6. I pre-create some files xmage creates at startup to ensure they are owned by 'xmage'.

  7. I added an xmage.service systemd unit for mage-server.

  8. I wasn't sure if 'detox' is necessary. I ran the installer w/o it and it seemed fine, but figured there was a reason for it.

PKGBUILD:

# Maintainer: Aidan Coward <aidan -dot- coward -at- gmail -dot- com>

pkgname=xmage
pkgver=1.4.37V4a
pkgrel=1

pkgdesc="Java-based program for playing Magic: The Gathering, including client and server"

arch=('any')
url="http://xmage.de"
license=('MIT')


source=("http://xmage.de/files/xmage_${pkgver}.zip"
	'https://raw.githubusercontent.com/magefree/mage/xmage_1.4.37V4/xmage.tmpfiles'
	'https://raw.githubusercontent.com/magefree/mage/xmage_1.4.37V4/LICENSE.txt')

sha256sums=("386f4febda37b76c29daa0ecceaff0dfe7f4faab71abfe98f5a8f45395e3b4fb" 
	"addd48398342887edfd9c151634c56d1f5011edda4dde60173ccd29ec5aba658"
	"bf696b246e52a279557d991916f7288c3dd296b9998f593c9d133c6906554ba3")

# Specify Java 8 directory so we don't conflict with newer versions.
_javadir=/usr/lib/jvm/java-8-openjdk/jre

depends=('jre8-openjdk' 'java8-openjfx')
makedepends=('detox')
optdepends=('wmname: change window manager name for compatibility with certain WMs')
#install="${pkgname}.install"

package() {
	cd "${srcdir}"

	# Clean up filenames
	detox -r -v ./* &> /dev/null

	# Clean up startup scripts
	sed -e "s|\.\/lib|/opt/${pkgname}/mage-client/lib|g" \
		-e 's|-Xmx512m|-Xmx1024m|g' \
		-e 's|^java|${JAVA_HOME}/bin/java|g' \
		-e "2i export JAVA_HOME=${_javadir}" \
		-e "3i cd /opt/${pkgname}/mage-client" \
		mage-client/startClient.sh > mage-client/mage-client
	sed -e "s|\.\/lib|/opt/${pkgname}/mage-server/lib|g" \
		-e 's|-Xmx512M|-Xmx1024M|g' \
		-e 's|^java|${JAVA_HOME}/bin/java|g' \
		-e "2i export JAVA_HOME=${_javadir}" \
		-e "3i cd /opt/${pkgname}/mage-server" \
		mage-server/startServer.sh > mage-server/mage-server

	# Create xmage directories
	install -dm755 "${pkgdir}"/opt/"${pkgname}"/mage-client \
		"${pkgdir}"/opt/"${pkgname}"/mage-server

	# Move startup scripts
	install -Dm755 mage-client/mage-client mage-server/mage-server \
		-t "${pkgdir}"/usr/bin

	# Copy files/directories to pkgdir
	cp -ra ./* "${pkgdir}"/opt/"${pkgname}"/

	install -Dm644 LICENSE.txt "${pkgdir}"/usr/share/licences/"${pkgname}"/LICENSE.txt

	# Create xmage user and group
	echo 'u xmage - "XMage system user"' |
	install -Dm644 /dev/stdin "$pkgdir"/usr/lib/sysusers.d/$pkgname.conf

	# XMage creates a number of directories on startup. We need to ensure
	# these exist and are writable by the 'xmage' group as well as have the
	# setgid flag set so all files created are also accessbile to the group.
	install -Dm644 "${srcdir}/xmage.tmpfiles" "${pkgdir}/usr/lib/tmpfiles.d/xmage.conf"
}

xmage.install:

post_install() {
	echo
	echo "==> XMage's files are located in /opt/xmage."
	echo
	echo "==> To start the XMage client run: mage-client"
	echo "==> To start the XMage server run: mage-server"
	echo
	echo "==> To run mage-server on startup run:"
	echo "==>   sudo systemctl enable xmage.service"
	echo 
	echo "==> To ensure proper functionality, please be sure to add your"
	echo "==> user to the 'xmage' group. You can do this by running:"
	echo "==>   sudo usermod -a -G xmage <username>"
	echo
	echo "==> The amount of RAM available to both the client and the server"
	echo "==> were increased from 512MB to 1024MB. To change the amount, "
	echo "==> edit /usr/bin/mage-client and/or /usr/bin/mage-server and "
	echo "==> change '1024' in '-Xmx1024M' to the amount of RAM (in MB) you"
	echo "==> wish to make available to each."
	echo
}

post_upgrade() {
	echo
	echo "==> Release notes can be found at"
	echo "==> https://github.com/magefree/mage/wiki/Release-changes"
	echo
}

xmage.service:

[Unit]
Description="XMage Server"

[Service]
Type=simple
User=xmage
Group=xmage
ExecStart=/usr/bin/mage-server

[Install]
WantedBy=multi-user.target

xmage.tmpfiles

d /opt/xmage/mage-client/config 2775 xmage xmage
d /opt/xmage/mage-client/db 2775 xmage xmage
d /opt/xmage/mage-client/gamelogs 2775 xmage xmage
d /opt/xmage/mage-client/gamelogsJson 2775 xmage xmage
d /opt/xmage/mage-client/resources 2775 xmage xmage
d /opt/xmage/mage-client/plugins 2775 xmage xmage
d /opt/xmage/mage-client/plugins/plugin.data 2775 xmage xmage
d /opt/xmage/mage-client/plugins/plugin.data/counters 2775 xmage xmage
d /opt/xmage/mage-client/plugins/images 2775 xmage xmage
d /opt/xmage/mage-client/plugins/images/default 2775 xmage xmage
d /opt/xmage/mage-client/plugins/images/downloading 2775 xmage xmage
d /opt/xmage/mage-client/plugins/images/temp 2775 xmage xmage
d /opt/xmage/mage-client/plugins/images/sets 2775 xmage xmage
d /opt/xmage/mage-client/plugins/images/sets/small 2775 xmage xmage
d /opt/xmage/mage-client/plugins/images/symbols 2775 xmage xmage
d /opt/xmage/mage-client/plugins/images/symbols/large 2775 xmage xmage
d /opt/xmage/mage-client/plugins/images/symbols/medium 2775 xmage xmage
d /opt/xmage/mage-client/plugins/images/symbols/png 2775 xmage xmage
d /opt/xmage/mage-client/plugins/images/symbols/small 2775 xmage xmage
d /opt/xmage/mage-client/plugins/images/symbols/svg 2775 xmage xmage
f /opt/xmage/mage-client/plugins/images/temp/batic-svg-settings.css 0664 xmage xmage
f /opt/xmage/mage-client/plugins/plugin.data/counters/counters 0664 xmage xmage
f /opt/xmage/mage-client/db/cards.h2.mv.db 0664 xmage xmage
f /opt/xmage/mage-client/db/cards.h2.trace.db 0664 xmage xmage
f /opt/xmage/mage-client/config/config.properties 0664 xmage xmage
f /opt/xmage/mage-client/config/log4j.properties 0664 xmage xmage
f /opt/xmage/mage-client/config/security.policy 0664 xmage xmage
f /opt/xmage/mage-client/plugins/mage-counter-plugin-0.1.jar 0664 xmage xmage

d /opt/xmage/mage-server/config 2775 xmage xmage
d /opt/xmage/mage-server/db 2775 xmage xmage
d /opt/xmage/mage-server/extensions 2775 xmage xmage
d /opt/xmage/mage-server/saved 2775 xmage xmage
f /opt/xmage/mage-server/db/cards.h2.mv.db 0664 xmage xmage
f /opt/xmage/mage-server/db/cards.h2.trace.db 0664 xmage xmage
f /opt/xmage/mage-server/db/table_record.db 0664 xmage xmage
f /opt/xmage/mage-server/db/user_stats.db 0664 xmage xmage
f /opt/xmage/mage-server/config/config.xml 0664 xmage xmage
f /opt/xmage/mage-server/config/log4j.properties 0664 xmage xmage
f /opt/xmage/mage-server/config/logging.properties 0664 xmage xmage
f /opt/xmage/mage-server/config/security.policy 0664 xmage xmage
f /opt/xmage/mage-server/plugins/mage-deck-constructed-1.4.37.jar 0664 xmage xmage
f /opt/xmage/mage-server/plugins/mage-deck-limited-1.4.37.jar 0664 xmage xmage
f /opt/xmage/mage-server/plugins/mage-game-commanderduel-1.4.37.jar 0664 xmage xmage
f /opt/xmage/mage-server/plugins/mage-game-freeforall-1.4.37.jar 0664 xmage xmage
f /opt/xmage/mage-server/plugins/mage-game-twoplayerduel-1.4.37.jar 0664 xmage xmage
f /opt/xmage/mage-server/plugins/mage-player-ai-draftbot-1.4.37.jar 0664 xmage xmage
f /opt/xmage/mage-server/plugins/mage-player-ai-ma-1.4.37.jar 0664 xmage xmage
f /opt/xmage/mage-server/plugins/mage-player-aiminimax-1.4.37.jar 0664 xmage xmage
f /opt/xmage/mage-server/plugins/mage-player-human-1.4.37.jar 0664 xmage xmage
f /opt/xmage/mage-server/plugins/mage-tournament-boosterdraft-1.4.37.jar 0664 xmage xmage
f /opt/xmage/mage-server/plugins/mage-tournament-sealed-1.4.37.jar 0664 xmage xmage
f /opt/xmage/mage-server/plugins/AIMinimax.properties 0664 xmage xmage

d /var/log/xmage 0755
f /var/log/xmage/mageclient.log 0664 root xmage
f /var/log/xmage/magediag.log 0664 root xmage
f /var/log/xmage/mageserver.log 0664 root xmage
L /opt/xmage/mage-client/mageclient.log - - - - /var/log/xmage/mageclient.log
L /opt/xmage/mage-server/magediag.log - - - - /var/log/xmage/magediag.log
L /opt/xmage/mage-server/mageserver.log - - - - /var/log/xmage/mageserver.log

Directory structure output:

$ ls -l /opt/xmage/mage-client/
total 64
drwxr-xr-x  2 root  root  4096 Aug 19 16:15  backgrounds
drwxrwsr-x  2 xmage xmage 4096 Aug 19 16:15  config
drwxrwsr-x  2 xmage xmage 4096 Aug 19 16:21  db
drwxrwsr-x  2 xmage xmage 4096 Aug 19 16:11  gamelogs
drwxrwsr-x  2 xmage xmage 4096 Aug 19 16:11  gamelogsJson
-rw-r--r--  1 root  root   168 Aug 19 16:11 'how to start.txt'
drwxr-xr-x  2 root  root  4096 Aug 19 16:15  lib
lrwxrwxrwx  1 root  root    29 Aug 19 16:11  mageclient.log -> /var/log/xmage/mageclient.log
drwxrwsr-x  4 xmage xmage 4096 Aug 19 16:15  plugins
-rw-r--r--  1 root  root  3162 Aug 19 16:11  readme.txt
drwxrwsr-x  2 xmage xmage 4096 Aug 19 16:11  resources
drwxr-xr-x 15 root  root  4096 Aug 19 16:15  sample-decks
drwxr-xr-x  2 root  root  4096 Aug 19 16:15  sounds
-rwxr-xr-x  1 root  root   345 Aug 19 16:11  startClient.bat
-rw-r--r--  1 root  root   169 Aug 19 16:11  startClient.command
-rw-r--r--  1 root  root   250 Aug 19 16:11  startClient.sh
-rwxr-xr-x  1 root  root   357 Aug 19 16:11  startClientWin7.bat

$ ls -l /opt/xmage/mage-server/
total 56
drwxrwsr-x 2 xmage xmage 4096 Aug 19 16:15  config
drwxrwsr-x 2 xmage xmage 4096 Aug 19 16:15  db
drwxrwsr-x 2 xmage xmage 4096 Aug 19 16:11  extensions
-rw-r--r-- 1 root  root   129 Aug 19 16:11 'how to start.txt'
drwxr-xr-x 2 root  root  4096 Aug 19 16:15  lib
-rw-r--r-- 1 root  root  1577 Aug 19 16:11  license.txt
lrwxrwxrwx 1 root  root    27 Aug 19 16:11  magediag.log -> /var/log/xmage/magediag.log
lrwxrwxrwx 1 root  root    29 Aug 19 16:11  mageserver.log -> /var/log/xmage/mageserver.log
drwxr-xr-x 2 root  root  4096 Aug 19 16:15  plugins
-rw-r--r-- 1 root  root  3157 Aug 19 16:11  readme.txt
drwxrwsr-x 2 xmage xmage 4096 Aug 19 16:11  saved
-rw-r--r-- 1 root  root   320 Aug 19 16:11  server.msg.txt
-rwxr-xr-x 1 root  root   450 Aug 19 16:11  startServer.bat
-rw-r--r-- 1 root  root   272 Aug 19 16:11  startServer.command
-rw-r--r-- 1 root  root   352 Aug 19 16:11  startServer.sh
-rwxr-xr-x 1 root  root   453 Aug 19 16:11  startServerWin7.bat

$ ls -l /var/log/xmage/
total 4
-rw-rw-r-- 1 root xmage 2987 Aug 19 16:20 mageclient.log
-rw-rw-r-- 1 root xmage    0 Aug 19 16:11 magediag.log
-rw-rw-r-- 1 root xmage    0 Aug 19 16:11 mageserver.log

Last edited by jmjohnson (2019-08-27 18:33:53)

Offline

#2 2019-08-23 16:24:08

Scimmia
Bug Wrangler
Registered: 2012-09-01
Posts: 7,293

Re: [REQUEST] XMage PKGBUILD Review

Not sure how that pkgver is incremented upstream, but it could break things with vercmp.
Invalid pkgrel
Invalid source entry
Source entry pointing to master
Skipping checksums
Not using source_x86_64, etc.
Entire .install file is wrong, should be using systemd-sysusers and systemd-tmpfiles and not documenting basic usage.

That's just in the metadata, not even getting into the logic.

Offline

#3 2019-08-23 22:10:02

jmjohnson
Member
Registered: 2019-08-23
Posts: 4

Re: [REQUEST] XMage PKGBUILD Review

Thanks for the comments. Made a bunch of changes to the original post.

Upped pkgrel.
Updated source entry.
Moved master to version specific link.
Updated checksums.
Moved source to source_x86_64 in java check.
Completely redid the .install file and now using systemd-sysusers and systemd-tmpfiles in the PKGBUILD.

Last edited by jmjohnson (2019-08-23 22:40:25)

Offline

#4 2019-08-23 23:36:30

loqs
Member
Registered: 2014-03-06
Posts: 8,800

Re: [REQUEST] XMage PKGBUILD Review

Including a binary build of sun/oracle java stops the package from being any on X86_64 and is not covered by MIT.

Offline

#5 2019-08-23 23:58:58

Scimmia
Bug Wrangler
Registered: 2012-09-01
Posts: 7,293

Re: [REQUEST] XMage PKGBUILD Review

Now that you're using source_x86_64, there's no need to guard it with the if statement.

BUT, as loqs points out, it causes other problems. Really, it should be in a separate package. Even the fact that the deps will be different between the packages precludes arch=any, though.

As for the rest of it, you're running sed, install, and mkdir (formerly) over and over again for no reason. They will all take multiple argument, and sed can have multiple commands.

Everything possible should be in the package, even the things that will be created at runtime. systemd-tmpfiles can change permissions on things that exist.

msg2 should not be used.

That install file is now totally useless. Get rid of it.

Last edited by Scimmia (2019-08-24 00:01:40)

Offline

#6 2019-08-27 18:38:42

jmjohnson
Member
Registered: 2019-08-23
Posts: 4

Re: [REQUEST] XMage PKGBUILD Review

Thank you both for the input. I didn't even think about the licensing issues, so thanks for pointing that out. I tried to find why XMage needed the specific version but couldn't find anything so I tried installing with the Arch version of openjdk 8 and everything seemed to work fine. Because of that I just pulled out all the custom java stuff as well as the x86_64 stuff. I'll reach out to the maintainer and see if they can point me to something and we can look in to an alternative if necessary.

I simplified all the sed commands and some of the install commands as well as pulled out all the msg2 stuff. As far as pulling in the post-install stuff and anything else, I couldn't find any documentation or examples; everything seems to use external files. Can you point me to an example or documentation I may have missed? Thanks.

Offline

#7 2019-09-12 23:43:14

jmjohnson
Member
Registered: 2019-08-23
Posts: 4

Re: [REQUEST] XMage PKGBUILD Review

Hey there, been a while since I've had time to check on this. Any suggestions for my last comment? Thanks in advance.

Offline

#8 2019-09-13 09:49:14

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 7,299

Re: [REQUEST] XMage PKGBUILD Review

In pacman 5.0 hooks were introduced[1]. Many actions that used to be done in .install-files are now done through hooks.
See https://wiki.archlinux.org/index.php/Pacman#Hooks for more info.

[1] https://www.archlinux.org/news/required … 016-04-23/

Please post your latest PKGBUILD and .install files .


Multi-init booting with apg Openrc and systemd coexisting
Automounting : not needed, i prefer pmount
Aur helpers : makepkg + my own local repo === rarely need them

Offline

Board footer

Powered by FluxBB