Skip to content

Instantly share code, notes, and snippets.

Created October 24, 2012 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3945758 to your computer and use it in GitHub Desktop.
Save anonymous/3945758 to your computer and use it in GitHub Desktop.
INSTALL
#!/bin/sh
# $NetBSD$
PATH=/bin:/usr/sbin
USER=PACKAGE_NAME
GROUP=PACKAGE_NAME
HOME=/usr/pkg/PACKAGE_NAME
DAEMON=${HOME}/agent
case ${STAGE} in
PRE-INSTALL)
if groupinfo ${GROUP} 2> /dev/null; then
echo "Group \"${GROUP}\" alredy exists, leaving as is."
else
if groupadd ${GROUP} 2> /dev/null
then
echo "Created agent's \"${GROUP}\" group."
else
echo "Creating agent's group \"${GROUP}\" has failed."
exit 1
fi
fi
if /usr/bin/id ${USER} 2> /dev/null; then
echo "User \"${USER}\" already exists."
else
if useradd -g ${GROUP} \
-d ${HOME} -s /sbin/nologin -c "PACKAGE_NAME" ${USER} 2> /dev/null
then
echo "Added agent's user \"${USER}\"."
else
echo "Adding agent's \"${USER}\" user has failed."
exit 1
fi
fi
;;
POST-INSTALL)
if cat /etc/rc.conf | /usr/bin/grep PACKAGE_NAME 2>&1 > /dev/null; then
echo "Agent's service was found rc.conf, leaving as is"
else
echo 'PACKAGE_NAME=YES' >> /etc/rc.conf
echo "Agent's service enabled in rc.conf."
fi
chown -R ${USER}:${GROUP} ${HOME}
chmod 770 ${HOME}
chmod 770 ${DAEMON}
/usr/pkg/bin/perl ${DAEMON} register
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment