[Pkg-sympa-commits] [sympa] 05/06: Fix various bugs in debconf usage (#821819)

Emmanuel Bouthenot kolter at moszumanska.debian.org
Wed Sep 28 21:09:37 UTC 2016


This is an automated email from the git hooks/post-receive script.

kolter pushed a commit to branch master
in repository sympa.

commit 3ccfbacb68aaa3b62cb17fe0bf0dcdd1219b29c9
Author: Emmanuel Bouthenot <kolter at openics.org>
Date:   Wed Sep 28 23:07:13 2016 +0200

    Fix various bugs in debconf usage (#821819)
---
 debian/config | 122 ++++++++++++++++++++--------------------------------------
 1 file changed, 42 insertions(+), 80 deletions(-)

diff --git a/debian/config b/debian/config
index 39239f7..5f9dba8 100644
--- a/debian/config
+++ b/debian/config
@@ -7,6 +7,13 @@ set -e
 
 db_version 2.0
 
+sympa_conf_get() {
+    key="${1}"
+    if [ -e "${conf}" ]; then
+        sed -r -n 's/^\s*db_user\s+(.*)$/\1/p' "${conf}"
+    fi
+}
+
 if [ -f "/etc/sympa/sympa/sympa.conf" ] || [ ! -f "/etc/sympa/sympa.conf" ]; then
     conf=/etc/sympa/sympa/sympa.conf
 else
@@ -21,52 +28,29 @@ supported_langs="${default_lang}"
 locales="$(locale -a)"
 
 for lang in ${possible_langs} ; do
-    if locale -a | grep -q "${lang}" ; then
+    if echo "${locales}" | grep -q "^${lang}" ; then
         supported_langs="${supported_langs}, ${lang}"
     fi
 done
 
-# Get the language value in case of a manual change
-if [ -f "${conf}" ]; then
-    lang=$(perl -nle 'if (/^\s*lang\s+(\w+)/) {print $1;}' "${conf}")
-    db_set sympa/language "${lang}"
-    # Get the hostname.
-    # Since this parameter could be a unix command, we have
-    # to check this and run the command to get the value
-    if grep -q "^[  ]*host" "${conf}" ; then
-        host=$(perl -nle 'if (/^\s*host\s+(.*)$/) {
-                    if ($1 =~ m/^`(.*)`$/) {
-                        ${cmd}=`$1`; print ${cmd};
-                    } else {
-                        print $1;
-                    }
-                }' "${conf}")
-    else
-        host=$(perl -nle 'if (/^\s*domain\s+(.*)$/) {
-                    if ($1 =~ m/^`(.*)`$/) {
-                        ${cmd}=`$1`; print ${cmd};
-                    } else {
-                        print $1;
-                    }
-                }' "${conf}")
-    fi
-    # Get the listmasters, since this parameter could be a unix command, we have
-    # to check this and run the command to get the value
-    listmaster=$(perl -nle 'if (/^\s*listmaster\s+(.*)$/) {
-                    if ($1 =~ m/^`(.*)`$/) {
-                        ${cmd}=`$1`; print ${cmd};
-                    } else {
-                        print $1;
-                    }
-                }' "${conf}")
-else
-    # Get default values on configure
-    host=$(head -n 1 /etc/mailname || hostname -f || echo localhost)
-    listmaster="listmaster@${host}"
+# Get current config settings
+if [ -e "${conf}" ]; then
+    db_set sympa/language "$(sympa_conf_get 'lang')"
+    db_set sympa/hostname "$(sympa_conf_get 'domain')"
+    db_set sympa/listmaster "$(sympa_conf_get 'listmaster')"
+    db_set wwsympa/wwsympa_url "$(sympa_conf_get 'wwsympa_url')"
+    case "$(sympa_conf_get 'use_fast_cgi')" in
+        0)
+            db_set wwsympa/fastcgi "false"
+            ;;
+        1)
+            db_set wwsympa/fastcgi "true"
+            ;;
+        *)
+            ;;
+    esac
 fi
 
-# Set default values
-
 # Ask for language
 if [ "${supported_langs}" != "en" ]; then
     db_subst sympa/language supported_langs ${supported_langs}
@@ -76,34 +60,34 @@ else
     db_set sympa/language "${default_lang}"
 fi
 
+# Ask for hostname / domain
 db_get sympa/hostname
 if [ -z "${RET}" ]; then
