You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
205 lines
4.8 KiB
205 lines
4.8 KiB
#! /bin/sh |
|
# postinst script for GeneWeb |
|
# |
|
# see: dh_installdeb(1) |
|
|
|
set -e |
|
|
|
# Needs Depends: iso-codes, isoquery |
|
ISOQUERY=/usr/bin/isoquery |
|
|
|
# These will be used here and there below |
|
SERVICES=/etc/services |
|
OLDRCFILE=/etc/geneweb/genewebrc |
|
NEWRCFILE=/etc/default/geneweb |
|
INITFILE=/etc/init.d/geneweb |
|
GENEWEBUSER=geneweb |
|
|
|
|
|
# We we'll need some variables defined there |
|
# We first define some defaults values...just in case |
|
GENEWEBDB=/var/lib/geneweb |
|
USERS_GROUP=geneweb |
|
LOGFILE=/var/log/geneweb.log |
|
|
|
# Default settings |
|
DEFAULTLNG="en" |
|
DEFAULTFULLLNG="English" |
|
DEFAULTPORT=2317 |
|
DEFAULTRUNMODE="Always on" |
|
DEFAULTREMOVE=false |
|
DEFAULTOPTIONS="" |
|
|
|
|
|
# Reads config file (will override defaults above) |
|
[ -r $NEWRCFILE ] && . $NEWRCFILE |
|
|
|
. /usr/share/debconf/confmodule |
|
db_version 2.0 |
|
|
|
write_rcfile() { |
|
cat >$NEWRCFILE <<EOF |
|
# |
|
# GeneWeb Configuration Data |
|
# |
|
# This file may be changed manually, or by running "dpkg-reconfigure geneweb" |
|
|
|
# The port which the daemon listens to |
|
PORT="${PORT}" |
|
|
|
# The default language |
|
# Look at Geneweb documentation for valid values |
|
# Versions prior to 4.10-9 used LANG which could mix up with |
|
# the system's localisation settings |
|
LNG="${LNG}" |
|
|
|
# The run mode |
|
# Two possible values: "Always on" or "Manual" |
|
# You need to use quotes |
|
RUN_MODE="${RUN_MODE}" |
|
|
|
# Additionnal options for gwd |
|
# Example: OPTIONS="-a 192.168.1.1" for binding the daemon to a given address |
|
# This setting is not handled by debconf |
|
OPTIONS="${OPTIONS}" |
|
EOF |
|
} |
|
|
|
get_debconf() { |
|
db_get geneweb/port |
|
PORT=$RET |
|
# If not present, use default |
|
if [ "$PORT" = "" ] |
|
then |
|
PORT=$DEFAULTPORT |
|
fi |
|
|
|
|
|
db_get geneweb/lang |
|
FULLLNG=$RET |
|
# If not present, use default |
|
if [ "$FULLLNG" = "" ] |
|
then |
|
FULLLNG=$DEFAULTFULLLNG |
|
fi |
|
# Find the two letter code for language |
|
# LNG=`echo $FULLLNG | cut -f 2 -d "(" | cut -f 1 -d ")"` |
|
LNG=`$ISOQUERY --iso=639-2 | grep "${FULLLNG}\$" | cut -f3` |
|
|
|
|
|
db_get geneweb/run_mode |
|
RUN_MODE="$RET" |
|
# If not present, use default |
|
if [ "$RUN_MODE" = "" ] |
|
then |
|
RUN_MODE="$DEFAULTRUNMODE" |
|
fi |
|
} |
|
|
|
|
|
|
|
|
|
case "$1" in |
|
configure) |
|
|
|
# NEWRCFILE has to be world-readable if we want the entry menu to work |
|
[ -f $NEWRCFILE ] && chmod g+r,a+r $NEWRCFILE |
|
|
|
[ -f $INITFILE ] && chmod a+rx $INITFILE |
|
|
|
if [ ! -x `which addgroup` ]; then |
|
echo "addgroup(8) from the \'adduser\' package is needed..."; |
|
exit 1; |
|
fi |
|
|
|
# Make sure user group is available |
|
if ! getent group ${USERS_GROUP} >/dev/null |
|
then |
|
echo "Adding $USERS_GROUP group ... " |
|
addgroup --quiet --force-badname $USERS_GROUP |
|
fi |
|
|
|
if [ ! -x `which adduser` ]; then |
|
echo "adduser(8) from the \'adduser\' package is needed..."; |
|
exit 1; |
|
fi |
|
|
|
# Make sure geneweb user exists |
|
if ! getent passwd ${GENEWEBUSER} >/dev/null |
|
then |
|
echo "Adding $GENEWEBUSER user ... " |
|
adduser --quiet --system --home /var/lib/geneweb --no-create-home --ingroup $USERS_GROUP $GENEWEBUSER |
|
fi |
|
|
|
# Permissions and groups changes come back |
|
# to the configure stage again. |
|
# Problems may remains if users previously messed up |
|
# the permissions...but more huge problems will |
|
# occur if this stage occurs _before_ the geneweb |
|
# group creation (was bug 171570 on 4.07-3 release) |
|
|
|
if [ ! -f $LOGFILE ] |
|
then |
|
touch $LOGFILE |
|
fi |
|
|
|
# Thus all files created there will have geneweb as group |
|
chown root:$USERS_GROUP $GENEWEBDB $GENEWEBDB/images $GENEWEBDB/cnt $GENEWEBDB/etc |
|
# The database directory is writable by geneweb group |
|
chmod ug+rwx,o-rwx $GENEWEBDB $GENEWEBDB/images $GENEWEBDB/cnt $GENEWEBDB/etc |
|
# SetGID bit on the database directory owned by geneweb group |
|
chmod g+s $GENEWEBDB $GENEWEBDB/images $GENEWEBDB/cnt $GENEWEBDB/etc |
|
|
|
# The log file is written by gwd running as the geneweb user |
|
# Make it readable/writable by this user only |
|
chown $GENEWEBUSER:$USERS_GROUP $LOGFILE |
|
chmod 600 $LOGFILE |
|
|
|
# Fix incorrect database and images directories permissions |
|
# These directories have to be group-writable |
|
# as the daemon now runs with an unprivileged UID |
|
# |
|
# Thanks to Russell Sutherland for pointing this to me |
|
# Bug: 179918 |
|
# |
|
# Deal properly with database names that contain spaces |
|
OLDIFS=${IFS} |
|
IFS=' |
|
' |
|
for base in `find $GENEWEBDB -type d -name \*.gwb` |
|
do |
|
chgrp $USERS_GROUP "$base" |
|
chmod g+w,g+s "$base" |
|
# Fix files permissions. See #219779 |
|
for file in `find $base -type f` |
|
do |
|
chgrp $USERS_GROUP "$file" |
|
chmod g+w "$file" |
|
done |
|
done |
|
for imagedir in `find $GENEWEBDB/images -type d` |
|
do |
|
chgrp $USERS_GROUP "$imagedir" |
|
chmod g+w,g+s "$imagedir" |
|
done |
|
IFS=${OLDIFS} |
|
|
|
# Values are read from debconf |
|
# to update variables |
|
get_debconf |
|
# The settings file is written |
|
# Moved to postinst |
|
write_rcfile |
|
|
|
;; |
|
*) |
|
;; |
|
esac |
|
|
|
# Transition of init scripts links: we don't want them in runlevels |
|
# 0 and 6 anymore |
|
if dpkg --compare-versions "$2" lt "5.01-4"; then |
|
update-rc.d -f geneweb remove |
|
fi |
|
|
|
#DEBHELPER#
|
|
|