Skip to content
Advertisement

How can I make a chgrp command optional in my install script?

I’m creating an install script for a Linux game. As part of the installation, I change the suid permissions of the game executable to the “games” group so that the game can update the highscore file even when its run by regular users.

Right now my Makefile.am looks like this:

AUTOMAKE_OPTIONS = foreign
SUBDIRS = src man

install-exec-hook:
    chgrp games @bindir@/xjump
    chmod +s    @bindir@/xjump

    mkdir -p    @localstatedir@/xjump
    touch       @localstatedir@/xjump/record
    chmod 660   @localstatedir@/xjump/record
    chgrp games @localstatedir@/xjump/record

The problem I am having is that the chgrp command requires administrative privileges. If I am installing the game globally using sudo make install then its all works fine but if I change the prefix to somewhere in my home directory and try to do a regular make install it fails due to the chgrp

chgrp: changing group of ‘/home/hugo/Desktop/aaa/bin/xjump’: Operation not permitted

Since the locally installed version of the game only has a single player, I don’t really need to do the chgrp thing. Is there a way to detect if the makefile is being run without root privileges and skip the permission changing? Or should I add a configuration flag to my configure script instead of trying to fix this permission issue automatically?

Advertisement

Answer

When the commands fail, you did not run as root. It seems nothing goes wrong, you just do not want the error messages. You can see who you are, but the easiest solution is redirecting the output Finish with true, so your step doesn’t fail:

chgrp games @localstatedir@/xjump/record 2>/dev/null || true
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement