Merge lp:~nijaba/charms/oneiric/roundcube/new-scp into lp:charms/oneiric/roundcube

Proposed by Nick Barcet
Status: Rejected
Rejected by: Jorge Castro
Proposed branch: lp:~nijaba/charms/oneiric/roundcube/new-scp
Merge into: lp:charms/oneiric/roundcube
Diff against target: 336 lines (+79/-147)
5 files modified
hooks/install (+1/-1)
hooks/peer-relation-all (+17/-47)
hooks/peer-relation-departed (+12/-0)
hooks/roundcube-common (+48/-98)
revision (+1/-1)
To merge this branch: bzr merge lp:~nijaba/charms/oneiric/roundcube/new-scp
Reviewer Review Type Date Requested Status
Juan L. Negron (community) Disapprove
Review via email: mp+88239@code.launchpad.net

Description of the change

This branch fixes a few bugs and uses the new charm-helper copy functions instead of its own

To post a comment you must log in.
Revision history for this message
Juan L. Negron (negronjl) wrote :

I cannot review this as I am unable to branch lp:charms/oneiric/roundcube at the moment.
I'll try to investigate why ( I suspect this is a by-product of the switch from oneiric to precise ).

-Juan

Revision history for this message
Juan L. Negron (negronjl) wrote :

Both Proposed Branch and Merge Into branches are gone ...

I cannot review them ... therefore I have to reject this.

Nick:

If you moved this code somewhere else and want me to review it, let me know. I think you'll have to do another MP.

-Juan

review: Disapprove
Revision history for this message
Kapil Thangavelu (hazmat) wrote :

There's some discussion on the lists of this issue, namely majority of
oneiric official charms branches are mia atm.

On Wed, May 23, 2012 at 12:38 PM, Juan L. Negron
<email address hidden>wrote:

> I cannot review this as I am unable to branch lp:charms/oneiric/roundcube
> at the moment.
> I'll try to investigate why ( I suspect this is a by-product of the switch
> from oneiric to precise ).
>
> -Juan
> --
>
> https://code.launchpad.net/~nijaba/charms/oneiric/roundcube/new-scp/+merge/88239
> Your team charmers is requested to review the proposed merge of
> lp:~nijaba/charms/oneiric/roundcube/new-scp into
> lp:charms/oneiric/roundcube.
>

Unmerged revisions

34. By Nick Barcet

going around a weird output behaviour of juju-log on lxc

33. By Nick Barcet

allow execution of peer-relation-departed

32. By Nick Barcet

use the official ppa now that my changes have been merged

31. By Nick Barcet

missing $

30. By Nick Barcet

[ -e ] is true, needs to protect against that

29. By Nick Barcet

add peer-relation-departed and call to ch_sshd_set_root_login

28. By Nick Barcet

now fully working with ch_peer_copy

27. By Nick Barcet

removing an uneeded test

26. By Nick Barcet

