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.
yacy_search_server/debian/postinst

154 lines
4.8 KiB

#!/bin/sh
# postinst script for yacy
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
add_group_if_missing() {
if [ -x /usr/sbin/adduser ]; then
if ! id -g yacy >/dev/null 2>&1; then
addgroup --gid 265 --force-badname yacy
fi
fi
}
add_user_if_missing() {
if [ -x /usr/sbin/adduser ]; then
if ! id -u yacy > /dev/null 2>&1; then
adduser --system --home /var/lib/yacy --no-create-home \
--uid 264 --gid 265 --disabled-password --force-badname \
yacy
fi
fi
}
add_group_if_missing
add_user_if_missing
###### debconf stuff
CONFIGFILE=/var/lib/yacy/SETTINGS/yacy.conf
. /usr/share/debconf/confmodule
if [ -e $CONFIGFILE ]; then
ADMIN_LOGIN=$(grep ^adminAccountUserName= "$CONFIGFILE" | cut -d= -f2 | tr -d '\r\n')
ADMIN_REALM=$(grep "^adminRealm=" "$CONFIGFILE" | cut -d= -f2 | tr -d '\r\n')
else
ADMIN_LOGIN=$(grep ^adminAccountUserName= /usr/share/yacy/defaults/yacy.init | cut -d= -f2 | tr -d '\r\n')
ADMIN_REALM=$(grep "^adminRealm=" /usr/share/yacy/defaults/yacy.init | cut -d= -f2 | tr -d '\r\n')
fi
# admin user name and realm should not be empty : by the way, in that case use the same default values as in YaCy application
if [ -z "$ADMIN_LOGIN" ]; then
ADMIN_LOGIN="admin"
fi
if [ -z "$ADMIN_REALM" ]; then
ADMIN_REALM="YaCy"
fi
# Substitute in the values from the debconf db.
# There are obvious optimizations possible here.
# The cp before the sed ensures we do not mess up
# the config file's ownership and permissions.
db_get yacy/peername
PEERNAME="$RET"
db_get yacy/password
PASSWORD="$RET"
if [ "$PASSWORD" != "" ]; then
B64MD5=$(java -cp /usr/share/java/yacy/yacycore.jar net.yacy.cora.order.Digest -strfhex "$ADMIN_LOGIN:$ADMIN_REALM:$PASSWORD" | head -n 1)
PASSWORD_HASH="MD5:$B64MD5"
# When entered password is not empty always disable unauthenticated admin access from localhost
ADMIN_ACCOUNT_LOCALHOST="false"
db_set yacy/password ""
else
if [ -e $CONFIGFILE ]; then
PASSWORD_HASH=$(grep "^adminAccountBase64MD5=" $CONFIGFILE | sed -e "s/^adminAccountBase64MD5=\(.*\)/\1/" | tr -d '\r\n')
ADMIN_ACCOUNT_LOCALHOST=$(grep "^adminAccountForLocalhost=" "$CONFIGFILE" | cut -d= -f2 | tr -d '\r\n')
else
PASSWORD_HASH=""
ADMIN_ACCOUNT_LOCALHOST="true"
fi
fi
# Generate config file, if it doesn't exist.
if [ ! -e $CONFIGFILE ]; then
mkdir -p /var/lib/yacy/SETTINGS
echo "# Initial configfile from debconf" > $CONFIGFILE
echo "peerName=$HOSTNAME" >> $CONFIGFILE
echo "adminAccountBase64MD5=" >> $CONFIGFILE
echo "adminAccountForLocalhost=$ADMIN_ACCOUNT_LOCALHOST" >> $CONFIGFILE
echo "network.unit.definition=defaults/yacy.network.freeworld.unit" >> $CONFIGFILE
echo "javastart_Xmx=Xmx600m" >> $CONFIGFILE
echo "javastart_Xms=Xmx600m" >> $CONFIGFILE
fi
db_get yacy/network
NETWORK="$RET"
if [ "$NETWORK" = "url" ]; then
db_get yacy/network-url
NETWORK="$RET"
else
NETWORK="defaults/yacy\\.network\\.$NETWORK\\.unit"
fi
db_get yacy/memory-start
MEMORY_START="$RET"
db_get yacy/memory-max
MEMORY_MAX="$RET"
cp -a -f $CONFIGFILE $CONFIGFILE.tmp
# If the admin deleted or commented some variables but then set
# them via debconf, (re-)add them to the conffile.
#test -z "$FOO" || grep -Eq '^ *FOO=' $CONFIGFILE || \
# echo "FOO=" >> $CONFIGFILE
#test -z "$BAR" || grep -Eq '^ *BAR=' $CONFIGFILE || \
# echo "BAR=" >> $CONFIGFILE
sed -e "s,^ *peerName=.*,peerName=$PEERNAME," \
-e "s,^ *adminAccountBase64MD5=.*,adminAccountBase64MD5=$PASSWORD_HASH," \
-e "s,^ *adminAccountForLocalhost=.*,adminAccountForLocalhost=$ADMIN_ACCOUNT_LOCALHOST," \
-e "s,^ *network\.unit\.definition=.*,network\.unit\.definition=$NETWORK," \
-e "s,^ *javastart_Xms=.*,javastart_Xms=Xms${MEMORY_START}m," \
-e "s,^ *javastart_Xmx=.*,javastart_Xmx=Xmx${MEMORY_MAX}m," \
< $CONFIGFILE > $CONFIGFILE.tmp
mv -f $CONFIGFILE.tmp $CONFIGFILE
#### debconf stuff end
chown yacy:yacy -R /var/lib/yacy
case "$1" in
configure)
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0