Hi Matthias,

On Fri, Mar 17, 2023 at 08:36:07AM +0100, Mathias Behrle wrote:
> thanks for testing the package and your patch, will have a look at it shortly.

I've attached an extended patch. Please consider it to be a suggested
improvement hunk by hunk. I've gone through all shell scripts in debian/
now and it covers quite a bit more occasions.

Regarding the postgresql setup, I am mildly surprised that it requires a
password. I try to always use unix domain socket based authentication
and wonder whether tryton should prefer the same for a local database.
If there is no password, you cannot leak it. However, this is drifting
from the original matter.

Helmut
diff --minimal -Nru tryton-server-6.0.29/debian/changelog 
tryton-server-6.0.29/debian/changelog
--- tryton-server-6.0.29/debian/changelog       2023-03-04 10:45:59.000000000 
+0100
+++ tryton-server-6.0.29/debian/changelog       2023-03-16 12:34:42.000000000 
+0100
@@ -1,3 +1,10 @@
+tryton-server (6.0.29-1.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Fix bugs in various maintainer scripts. (Closes: #-1)
+
+ -- Helmut Grohne <hel...@subdivi.de>  Thu, 16 Mar 2023 12:34:42 +0100
+
 tryton-server (6.0.29-1) unstable; urgency=high
 
   * Merging upstream version 6.0.29.
diff --minimal -Nru tryton-server-6.0.29/debian/scripts/activate_modules.sh 
tryton-server-6.0.29/debian/scripts/activate_modules.sh
--- tryton-server-6.0.29/debian/scripts/activate_modules.sh     2023-03-04 
10:45:59.000000000 +0100
+++ tryton-server-6.0.29/debian/scripts/activate_modules.sh     2023-03-16 
12:34:42.000000000 +0100
@@ -7,7 +7,7 @@
     . /etc/dbconfig-common/tryton-server-postgresql.conf
 fi
 
-if [ ! -z $dbc_dbname ]; then
+if [ ! -z "$dbc_dbname" ]; then
     db_name=$dbc_dbname
 fi
 
diff --minimal -Nru tryton-server-6.0.29/debian/scripts/initialize_db.sh 
tryton-server-6.0.29/debian/scripts/initialize_db.sh
--- tryton-server-6.0.29/debian/scripts/initialize_db.sh        2023-03-04 
10:45:59.000000000 +0100
+++ tryton-server-6.0.29/debian/scripts/initialize_db.sh        2023-03-16 
12:34:42.000000000 +0100
@@ -22,13 +22,13 @@
 
 TRYTONPASSFILE=`mktemp`
 export TRYTONPASSFILE
-echo $admin_password > $TRYTONPASSFILE
+echo "$admin_password" > "$TRYTONPASSFILE"
 unset admin_password
 
 # The new configuration file is not yet in place, we construct the database 
url and use that
-uri=postgresql://$dbc_dbuser:$dbc_dbpass@$dbc_dbserver
-if [ ! -z $dbc_dbport ]; then
-    uri="$uri":$dbc_dbport
+uri="postgresql://$dbc_dbuser:$dbc_dbpass@$dbc_dbserver"
+if [ ! -z "$dbc_dbport" ]; then
+    uri="$uri:$dbc_dbport"
 fi
 uri="$uri"/
 export TRYTOND_DATABASE_URI="$uri"
diff --minimal -Nru tryton-server-6.0.29/debian/scripts/run_imports.sh 
tryton-server-6.0.29/debian/scripts/run_imports.sh
--- tryton-server-6.0.29/debian/scripts/run_imports.sh  2023-03-04 
10:45:59.000000000 +0100
+++ tryton-server-6.0.29/debian/scripts/run_imports.sh  2023-03-16 
12:34:42.000000000 +0100
@@ -8,7 +8,7 @@
     . /etc/dbconfig-common/tryton-server-postgresql.conf
 fi
 
-if [ ! -z $dbc_dbname ]; then
+if [ ! -z "$dbc_dbname" ]; then
     db_name=$dbc_dbname
 fi
 
diff --minimal -Nru tryton-server-6.0.29/debian/tryton-server-nginx.postinst 
tryton-server-6.0.29/debian/tryton-server-nginx.postinst
--- tryton-server-6.0.29/debian/tryton-server-nginx.postinst    2023-03-04 
10:45:59.000000000 +0100
+++ tryton-server-6.0.29/debian/tryton-server-nginx.postinst    2023-03-16 
12:34:42.000000000 +0100
@@ -38,7 +38,7 @@
 create_config () {
     trap cleanup EXIT
     TRYTON_NGINX_CONF_NEW=$(mktemp)
-    cp -a "$TRYTON_NGINX_CONF_TEMPLATE" $TRYTON_NGINX_CONF_NEW
+    cp -a "$TRYTON_NGINX_CONF_TEMPLATE" "$TRYTON_NGINX_CONF_NEW"
 
     uwsgi_uri=$(hostname):8001
     website_uri=$(hostname -f)
diff --minimal -Nru 
tryton-server-6.0.29/debian/tryton-server-postgresql.postinst 
tryton-server-6.0.29/debian/tryton-server-postgresql.postinst
--- tryton-server-6.0.29/debian/tryton-server-postgresql.postinst       
2023-03-04 10:45:59.000000000 +0100
+++ tryton-server-6.0.29/debian/tryton-server-postgresql.postinst       
2023-03-16 12:34:42.000000000 +0100
@@ -32,15 +32,15 @@
 
     case "$dbc_dbtype" in
         pgsql)
-            uri=$dbc_dbuser:$dbc_dbpass@$dbc_dbserver
-            if [ ! -z $dbc_dbport ]; then
-                uri="$uri":$dbc_dbport
+            uri="$dbc_dbuser:$dbc_dbpass@$dbc_dbserver"
+            if [ ! -z "$dbc_dbport" ]; then
+                uri="$uri:$dbc_dbport"
             fi
             uri="$uri"/
             # first uncomment the existing postgresql uri sample line
-            sed -i -e "s|^#\s*\(uri = 
postgresql://tryton:tryton@localhost:5432/\)|\1|" "$TRYTON_CONFNEW"
+            sed -i -e '/^\[database\]$/,/^\[.*\]$/s|^#\s*\(uri = 
postgresql://tryton:tryton@localhost:5432/\)|\1|' "$TRYTON_CONFNEW"
             # now update the active postgresql uri with the correct uri
-            sed -i -e "s|^\(uri = 
postgresql://\)\(tryton:tryton@localhost:5432/\)|\1$uri|" "$TRYTON_CONFNEW"
+            sed -i -e '/^\[database\]$/,/^\[.*\]$/s|^\(uri = 
postgresql://\)\(tryton:tryton@localhost:5432/\)|\1'"$uri|" "$TRYTON_CONFNEW"
             ;;
         sqlite3)
             # just use the default sqlite database
@@ -48,7 +48,7 @@
         "")
             ;;
         *)
