You are not logged in.

#1 2013-01-21 13:58:27

Registered: 2011-06-29
Posts: 5

[SOLVED] Problem with hardcoded paths

I found this little game that comes with linux binaries but unfortunately without source and I thought it would be a good exercise to package it for AUR. It seemed quite forward at first glance - copying the data to /usr/share/ and creating a symlink in /usr/bin (in the end it wasn't as simple as that but basically thats what i've come up with so far).
But now I come across the real problem. The game stores the savegames and the config relative to the binary (./data/ in this case) at hardcoded paths. Since /usr/share is readonly this obviously won't work. Even worse it would share the settings across all users. My first idea to overcome this was to symlink the files into /tmp and run a script at execution that symlinks those to files in the home-directory of the user who executed it (e.g. /usr/share/umg/data/game.sav -> /tmp/umg/game.sav -> /home/foo/.umg/game.sav).
I guess this would work just fine in this specific case since its unlikely that two people at the same time execute the game but I'm curious if there is a better way to handle such cases? I've read up on dynamic symlinks but couldn't find anything concerning user-depended symlinks.

My PKGBUILD so far, for anyone who wants to try to tackle this problem:

pkgdesc="2d platformer game"
arch=('i686' 'x86_64')
source=( umg)
md5sums=('e75c46984344af1f4fd8ed3cbd54a40d' '9351da852056a092bc32f020dcd2fd3c')
    mkdir -p ${pkgdir}/usr/share/${pkgname}
    mkdir -p ${pkgdir}/usr/bin
    cp -R ${srcdir}/linux-x86/* ${pkgdir}/usr/share/${pkgname}
    cd ${pkgdir}/usr/share/${pkgname}
    ln -s /usr/lib32/ ./
    chmod +x ./umg.bin
    install -m755 ${srcdir}/umg ${pkgdir}/usr/bin

and the umg wrapper used:

exec /usr/share/unnamed-monkey-game/umg.bin

Any other feedback on creating a PKGBUILD in general is welcome as well.

Last edited by trashstar (2013-01-24 15:05:19)


#2 2013-01-21 14:08:37

Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 15,551

Re: [SOLVED] Problem with hardcoded paths

That should all be in the package function, not the build function - there is nothing to build.

For the underlying problem, I'd consider an alternative to the symlink in /usr/bin.  Make a script in /usr/bin/ that checks for/creates a symlink in XDG_CONFIG_HOME to the program, then launches that symlink.  For example:


if [[ -x $launch ]]; then
   exec launch
   ln -s /usr/share/rest/of/path/to/bin $launch

EDIT: also, are you sure it is saving in a path relative to where the binary is, and not just to the current working directory?  The latter is much more likely, in which case the script would only need to cd to $dir/monkey then exec /usr/share/path/to/bin.

EDIT2: XDG_DATA_HOME might make more sense than CONFIG, but the effect would be the same.

Last edited by Trilby (2013-01-21 14:13:15)


#3 2013-01-21 15:17:18

Registered: 2011-06-29
Posts: 5

Re: [SOLVED] Problem with hardcoded paths

Thanks for the input. You are right - the game searchs the current working directory for configs and data. Now this creates the problem that i have to symlink the actual data or at least the directories. My launch script now looks like this:

export LD_LIBRARY_PATH=/usr/share/unnamed-monkey-game:$LD_LIBRARY_PATH

if [[ -d $dir ]]; then
   cd $dir
   exec $bin/umg.bin
   mkdir --parents $dir/data
   cp $bin/data/config.cfg $dir/data
   ln -s $bin/data/sfx/ $dir/data/sfx
   ln -s $bin/data/music/ $dir/data/music
   ln -s $bin/data/mobs/ $dir/data/mobs
   ln -s $bin/data/maps/ $dir/data/maps
   ln -s $bin/data/gfx/ $dir/data/gfx
   ln -s $bin/data/lang/ $dir/data/lang
   cd $dir
   exec $bin/umg.bin

Last edited by trashstar (2013-01-21 15:22:13)


#4 2013-03-17 12:45:35

Registered: 2013-03-17
Posts: 1

Re: [SOLVED] Problem with hardcoded paths

Hello, I'm the author of this game.
First, thanks for the interest trashstar smile
I actually use Arch as my main computer and that's what this game was written on.
I would prefer if this version of the game never ended up in AUR. It's an old promotion build released during the Ultimate Meeting 2011 party.
The game has since evolved a lot. Now it's a commercial title with a release (hopefully) somewhere this year. Among other changes to the game, it now saves the data to $HOME. I would be glad to provide a demo version data for inclusion in AUR/pacman, once the demo build is released.
Keep an eye on for it.

Last edited by zear (2013-03-17 12:46:46)


Board footer

Powered by FluxBB