I'm writing a daemon in C which needs to do some things as a separate user from root. I will call this user "testuser". My program is installed by its makefile. My question is thus, when should this user testuser be added? I could add it at the end of the install target:
install:
something
something
useradd -r testuser
however if the user is already added (for example by a previous install) this will fail. -useradd -r testuser
would surpress this error but this seems like bad practice.
Also, another problem with doing it during make install
would be if we are not actually installing the daemon for this system, e.g. make install DESTDIR=something
.
Should I leave the useradd to the system administrator and simply make the daemon fail with an error message if the user is not present? What are the conventions?