File: update-script.patch

package info (click to toggle)
roundcube 1.6.11%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 44,868 kB
  • sloc: javascript: 195,588; php: 76,818; sql: 3,150; sh: 2,882; pascal: 1,079; makefile: 234; xml: 93; perl: 73; ansic: 48; python: 21
file content (144 lines) | stat: -rw-r--r-- 5,682 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
From: Sandro Knauß <bugs@sandroknauss.de>
Date: Fri, 13 Mar 2015 00:42:00 +0100
Subject: Patch update scripts to work with Debian package

Forwarded: not-needed
---
 bin/update.sh                      | 19 +++++++++++--------
 program/include/rcmail_install.php | 33 +++++++++++++++++++++++++++++----
 2 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/bin/update.sh b/bin/update.sh
index c123385..de6c10c 100755
--- a/bin/update.sh
+++ b/bin/update.sh
@@ -19,6 +19,7 @@
 */
 
 define('INSTALL_PATH', '/var/lib/roundcube/');
+define('DEBIAN_PKG', getenv('DEBIAN_PKG') ? true : false);
 
 require_once INSTALL_PATH . 'program/include/clisetup.php';
 
@@ -88,19 +89,21 @@ if ($RCI->configured) {
             if (!empty($opts['accept']) || strtolower($input) == 'y') {
                 $error = $written = false;
 
-                echo "- backing up the current config file(s)...\n";
+                if (!DEBIAN_PKG) {
+                    echo "- backing up the current config file(s)...\n";
 
-                foreach (['config', 'main', 'db'] as $file) {
-                    if (file_exists(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php')) {
-                        if (!copy(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php', RCMAIL_CONFIG_DIR . '/' . $file . '.old.php')) {
-                            $error = true;
+                    foreach (['config', 'main', 'db'] as $file) {
+                        if (file_exists(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php')) {
+                            if (!copy(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php', RCMAIL_CONFIG_DIR . '/' . $file . '.old.php')) {
+                                $error = true;
+                            }
                         }
                     }
                 }
 
                 if (!$error) {
                     $RCI->merge_config();
-                    echo "- writing " . RCMAIL_CONFIG_DIR . "/config.inc.php...\n";
+                    echo "- writing " . RCMAIL_CONFIG_DIR .  "/config.inc.php".(DEBIAN_PKG ? ".dpkg-new" : "")."...\n";
                     $written = $RCI->save_configfile($RCI->create_config(false));
                 }
 
@@ -116,7 +119,7 @@ if ($RCI->configured) {
                         }
                     }
 
-                    if ($RCI->legacy_config) {
+                    if (!DEBIAN_PKG && $RCI->legacy_config) {
                         foreach (['main', 'db'] as $file) {
                             @unlink(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php');
                         }
@@ -168,7 +171,7 @@ if ($RCI->configured) {
     }
 
     // check database schema
-    if (!empty($RCI->config['db_dsnw'])) {
+    if (!DEBIAN_PKG && !empty($RCI->config['db_dsnw'])) {
         echo "Executing database schema update.\n";
         $success = rcmail_utils::db_update(INSTALL_PATH . 'SQL', 'roundcube', $opts['version'], ['errors' => true]);
     }
diff --git a/program/include/rcmail_install.php b/program/include/rcmail_install.php
index 23829a6..106b52e 100644
--- a/program/include/rcmail_install.php
+++ b/program/include/rcmail_install.php
@@ -18,6 +18,9 @@
  +-----------------------------------------------------------------------+
 */
 
+if (!defined('DEBIAN_PKG'))
+    define('DEBIAN_PKG', false);
+
 /**
  * Class to control the installation process of the Roundcube Webmail package
  *
@@ -132,10 +135,22 @@ class rcmail_install
                 $this->legacy_config = true;
             }
 
+            // Debian saves its old config in .dpkg-bak file
+            if (DEBIAN_PKG && $config = $this->load_config_file(RCUBE_CONFIG_DIR . 'main.inc.php.dpkg-bak')) {
+                $this->config        = array_merge($this->config, $config);
+                $this->legacy_config = true;
+            }
+
             if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'db.inc.php')) {
                 $this->config        = array_merge($this->config, $config);
                 $this->legacy_config = true;
             }
+
+            // Debian saves its old config in .dpkg-bak file
+            if (DEBIAN_PKG && $config = $this->load_config_file(RCUBE_CONFIG_DIR . 'db.inc.php.dpkg-bak')) {
+                $this->config        = array_merge($this->config, $config);
+                $this->legacy_config = true;
+            }
         }
 
         $this->configured = !empty($config);
@@ -286,8 +301,10 @@ class rcmail_install
             }
 
             // save change
-            $this->config[$prop] = $value;
-            $config[$prop]       = $value;
+            if (!DEBIAN_PKG || $prop != 'db_dsnw') {
+                $this->config[$prop] = $value;
+                $config[$prop]       = $value;
+            }
         }
 
         $out = "<?php\n\n";
@@ -299,6 +316,11 @@ class rcmail_install
             $out .= "\$config['$prop'] = " . self::_dump_var($value, $prop) . ";\n\n";
         }
 
+        if (DEBIAN_PKG) {
+            $out .= "// Do not set db_dsnw here, use dpkg-reconfigure roundcube-core to configure database!\n";
+            $out .= "include(\"/etc/roundcube/debian-db-roundcube.php\");\n";
+        }
+
         return $out;
     }
 
@@ -309,8 +331,11 @@ class rcmail_install
      */
     public function save_configfile($config)
     {
-        if (is_writable(RCUBE_CONFIG_DIR)) {
-            return file_put_contents(RCUBE_CONFIG_DIR . 'config.inc.php', $config);
+        $filename = RCUBE_CONFIG_DIR . "config.inc.php"
+                  . (DEBIAN_PKG ? ".dpkg-new" : "");
+
+        if (is_writable(file_exists($filename) ? $filename : RCUBE_CONFIG_DIR)) {
+            return file_put_contents($filename, $config);
         }
 
         return false;