Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 08 Feb 2015 18:05:57 -0800
From:      "Chris H" <bsd-lists@bsdforge.com>
To:        "FreeBSD ports" <freebsd-ports@FreeBSD.org>
Subject:   Is pkg-install the best solution?
Message-ID:  <47937acfdc6fc1260b746fc52a2f5d92@ultimatedns.net>

next in thread | raw e-mail | index | archive | help
Greetings,
 I'm working with a port that [conditionally] requires
creating/setting a UID && GID. Following is my approach
for a pkg-install. But would simply setting them as
USERS=
GROUPS=
in Makefile be a better approach?
pkg-install:
#!/bin/sh

PATH=/bin:/usr/sbin

if [ -z "${WRAP_USER}" ]; then
	WRAP_USER=myapp
fi

case $2 in
    PRE-INSTALL)
	UID=181
	GID=${UID}
	if [ ! -d "${MYAPP_DIR}" ]; then
		mkdir -p ${MYAPP_DIR}
	fi
	if pw user show "${WRAP_USER}" 2>/dev/null; then
		echo "You already have a user \"${WRAP_USER}\", so I will use it."
		if pw usermod ${WRAP_USER} -d ${MYAPP_DIR}
		then
			echo "Changed home directory of \"${WRAP_USER}\" to \"${MYAPP_DIR}\""
		else
			"${MYAPP_DIR}\" failed..."
			exit 1
		fi
		else
		if pw useradd ${WRAP_USER} -u ${UID} \
			-d ${MYAPP_DIR} -s /sbin/nologin -c "MyApp Daemon"
		then
			echo "Added user \"${WRAP_USER}\"."
		else
			echo "Adding user \"${WRAP_USER}\" failed..."
			exit 1
		fi
	fi
	;;
esac

--Chris

--





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?47937acfdc6fc1260b746fc52a2f5d92>