make user:group on install, adjust the packaging some

This commit is contained in:
Jesse McConnell 2012-11-16 16:08:40 -06:00
parent b76669434f
commit 5e61d136d7
4 changed files with 156 additions and 13 deletions

View File

@ -35,33 +35,57 @@
<assembly>
<extractArtifact>
<artifact>org.eclipse.jetty:jetty-distribution:zip</artifact>
<to>/opt/jetty</to>
<to>/usr/share/jetty9</to>
<pattern>/jetty-distribution-${project.version}(.*)</pattern>
<replacement>$1</replacement>
<excludes>
<include>jetty-distribution-*/contexts/javadoc.xml</include>
<exclude>jetty-distribution-*/javadoc</exclude>
<exclude>jetty-distribution-*/javadoc/**</exclude>
</excludes>
<exclude>jetty-distribution-*/logs/**</exclude>
<exclude>jetty-distribution-*/bin/**</exclude>
<exclude>jetty-distribution-*/webapps/**</exclude>
<exclude>jetty-distribution-*/*.html</exclude>
<exclude>jetty-distribution-*/*.txt</exclude>
</excludes>
</extractArtifact>
<extractArtifact>
<artifact>org.eclipse.jetty:jetty-distribution:zip</artifact>
<to>/usr/share/doc/jetty9</to>
<pattern>/jetty-distribution-${project.version}(.*)</pattern>
<replacement>$1</replacement>
<excludes>
<include>jetty-distribution-*/*.html</include>
<include>jetty-distribution-*/*.txt</include>
<exclude>jetty-distribution-*/**</exclude>
</excludes>
</extractArtifact>
<extractArtifact>
<artifact>org.eclipse.jetty:jetty-distribution:zip</artifact>
<to>/etc/jetty9</to>
<pattern>/jetty-distribution-${project.version}(.*)</pattern>
<replacement>$1</replacement>
<excludes>
<include>jetty-distribution-*/etc/**</include>
<exclude>jetty-distribution-*/**</exclude>
</excludes>
</extractArtifact>
</assembly>
</package>
<!--package>
<id>jetty-javadoc</id>
<classifier>javadoc</classifier>
<package>
<id>jetty-test-webapp</id>
<classifier>test-webapp</classifier>
<assembly>
<extractArtifact>
<artifact>org.eclipse.jetty:jetty-distribution:zip</artifact>
<to>/opt/jetty</to>
<to>/var/lib/jetty9/webapps</to>
<pattern>/jetty-distribution-${project.version}(.*)</pattern>
<replacement>$1</replacement>
<includes>
<include>jetty-distribution-*/contexts/javadoc.xml</include>
<include>jetty-distribution-*/javadoc/**</include>
<include>jetty-distribution-*/webapps/**</include>
</includes>
</extractArtifact>
</assembly>
</package-->
</package>
</packages>
</configuration>
</plugin>

View File

@ -1,6 +1,20 @@
#!/bin/bash
cp /opt/jetty/bin/jetty.sh /etc/init.d/jetty
LOG_DIR=/var/lib/jetty9/logs
WEBAPP_DIR=/var/lib/jetty9/webapps
# copy the jetty start script into place
cp /usr/share/jetty9/bin/jetty.sh /etc/init.d/jetty
# make it generally executable
chmod 755 /etc/init.d/jetty
chmod 755 /opt/jetty/bin/*.sh
# ensure we have a logging directory
if [ ! -d "$LOG_DIR" ]; then
mkdir $LOG_DIR
fi
# ensure we have a webapps directory
if [ ! -d "$WEBAPP_DIR" ]; then
mkdir $WEBAPP_DIR
fi

View File

@ -1,3 +1,48 @@
#!/bin/bash
rm -f /etc/init.d/jetty
#rm -f /etc/init.d/jetty
case "$1" in
purge)
[...]
# find first and last SYSTEM_UID numbers
for LINE in `grep SYSTEM_UID /etc/adduser.conf | grep -v "^#"`; do
case $LINE in
FIRST_SYSTEM_UID*)
FIST_SYSTEM_UID=`echo $LINE | cut -f2 -d '='`
;;
LAST_SYSTEM_UID*)
LAST_SYSTEM_UID=`echo $LINE | cut -f2 -d '='`
;;
*)
;;
esac
done
# Remove system account if necessary
CREATEDUSER="jetty"
if [ -n "$FIST_SYSTEM_UID" ] && [ -n "$LAST_SYSTEM_UID" ]; then
if USERID=`getent passwd $CREATEDUSER | cut -f 3 -d ':'`; then
if [ -n "$USERID" ]; then
if [ "$FIST_SYSTEM_UID" -le "$USERID" ] && \
[ "$USERID" -le "$LAST_SYSTEM_UID" ]; then
echo -n "Removing $CREATEDUSER system user.."
deluser --quiet $CREATEDUSER || true
echo "..done"
fi
fi
fi
fi
# Remove system group if necessary
CREATEDGROUP="jetty"
FIRST_USER_GID=`grep ^USERS_GID /etc/adduser.conf | cut -f2 -d '='`
if [ -n "$FIST_USER_GID" ] then
if GROUPGID=`getent group $CREATEDGROUP | cut -f 3 -d ':'`; then
if [ -n "$GROUPGID" ]; then
if [ "$FIST_USER_GID" -gt "$GROUPGID" ]; then
echo -n "Removing $CREATEDGROUP group.."
delgroup --only-if-empty $CREATEDGROUP || true
echo "..done"
fi
fi
fi
fi

View File

@ -0,0 +1,60 @@
#!/bin/bash
case "$1" in
install|upgrade)
# If the package has default file it could be sourced, so that
# the local admin can overwrite the defaults
[ -f "/etc/default/packagename" ] && . /etc/default/packagename
# Sane defaults:
[ -z "$SERVER_HOME" ] && SERVER_HOME=/usr/share/jetty9
[ -z "$SERVER_USER" ] && SERVER_USER=jetty
[ -z "$SERVER_NAME" ] && SERVER_NAME="Jetty-9 Http and Servlet Engine"
[ -z "$SERVER_GROUP" ] && SERVER_GROUP=jetty
# Groups that the user will be added to, if undefined, then none.
ADDGROUP=""
# create user to avoid running server as root
# 1. create group if not existing
if ! getent group | grep -q "^$SERVER_GROUP:" ; then
echo -n "Adding group $SERVER_GROUP.."
addgroup --quiet --system $SERVER_GROUP 2>/dev/null ||true
echo "..done"
fi
# 2. create homedir if not existing
test -d $SERVER_HOME || mkdir $SERVER_HOME
# 3. create user if not existing
if ! getent passwd | grep -q "^$SERVER_USER:"; then
echo -n "Adding system user $SERVER_USER.."
adduser --quiet \
--system \
--ingroup $SERVER_GROUP \
--no-create-home \
--disabled-password \
$SERVER_USER 2>/dev/null || true
echo "..done"
fi
# 4. adjust passwd entry
usermod -c "$SERVER_NAME" \
-d $SERVER_HOME \
-g $SERVER_GROUP \
$SERVER_USER
# 5. adjust file and directory permissions
if ! dpkg-statoverride --list $SERVER_HOME >/dev/null
then
chown -R $SERVER_USER:$SERVER_GROUP $SERVER_HOME
chmod u=rwx,g=rxs,o= $SERVER_HOME
fi
# 6. Add the user to the ADDGROUP group
if test -n $ADDGROUP
then
if ! groups $SERVER_USER | cut -d: -f2 | \
grep -qw $ADDGROUP; then
adduser $SERVER_USER $ADDGROUP
fi
fi
;;