update to use the new ch_peer_scp function

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/install'
2--- hooks/install 2011-12-11 17:44:19 +0000
3+++ hooks/install 2012-01-13 09:25:46 +0000
4@@ -7,7 +7,7 @@
5 apt-get update
6 apt-get upgrade -y
7
8-apt-get install -y apache2 php5 php5-mcrypt php5-gd php5-intl php-mdb2 php-auth php-net-smtp php-net-socket php-mail-mime php5-pspell libmagic1 php-auth-sasl libjs-jquery php5-mysql libapache2-mod-php5 charm-helper-sh mysql-client tinymce
9+apt-get install -y apache2 php5 php5-mcrypt php5-gd php5-intl php-mdb2 php-auth php-net-smtp php-net-socket php-mail-mime php5-pspell libmagic1 php-auth-sasl libjs-jquery php5-mysql libapache2-mod-php5 charm-helper-sh mysql-client tinymce pwgen
10
11 service apache2 stop
12
13
14=== modified file 'hooks/peer-relation-all'
15--- hooks/peer-relation-all 2011-12-13 11:11:24 +0000
16+++ hooks/peer-relation-all 2012-01-13 09:25:46 +0000
17@@ -1,9 +1,7 @@
18 #!/bin/bash
19-juju-log $JUJU_REMOTE_UNIT modified its settings
20-juju-log Relation settings:
21-relation-get
22-juju-log Relation members:
23-relation-list
24+ARG0=${0##*/}
25+
26+juju-log "$JUJU_REMOTE_UNIT - $ARG0"
27
28 common="roundcube-common"
29 FORMULA_DIR=$(dirname $0)
30@@ -11,50 +9,22 @@
31 . $FORMULA_DIR/$common
32 else
33 juju-log "ERROR: Could not load $common from $FORMULA_DIR"
34- echo "ERROR: Could not load $common from $FORMULA_DIR"
35 exit 1
36 fi
37-
38-juju-log $JUJU_REMOTE_UNIT new unit joined
39-
40-REMOTE_UNIT_ID=$(echo $JUJU_REMOTE_UNIT | cut -d/ -f2)
41-LOCAL_UNIT_ID=$(echo $JUJU_UNIT_NAME | cut -d/ -f2)
42-FIRST_UNIT_ID=$(echo "$(relation-list)" | head -n 1 | cut -d/ -f2)
43-
44-if [[ $LOCAL_UNIT_ID -lt $REMOTE_UNIT_ID ]] && [[ $LOCAL_UNIT_ID -lt $FIRST_UNIT_ID ]] ; then
45- juju-log "this is our master"
46- relation-set des-key=$(get-des-key)
47-
48- if [[ -e $ssl_crt_f ]] && [[ -e $ssl_key_f ]]; then
49- juju-log "send-ssh-keys"
50- send-ssh-key
51- else
52- juju-log "ssl certs not set yet"
53- fi
54+if [[ -e /usr/share/charm-helper/sh/peer.sh ]] ; then
55+ . /usr/share/charm-helper/sh/peer.sh
56 else
57- juju-log "this is a slave"
58-
59- #Handle des_key
60- des_key=$(relation-get des-key)
61- if [[ -z $des_key ]]; then
62- juju-log "roundcube: des-key not yet set."
63- else
64- echo $des_key > ${LPATH}config/des_key
65- set-des-key $des_key
66- fi
67-
68- #Handle_certs
69- relation-set hostname=`unit-get private-address`
70- if [ -z "`relation-get ssh-key`" ] ; then
71- juju-log "ssh-key not set yet"
72- else
73- juju-log "save-ssh-keys"
74- save_ssh_key
75- relation-set ssh-key-saved=1
76- fi
77-
78- if [[ $(relation-get restart_apache) == 1 ]]; then
79- restart-apache
80- fi
81+ juju-log -l ERROR "Could not load /usr/share/charm-helper/sh/peer.sh"
82+fi
83+
84+ch_sshd_set_root_login 1
85+
86+des_key_path=`get-des-key-path`
87+if ch_peer_copy "$ssl_crt_f" "$ssl_crt_f" "$ssl_key_f" "$ssl_key_f" "$des_key_path" "$des_key_path" ; then
88+ # this is a slave and the copy is complete
89+ set-des-key
90+ set-ssl-cert $ssl_crt_f
91+ set-ssl-cert $ssl_key_f
92+ restart-apache
93 fi
94
95
96=== added file 'hooks/peer-relation-departed'
97--- hooks/peer-relation-departed 1970-01-01 00:00:00 +0000
98+++ hooks/peer-relation-departed 2012-01-13 09:25:46 +0000
99@@ -0,0 +1,12 @@
100+#!/bin/bash
101+ARG0=${0##*/}
102+
103+juju-log "$JUJU_REMOTE_UNIT - $ARG0"
104+
105+if [[ -e /usr/share/charm-helper/sh/peer.sh ]] ; then
106+ . /usr/share/charm-helper/sh/peer.sh
107+else
108+ juju-log -l ERROR "Could not load /usr/share/charm-helper/sh/peer.sh"
109+fi
110+
111+ch_peer_copy_cleanup $JUJU_REMOTE_UNIT
112
113=== modified file 'hooks/roundcube-common'
114--- hooks/roundcube-common 2011-12-14 00:31:32 +0000
115+++ hooks/roundcube-common 2012-01-13 09:25:46 +0000
116@@ -3,70 +3,40 @@
117 LPATH="/var/opt/roundcube/"
118 config_file_path="${LPATH}config/"
119 config_tmp="$FORMULA_DIR/config.tmp"
120+
121+hostname=`unit-get public-address`
122+juju-log "Retrieved hostname: $hostname"
123+
124 ssl_crt_f="/etc/ssl/certs/ssl-cert-roundcube.pem"
125 ssl_key_f="/etc/ssl/private/ssl-cert-roundcube.key"
126-ssh_key_p="/root/.ssh/"
127-
128-hostname=`unit-get public-address`
129-juju-log "Retrieved hostname: $hostname"
130-
131-# Set our pub key
132-function send-ssh-key {
133- remote=$(relation-get hostname)
134- ssh_key_saved=$(relation-get ssh-key-saved)
135-
136- if [[ -n $remote ]] && [[ -n $ssh_key_saved ]]; then
137- echo "sending ssl certs to: $remote"
138- scp-ssl-cert "$remote"
139- relation-set restart_apache=1
140- fi
141-
142- if [[ $ssh_key_saved != 1 ]]; then
143- if [[ ! -f "$ssh_key_p/id_rsa" ]]; then
144- ssh-keygen -q -N '' -t rsa -b 2048 -f /root/.ssh/id_rsa
145- fi
146- relation-set ssh-key="`cat /root/.ssh/id_rsa.pub`"
147- echo "ssh pub keys set"
148- fi
149-
150-}
151-
152-# Save a received pub key
153-function save_ssh_key {
154- mkdir -p $ssh_key_p
155- key=`relation-get ssh-key`
156- if [ -n "$key" ] ; then
157- grep -q -F "$key" $ssh_key_p/authorized_keys
158- if [[ $? != 0 ]]; then
159- echo "saving ssh pub key"
160- echo "$key" >> $ssh_key_p/authorized_keys
161- fi
162- else
163- echo "no keys yet"
164- fi
165-}
166-
167-#Get the des_key, or generate if it does not exist
168-function get-des-key {
169- # Generate a des key if not set yet
170- if [[ ! -e "${LPATH}config/des_key" ]]; then
171- [[ ! `which pwgen` ]] && apt-get -y install pwgen
172- des_key=$(pwgen -c -s 24 1)
173- echo $des_key > ${LPATH}config/des_key
174- juju-log "des key generated: $des_key"
175- else
176- des_key=$(cat ${LPATH}config/des_key)
177- juju-log "des key retrieved: $des_key"
178- fi
179+
180+#generate the des key
181+function gen-des-key {
182+ [[ ! `which pwgen` ]] && apt-get -y install pwgen
183+ local des_key=$(pwgen -c -s 24 1)
184+ echo $des_key > ${LPATH}config/des_key
185+ juju-log "des key generated: $des_key" &> /dev/null
186 echo $des_key
187 }
188
189-
190+# Get the des_key parth, or generate if it does not exist
191+function get-des-key-path {
192+ if ch_peer_i_am_leader && [[ ! -e "${LPATH}config/des_key" ]]; then
193+ # Generate a des key if not set yet
194+ set-des-key "`gen-des-key`"
195+ fi
196+ echo "${LPATH}config/des_key"
197+}
198
199 #Write the des_key to the config
200 function set-des-key {
201 if [[ $# < 1 ]]; then
202- des_key=$(get-des-key)
203+ if [[ ! -e "${LPATH}config/des_key" ]]; then
204+ # Generate a des key if not set yet
205+ des_key=`gen-des-key`
206+ else
207+ des_key=`cat ${LPATH}config/des_key`
208+ fi
209 else
210 des_key=$1
211 fi
212@@ -80,49 +50,29 @@
213 chown root:www-data $LPATH/config/des_key.inc.php
214 }
215
216-#send over the certificate file
217-function scp-ssl-cert {
218- scp -o StrictHostKeyChecking=no $ssl_crt_f root@$1:$ssl_crt_f || exit 0
219- scp $ssl_key_f root@$1:$ssl_key_f || exit 0
220-}
221-
222-#Write the ssl cert files
223+#set correct rights on ssl certs
224 function set-ssl-cert {
225- if [[ $# == 2 ]]; then
226- #the content of the keys have been passed, write them
227- echo "$1" > $ssl_crt_f
228- echo "$2" > $ssl_key_f
229- else
230- #key files have been given to us? use them if they are not set yet
231+ if [ $# -gt 0 ] ; then
232+ chmod 0640 "$1"
233+ chown root:www-data "$1"
234+ else
235 ssl_crt=$(config-get ssl_crt)
236 ssl_key=$(config-get ssl_key)
237- if [[ -n $ssl_crt ]] && [[ -n $ssl_key ]]; then
238- if [[ ! -e $ssl_crt ]]; then
239- juju-log "HTTPS cannot be activated: you must provide a valid full path to a SSL certificate file in ssl_crt"
240- exit 0
241- fi
242- if [[ ! -e $ssl_key ]]; then
243- juju-log "HTTPS cannot be activated: you must provide a valid full path to a SSL certificate key file in ssl_key"
244- do_https=0
245- fi
246- cat $ssl_crt > $ssl_crt_f
247- cat $ssl_key > $ssl_key_f
248-
249- #restrict access to cert files
250- chmod 0640 $ssl_crt_f
251- chmod 0640 $ssl_key_f
252- chown root:www-data $ssl_crt_f
253- chown root:www-data $ssl_key_f
254- else
255- juju-log "HTTPS cannot be activated: you must provide a valid full path to a SSL certificate file in ssl_crt & ssl_key"
256+ if [ -e "$ssl_crt" ] ; then
257+ cp $ssl_crt $ssl_crt_f
258+ set-ssl-cert $ssl_crt_f
259+ else
260+ juju-log "Config's file ssl_crt: $ssl_crt does not exist"
261+ fi
262+ if [ -e "$ssl_key" ] ; then
263+ cp $ssl_key $ssl_key_f
264+ set-ssl-cert $ssl_key_f
265+ else
266+ juju-log "Config's file ssl_key: $ssl_key does not exist"
267 fi
268 fi
269-
270-
271 }
272
273-
274-
275 #Store the invariant part of the config file on disk, so that we can
276 #reuse it outside of a relation-changed hook. This is a workaround until
277 #we will be able to do relation-get <relation> <variable>
278@@ -141,7 +91,7 @@
279 password=`relation-get password`
280 host=`relation-get private-address`
281
282- if [[ ! -e $LPATH/config/db.juju.inc.php ]]; then
283+ if [[ ! -e "$LPATH/config/db.juju.inc.php" ]]; then
284 juju-log "Starting roundcube install"
285 echo "Starting roundcube install"
286 mysql -h $host -u $user --password=$password $database < $LPATH/SQL/mysql.initial.sql
287@@ -175,7 +125,7 @@
288 #Set the configuration values that can be changed after the relation
289 #with the db has been done
290 function set-config {
291- if [[ ! -e $LPATH/config/db.juju.inc.php ]] ; then
292+ if [[ ! -e "$LPATH/config/db.juju.inc.php" ]] ; then
293 juju-log "Database relation has not been established yet, can't write the config"
294 echo "Database relation has not been established yet, can't write the config"
295 exit 0
296@@ -195,11 +145,11 @@
297 do_https=$(config-get do_https)
298
299 if [[ $do_https != 0 ]]; then
300- if [[ ! -e $ssl_crt_f ]]; then
301+ if [[ ! -e "$ssl_crt_f" ]]; then
302 juju-log "HTTPS cannot be activated: you must provide a valid full path to a SSL certificate file in ssl_crt"
303 do_https=0
304 fi
305- if [[ ! -e $ssl_key_f ]]; then
306+ if [[ ! -e "$ssl_key_f" ]]; then
307 juju-log "HTTPS cannot be activated: you must provide a valid full path to a SSL certificate key file in ssl_key"
308 do_https=0
309 fi
310@@ -211,7 +161,7 @@
311 apache_config_file_path="/etc/apache2/sites-available/${hostname}.ssl"
312
313 #check if modifications are needed
314- if [[ -e apache_config_file_path ]]; then
315+ if [[ -e "$apache_config_file_path" ]]; then
316 grep -q "Listen $do_https" apache_config_file_path
317 if [[ $? == 0 ]]; then
318 grep -q "SSLCertificateFile $ssl_crt_f" apache_config_file_path
319@@ -249,8 +199,8 @@
320 function restart-apache {
321 juju-log "Restarting apache2 service"
322
323- if [[ ! -e $LPATH/config/db.juju.inc.php ]] ; then
324- juju-log "Database relation has not been established yet, let's no (re)start apache"
325+ if [[ ! -e "$LPATH/config/db.juju.inc.php" ]] ; then
326+ juju-log "Database relation has not been established yet, let's not (re)start apache"
327 exit 0
328 fi
329
330
331=== modified file 'revision'
332--- revision 2011-12-13 11:01:16 +0000
333+++ revision 2012-01-13 09:25:46 +0000
334@@ -1,1 +1,1 @@
335-17
336+27

Subscribers

People subscribed via source and target branches

to all changes: