Merge lp:~jseutter/landscape-client/backup-client-conf into lp:~landscape/landscape-client/trunk

Proposed by Jerry Seutter
Status: Merged
Approved by: Mike Milner
Approved revision: 455
Merged at revision: 456
Proposed branch: lp:~jseutter/landscape-client/backup-client-conf
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 95 lines (+35/-29)
2 files modified
debian/landscape-client.config (+32/-29)
debian/landscape-client.postinst (+3/-0)
To merge this branch: bzr merge lp:~jseutter/landscape-client/backup-client-conf
Reviewer Review Type Date Requested Status
Mike Milner (community) Approve
Chris Glass (community) Approve
Review via email: mp+92865@code.launchpad.net

Description of the change

Up until now, dpkg-reconfigure landscape-client would ignore user choices if /etc/landscape/client.conf existed because it would refuse to overwrite client.conf. This branch backs up /etc/landscape/client.conf to /etc/landscape/client.conf.bak.~1~ if it exists before writing the new config file.

This uncovered another bug where landscape-client.config would truncate the client.conf file when dpkg-reconfigure was run. The first setting that was not specified in the config file before dpkg-reconfigure would trigger an error after dpkg-reconfigure had completed, at which point reconfiguring would leave the file half written. landscape-client.config now checks for the existence of each setting before updating the value in the debconf database. This prevents nulls from entering the debconf database so that the debconf settings remain valid and can be used to write client.conf.

To post a comment you must log in.
Revision history for this message
Chris Glass (tribaal) wrote :

LGTM! +1 :)

review: Approve
Revision history for this message
Mike Milner (milner) wrote :

Ran some tests in a VM and all looks good! +1

review: Approve
456. By Jerry Seutter

Use true instead of /bin/true.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/landscape-client.config'
2--- debian/landscape-client.config 2011-10-07 12:14:19 +0000
3+++ debian/landscape-client.config 2012-02-14 21:25:20 +0000
4@@ -6,7 +6,13 @@
5 set -e
6 . /usr/share/debconf/confmodule
7
8-# This function also exists in the postinst, please keep them in sync
9+var_in_file() {
10+ var="$1"
11+ file="$2"
12+ line=$(grep "^$var\s*=\s*" "$file" 2>/dev/null || true)
13+ echo "$line"
14+}
15+
16 get_var_from_file() {
17 var="$1"
18 file="$2"
19@@ -14,37 +20,34 @@
20 echo "$val"
21 }
22
23+update_var() {
24+ var="$1"
25+ file="$2"
26+ line=$(var_in_file $var $file)
27+ if [ -n "$line" ]; then
28+ val=$(get_var_from_file $var $file)
29+ # Store value from config file in debconf.
30+ db_set $PACKAGE/$var $val
31+ fi
32+}
33+
34 # Load config file, if it exists.
35 if [ -e $CONFIGFILE ]; then
36 # Config file is "ini" type, not shell, so we cannot source it
37- COMPUTER_TITLE=$(get_var_from_file "computer_title" "$CONFIGFILE")
38- ACCOUNT_NAME=$(get_var_from_file "account_name" "$CONFIGFILE")
39- REGISTRATION_PASSWORD=$(get_var_from_file "registration_password" "$CONFIGFILE")
40- URL=$(get_var_from_file "url" "$CONFIGFILE")
41- EXCHANGE_INTERVAL=$(get_var_from_file "exchange_interval" "$CONFIGFILE")
42- URGENT_EXCHANGE_INTERVAL=$(get_var_from_file "urgent_exchange_interval" "$CONFIGFILE")
43- PING_URL=$(get_var_from_file "ping_url" "$CONFIG_FILE")
44- PING_INTERVAL=$(get_var_from_file "ping_interval" "$CONFIGFILE")
45- HTTP_PROXY=$(get_var_from_file "http_proxy" "$CONFIGFILE")
46- HTTPS_PROXY=$(get_var_from_file "https_proxy" "$CONFIGFILE")
47- OTP=$(get_var_from_file "otp" "$CONFIGFILE")
48- TAGS=$(get_var_from_file "tags" "$CONFIG_FILE")
49-
50- # Store values from config file into
51- # debconf db.
52-
53- db_set $PACKAGE/computer_title $COMPUTER_TITLE
54- db_set $PACKAGE/account_name $ACCOUNT_NAME
55- db_set $PACKAGE/registration_password $REGISTRATION_PASSWORD
56- db_set $PACKAGE/url $URL
57- db_set $PACKAGE/exchange_interval $EXCHANGE_INTERVAL
58- db_set $PACKAGE/urgent_exchange_interval $URGENT_EXCHANGE_INTERVAL
59- db_set $PACKAGE/ping_url $PING_URL
60- db_set $PACKAGE/ping_interval $PING_INTERVAL
61- db_set $PACKAGE/http_proxy $HTTP_PROXY
62- db_set $PACKAGE/https_proxy $HTTPS_PROXY
63- db_set $PACKAGE/otp $OTP
64- db_set $PACKAGE/tags $TAGS
65+ # If a setting is defined in the config file, update it in debconf
66+ # db.
67+ update_var "computer_title" "$CONFIGFILE"
68+ update_var "account_name" "$CONFIGFILE"
69+ update_var "registration_password" "$CONFIGFILE"
70+ update_var "url" "$CONFIGFILE"
71+ update_var "exchange_interval" "$CONFIGFILE"
72+ update_var "urgent_exchange_interval" "$CONFIGFILE"
73+ update_var "ping_url" "$CONFIGFILE"
74+ update_var "ping_interval" "$CONFIGFILE"
75+ update_var "http_proxy" "$CONFIGFILE"
76+ update_var "https_proxy" "$CONFIGFILE"
77+ update_var "otp" "$CONFIGFILE"
78+ update_var "tags" "$CONFIGFILE"
79 fi
80
81 # Ask questions.
82
83=== modified file 'debian/landscape-client.postinst'
84--- debian/landscape-client.postinst 2011-12-01 14:01:29 +0000
85+++ debian/landscape-client.postinst 2012-02-14 21:25:20 +0000
86@@ -27,6 +27,9 @@
87 configure)
88
89 CONFIG_FILE=/etc/landscape/client.conf
90+ if [ -f $CONFIG_FILE ]; then
91+ mv --backup=numbered $CONFIG_FILE $CONFIG_FILE.bak
92+ fi
93 if [ ! -f $CONFIG_FILE ]; then
94 # Get configuration values from debconf
95 db_get $PACKAGE/computer_title

Subscribers

People subscribed via source and target branches

to all changes: