From 1bc08e14163fe7785f4d9c9fe7b151c6cfc90dac Mon Sep 17 00:00:00 2001 From: f1ori Date: Wed, 18 Aug 2010 13:30:57 +0000 Subject: [PATCH] support debconf in debian package * now you are ask some questions to preconfigure yacy after installing the debian package git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7048 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- addon/yacyInit.m4 | 4 +- debian/config | 89 +++++++++++++++++++++++++++++++++++++++++++ debian/postinst | 67 ++++++++++++++++++++++++++++++++ debian/postrm | 6 ++- debian/rules | 3 +- debian/yacy.substvars | 1 + debian/yacy.templates | 50 ++++++++++++++++++++++++ 7 files changed, 216 insertions(+), 4 deletions(-) create mode 100644 debian/config create mode 100644 debian/yacy.substvars create mode 100644 debian/yacy.templates diff --git a/addon/yacyInit.m4 b/addon/yacyInit.m4 index dcdb37197..874a868ff 100644 --- a/addon/yacyInit.m4 +++ b/addon/yacyInit.m4 @@ -27,7 +27,7 @@ ifdef(`openSUSE', ` # Default-Start: 3 5 ')dnl ifdef(`Debian', ` -# Default-Start: 2 +# Default-Start: 2 3 4 5 ')dnl ifdef(`Fedora', ` # Default-Start: 3 5 @@ -35,7 +35,7 @@ ifdef(`Fedora', ` ifdef(`Mandriva', ` # Default-Start: 3 5 ')dnl -# Default-Stop: +# Default-Stop: 0 1 6 # Short-Description: Distributed web search engine # Description: yacy is a distributed search engine # config-file is /etc/yacy/yacy.conf diff --git a/debian/config b/debian/config new file mode 100644 index 000000000..95374db9a --- /dev/null +++ b/debian/config @@ -0,0 +1,89 @@ +#!/bin/sh +set -e + +# if we do not have debconf, we just skip this +. /usr/share/debconf/confmodule || exit 0 + +CONFIGFILE=/var/lib/yacy/SETTINGS/yacy.conf + +if [ ! -e $CONFIGFILE ]; then + db_set yacy/peername $(hostname) +else + db_set yacy/peername $(grep "^peerName=" $CONFIGFILE | sed -e "s/peerName=\(.*\)/\1/") + NETWORK_URL=$(grep "^network\.unit\.definition=" $CONFIGFILE | sed -e "s/network\.unit\.definition=\(.*\)/\1/") + case "$NETWORK_URL" in + defaults/yacy.network.freeworld.unit) + db_set yacy/network freeworld + ;; + defaults/yacy.network.intranet.unit) + db_set yacy/network intranet + ;; + defaults/yacy.network.allip.unit) + db_set yacy/network allip + ;; + defaults/yacy.network.webportal.unit) + db_set yacy/network webportal + ;; + *) + db_set yacy/network url + db_set yacy/network-url "$NETWORK_URL" + ;; + esac + db_set yacy/memory-start $(grep "^javastart_Xms=" $CONFIGFILE | sed -e "s/javastart_Xms=Xms\(.*\)m/\1/") + db_set yacy/memory-max $(grep "^javastart_Xmx=" $CONFIGFILE | sed -e "s/javastart_Xmx=Xmx\(.*\)m/\1/") +fi + +db_capb backup + +# use state machine to support step back + +STATE=1 +while true; do + case "$STATE" in + 1) + # Two unrelated questions. + db_input high yacy/peername || true + db_input high yacy/password || true + db_input high yacy/network || true + ;; + 2) + # Only ask this question if the + # first question was answered with + # url + db_get yacy/network + if [ "$RET" = "url" ]; then + db_input high yacy/network-url || true + fi + ;; + 3) + db_input high yacy/memory-start || true + db_input high yacy/memory-max || true + ;; + *) + # The default case catches when $STATE is greater than the + # last implemented state, and breaks out of the loop. This + # requires that states be numbered consecutively from 1 + # with no gaps, as the default case will also be entered + # if there is a break in the numbering + break # exits the enclosing "while" loop + ;; + esac + + if db_go; then + STATE=$(($STATE + 1)) + else + STATE=$(($STATE - 1)) + fi +done + +if [ $STATE -eq 0 ]; then + # The user has asked to back up from the first + # question. This case is problematical. Regular + # dpkg and apt package installation isn't capable + # of backing up questions between packages as this + # is written, so this will exit leaving the package + # unconfigured - probably the best way to handle + # the situation. + exit 10 +fi + diff --git a/debian/postinst b/debian/postinst index 1aa304e84..48c8ce598 100644 --- a/debian/postinst +++ b/debian/postinst @@ -38,6 +38,73 @@ add_user_if_missing() { add_group_if_missing add_user_if_missing +###### debconf stuff + +CONFIGFILE=/var/lib/yacy/SETTINGS/yacy.conf + +. /usr/share/debconf/confmodule + +# 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 "network.unit.definition=defaults/yacy.network.freeworld.unit" >> $CONFIGFILE + echo "adminAccountForLocalhost=false" >> $CONFIGFILE + echo "javastart_Xmx=Xmx600m" >> $CONFIGFILE + echo "javastart_Xms=Xmx180m" >> $CONFIGFILE +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 + BASE64=$(java -cp /usr/share/java/yacy/yacycore.jar net.yacy.kelondro.order.Base64Order -es "admin:$PASSWORD") + B64MD5=$(java -cp /usr/share/java/yacy/yacycore.jar net.yacy.kelondro.order.Digest -strfhex "$BASE64") + PASSWORD_HASH=$(echo $B64MD5 | sed "s/\(\S\) .*/\1/") + db_set yacy/password "" +else + PASSWORD_HASH=$(grep "^adminAccountBase64MD5=" $CONFIGFILE | sed -e "s/^adminAccountBase64MD5=\(.*\)/\1/") +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,^ *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 diff --git a/debian/postrm b/debian/postrm index c32ea85c7..51e32fcf9 100644 --- a/debian/postrm +++ b/debian/postrm @@ -21,7 +21,11 @@ set -e case "$1" in - purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + purge) + rm -rf /var/lib/yacy /etc/init.d/yacy + ;; + + remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) ;; *) diff --git a/debian/rules b/debian/rules index 95e85b952..6c5aca792 100755 --- a/debian/rules +++ b/debian/rules @@ -41,9 +41,10 @@ binary-indep: install # Build architecture-dependent files here. binary-arch: install + dh_installdebconf dh_installchangelogs dh_installdocs - dh_installinit -- defaults 95 05 + dh_installinit # dh_installman dh_installdeb dh_gencontrol diff --git a/debian/yacy.substvars b/debian/yacy.substvars new file mode 100644 index 000000000..a8fe3cff5 --- /dev/null +++ b/debian/yacy.substvars @@ -0,0 +1 @@ +misc:Depends=debconf (>= 0.5) | debconf-2.0 diff --git a/debian/yacy.templates b/debian/yacy.templates new file mode 100644 index 000000000..de01acda3 --- /dev/null +++ b/debian/yacy.templates @@ -0,0 +1,50 @@ +Template: yacy/peername +Type: string +Description: name for YaCy-peer + +Template: yacy/password +Type: password +Description: Admin password + Please choose an admin password for YaCy + . + If you leave this blank, YaCy's admin interface is accessable + from localhost without password. If you already set + a password, the old password won't be changed. + +Template: yacy/network +Type: select +Choices: freeworld, intranet, allip, webportal, url +Default: freeworld +Description: Choose network to participate + Choose a network: + * freeworld: public general purpose YaCy network + * intranet: index local (private) ips only + * allip: private peer for all websites + * webportal: public peer for specific websites + * url: give custom network definition file via url + +Template: yacy/network-url +Type: string +Description: URL for custom network definition file + Use this to configure your own YaCy-network + +Template: yacy/memory-start +Type: string +Default: 180 +Description: Initial java memory setting + Initial memory (in MB) for java virtual machine, you are ask for the maximum memory usage in the next question. + . + If a high performance for large search indexes is wanted, then setting the values to equal number is recommended. + . + If YaCy shall be nice in not-only-yacy environments, then the Xms value may be lower + +Template: yacy/memory-max +Type: string +Default: 600 +Description: Maximum java memory + Maximum memory (in MB) for java virtual machine + . + If a high performance for large search indexes is wanted, then setting the values to equal number is recommended + . + If YaCy shall be nice in not-only-yacy environments, then the Xms value may be lower +