-            echo "Unsupported database type $dbc_type."
+            echo "Unsupported database type $dbc_dbtype."
             exit 1
             ;;
     esac
diff --minimal -Nru tryton-server-6.0.29/debian/tryton-server-postgresql.postrm 
tryton-server-6.0.29/debian/tryton-server-postgresql.postrm
--- tryton-server-6.0.29/debian/tryton-server-postgresql.postrm 2023-03-04 
10:45:59.000000000 +0100
+++ tryton-server-6.0.29/debian/tryton-server-postgresql.postrm 2023-03-16 
12:34:42.000000000 +0100
@@ -27,8 +27,8 @@
     remove)
         # restore original connection settings, i.e. disable any active 
postgresql uris
         TRYTON_CONFNEW=$(mktemp)
-        cp -a "$TRYTON_CONFFILE" $TRYTON_CONFNEW
-        sed -i -e "s|^\(uri = 
postgresql://\)\(.*\)|#\1tryton:tryton@localhost:5432/|" "$TRYTON_CONFNEW"
+        cp -a "$TRYTON_CONFFILE" "$TRYTON_CONFNEW"
+        sed -i -e '/^\[database\]$/,/^\[.*\]$/s|^\(uri = 
postgresql://\)\(.*\)|#\1tryton:tryton@localhost:5432/|' "$TRYTON_CONFNEW"
         # register new config file
         if pathfind ucf; then
             ucf --debconf-ok --src-dir "$TRYTON_SHAREDIR/default/" 
