#!/bin/sh # # Checks if the '%%USER%%' user and '%%GROUP%%' group exist. If they don't, then # an attempt is made to create both. # # $FreeBSD: ports/www/tomcat55/files/pkg-install.in,v 1.4 2012/11/17 06:03:07 svnexp Exp $ # PATH=/usr/bin:/bin:/usr/sbin:/usr/local/bin # Set some constants UID=%%UID%% GID=${UID} USER=%%USER%% GROUP=%%GROUP%% APP_HOME=%%APP_HOME%% JAVA_HOME=%%JAVA_HOME%% LOG_DIR=%%LOG_DIR%% STDOUT_LOG=%%STDOUT_LOG%% STDERR_LOG=%%STDERR_LOG%% uidgid() { if ! pw groupshow "${GROUP}" 2>/dev/null 1>&2; then # If not, try to create it if pw groupadd "${GROUP}" -g ${GID}; then echo "Added group \"${GROUP}\"." elif pw groupadd "${GROUP}"; then echo "Added group \"${GROUP}\"." else echo "Adding group \"${GROUP}\" failed..." exit 1 fi else echo "You already have a group \"${GROUP}\", so I will use it." fi # See if the user already exists if ! pw usershow "${USER}" 2>/dev/null 1>&2; then # If not, try to create it if pw useradd "${USER}" -u ${UID} -g "${GROUP}" -h - \ -s "/usr/sbin/nologin" -d "/nonexistent" \ -c "World Wide Web Owner"; then echo "Added user \"${USER}\"." elif pw useradd "${USER}" -g "${GROUP}" -h - \ -s "/usr/sbin/nologin" -d "/nonexistent" \ -c "World Wide Web Owner"; then echo "Added user \"${USER}\"." else echo "Adding user \"${USER}\" failed..." exit 1 fi else echo "You already have a user \"${USER}\", so I will use it." fi } post() { echo -n ">> Creating destination directory..." mkdir -p ${APP_HOME} mkdir -p ${LOG_DIR} echo " [ DONE ]" echo ">> Copying files to destination directory..." echo " [ DONE ]" echo -n ">> Creating log files..." install -m 664 -o ${USER} -g ${GROUP} /dev/null ${STDOUT_LOG} install -m 664 -o ${USER} -g ${GROUP} /dev/null ${STDERR_LOG} echo " [ DONE ]" echo -n ">> Creating symlink to tools.jar..." ln -sf ${JAVA_HOME}/lib/tools.jar ${APP_HOME}/common/lib/tools.jar echo " [ DONE ]" echo -n ">> Fixing ownership settings..." chown -R ${USER}:${GROUP} ${APP_HOME}/conf ${APP_HOME}/logs \ ${APP_HOME}/temp ${APP_HOME}/work ${APP_HOME}/webapps chmod -R a+r ${APP_HOME}/common ${APP_HOME}/server ${APP_HOME}/bin echo " [ DONE ]" echo -n ">> Fixing permissions..." find ${APP_HOME} -type d -exec chmod 755 {} \; echo " [ DONE ] " } # PACKAGE_BUILDING is only defined on the build cluster or tinderbox! # No interactive parts, there is no one who can answer! if [ "x${PACKAGE_BUILDING}" != "x" ]; then uidgid post exit 0 fi if [ "$2" = "POST-INSTALL" ]; then uidgid post exit 0 fi exit 0