-    db_set sympa/hostname "${host}"
+    domain=$(head -n 1 /etc/mailname || hostname -fqdn || echo localhost)
+    db_set sympa/hostname "${domain}"
 fi
 db_input medium sympa/hostname || [ $? -eq 30 ]
 db_go
 
+# Ask for listmaster
 db_get sympa/listmaster
 if [ -z "${RET}" ]; then
-    if [ -n "${listmaster}" ]; then
-        db_set sympa/listmaster "${listmaster}"
-    else
-        db_get sympa/hostname
-        db_set sympa/listmaster "listmaster@${RET}"
-    fi
+    db_get sympa/hostname
+    db_set sympa/listmaster "listmaster@${RET}"
 fi
 db_input medium sympa/listmaster || [ $? -eq 30 ]
 db_go
 
+# Ask for database settings
 if [ -f /usr/share/dbconfig-common/dpkg/config ]; then
     dbc_dbtypes="mysql, pgsql, sqlite3"
     dbc_authmethod_user="password"
     . /usr/share/dbconfig-common/dpkg/config
     dbc_first_version="5.3.4-6~"
-    if [ -f "${conf}" ] && dbctmpfile=$(tempfile -p sympa); then
+    dbctmpfile=$(tempfile -p sympa)
+    if [ -e "${conf}" ] && [ -e "${dbctmpfile}" ]; then
         # Extract sympa.conf options parsable by dbconfig-common
-        perl -ne 'print "$1=\"$2\"\n" if /^\s*(db_[a-z]+)\s*(.*)\s*$/' \
-            "${conf}" > "${dbctmpfile}"
+        sed -r -n 's/^\s*(db_[a-z]+)\s+(.*)$/\1="\2"/p' "${conf}" > "${dbctmpfile}"
         dbc_load_include="sh:${dbctmpfile}"
         dbc_load_include_args="-d db_name -p db_passwd -s db_host -P db_port -u db_user -t db_type"
     fi
@@ -111,51 +95,30 @@ if [ -f /usr/share/dbconfig-common/dpkg/config ]; then
     rm -f -- "${dbctmpfile}"
 fi
 
+# Ask for WWSympa url
 db_get wwsympa/wwsympa_url
 if [ -z "${RET}" ]; then
-    wwsympa_url_default="http://${host}/wws"
-    # Get the url from sympa.conf
-    if [ -f "${conf}" ]; then
-        wwsympa_url_conf=$(perl -nle 'if (/^\s*wwsympa_url\s+(.*)$/) {print $1;}' "${conf}")
-        if [ -z "${wwsympa_url}" ]; then
-            db_get wwsympa/wwsympa_url
-            wwsympa_url_conf="${RET}"
-        fi
-    fi
-    if [ -z "${wwsympa_url_conf}" ]; then
-        db_set wwsympa/wwsympa_url "${wwsympa_url_default}"
-    else
-        db_set wwsympa/wwsympa_url "${wwsympa_url_conf}"
-    fi
+    db_get sympa/hostname
+    db_set wwsympa/wwsympa_url "http://${RET}/wws"
 fi
-
 db_input medium wwsympa/wwsympa_url || [ $? -eq 30 ]
 db_go
 
+# Fastcgi usage
 db_get wwsympa/fastcgi
-if [ -z "${RET}" ] && [ -f "${conf}" ]; then
-    fastcgi=$(perl -nle 'if (/^\s*use_fast_cgi\s+(\d)$/) {print $1;}' "${conf}")
-    case "${fastcgi}" in
-        1)
-            fastcgi="true"
-            ;;
-        *)
-            fastcgi="false"
-        ;;
-    esac
-    db_set wwsympa/fastcgi "${fastcgi}"
+if [ -z "${RET}" ] ; then
+    db_set wwsympa/fastcgi "true"
 fi
 
 # Ask for the installed web server
 db_input high wwsympa/webserver_type || [ $? -eq 30 ]
 db_go
-
 db_get wwsympa/webserver_type
 webserver="${RET}"
 
 if [ "${webserver}" != "none" ]; then
-    # Ask for fastCGI configuration
-    db_input medium wwsympa/fastcgi || [ $? -eq 30 ]
+    # Ask for fastcgi usage
+    db_input low wwsympa/fastcgi || [ $? -eq 30 ]
     db_go
     # Ask for soap usage
     db_input medium sympa/use_soap || [ $? -eq 30 ]
@@ -165,4 +128,3 @@ fi
 # Ask for spool directories removal
 db_input medium wwsympa/remove_spool || [ $? -eq 30 ]
 db_go
-

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/sympa.git



More information about the Pkg-sympa-commits mailing list