"$TRYTON_CONFNEW" "$TRYTON_CONFFILE"
diff --minimal -Nru tryton-server-6.0.29/debian/tryton-server-uwsgi.postinst 
tryton-server-6.0.29/debian/tryton-server-uwsgi.postinst
--- tryton-server-6.0.29/debian/tryton-server-uwsgi.postinst    2023-03-04 
10:45:59.000000000 +0100
+++ tryton-server-6.0.29/debian/tryton-server-uwsgi.postinst    2023-03-16 
12:34:42.000000000 +0100
@@ -36,14 +36,14 @@
 create_config () {
     trap cleanup EXIT
     TRYTON_UWSGI_INI_NEW=$(mktemp)
-    cp -a "$TRYTON_UWSGI_INI_TEMPLATE" $TRYTON_UWSGI_INI_NEW
+    cp -a "$TRYTON_UWSGI_INI_TEMPLATE" "$TRYTON_UWSGI_INI_NEW"
     TRYTON_CONFNEW=$(mktemp)
-    cp -a "$TRYTON_CONFFILE" $TRYTON_CONFNEW
+    cp -a "$TRYTON_CONFFILE" "$TRYTON_CONFNEW"
     
     db_name="tryton"
-    db_uri="$(grep "^uri =" $TRYTON_CONFFILE|cut -d' ' -f3)"
+    db_uri="$(sed -n '/^\[database\]$/,/^\[.*\]$/s/^uri\s*=\s*//p' 
"$TRYTON_CONFFILE")"
     # if no uri is configured we use the default sqlite connection
-    if [ -z $db_uri ]; then
+    if [ -z "$db_uri" ]; then
         db_uri=sqlite://
     fi
 
@@ -52,7 +52,7 @@
         . /etc/dbconfig-common/tryton-server-postgresql.conf
     fi
 
-    if [ ! -z $dbc_dbname ]; then
+    if [ ! -z "$dbc_dbname" ]; then
         db_name=$dbc_dbname
     fi
 
@@ -69,11 +69,11 @@
         # uncomment the worker daemon
         sed -i -e "s|^#\s*\(attach-daemon = /usr/bin/trytond-worker .*\)|\1|" 
"$TRYTON_UWSGI_INI_NEW"
         # configure workers in the server configuration (uncomment the 
existing worker sample line)
-        sed -i -e "s|^#\s*\(worker = False\)|\1|" "$TRYTON_CONFNEW"
-        sed -i "s|^worker = False|worker = True|" "$TRYTON_CONFNEW"
+        sed -i -e '/^\[queue\]$/,/^\[.*\]$/s|^#\s*\(worker\s*=\s*False\)|\1|' 
"$TRYTON_CONFNEW"
+        sed -i '/^\[queue\]$/,/^\[.*\]$/s|^worker\s*=\s*False|worker = True|' 
"$TRYTON_CONFNEW"
     else
         # when reconfiguring reset the server configuration
-        sed -i "s|^worker = True|#worker = False|" "$TRYTON_CONFNEW"
+        sed -i '/^\[queue\]$/,/^\[.*\]$/s|^worker\s*=\s*True|#worker = False|' 
"$TRYTON_CONFNEW"
     fi
     # register the updated server config file
     if pathfind ucf; then
@@ -109,7 +109,7 @@
         . /etc/dbconfig-common/tryton-server-postgresql.conf
     fi
 
-    if [ ! -z $dbc_dbname ]; then
+    if [ ! -z "$dbc_dbname" ]; then
         db_name=$dbc_dbname
     fi
 
diff --minimal -Nru tryton-server-6.0.29/debian/tryton-server-uwsgi.postrm 
tryton-server-6.0.29/debian/tryton-server-uwsgi.postrm
--- tryton-server-6.0.29/debian/tryton-server-uwsgi.postrm      2023-03-04 
10:45:59.000000000 +0100
+++ tryton-server-6.0.29/debian/tryton-server-uwsgi.postrm      2023-03-16 
12:34:42.000000000 +0100
@@ -27,7 +27,7 @@
 case "$1" in
     remove)
         # disable services depending on the service unit of this package
-        service_name=tryton-server-uwsgi@*.service
+        service_name="tryton-server-uwsgi@*.service"
         if [ -d /run/systemd/system ]; then
             deb-systemd-invoke stop "$service_name" >/dev/null || true
         fi
@@ -38,8 +38,8 @@
         db_get tryton-server-uwsgi/enable-workers
         if [ "$RET" != "false" ]; then
             TRYTON_CONFNEW=$(mktemp)
-            cp -a "$TRYTON_CONFFILE" $TRYTON_CONFNEW
-            sed -i "s|^worker = True|#worker = False|" "$TRYTON_CONFNEW"
+            cp -a "$TRYTON_CONFFILE" "$TRYTON_CONFNEW"
+            sed -i -e '/^\[queue\]$/,/^\[.*\]$/s|^worker = True|#worker = 
False|' "$TRYTON_CONFNEW"
             # register new config file
             if pathfind ucf; then
                 ucf --debconf-ok --src-dir "$TRYTON_SHAREDIR/default/" 
"$TRYTON_CONFNEW" "$TRYTON_CONFFILE"

Reply via email to