Merge lp:~marcoceppi/charms/precise/mysql/lp1293315 into lp:charms/mysql

Proposed by Marco Ceppi
Status: Merged
Merged at revision: 115
Proposed branch: lp:~marcoceppi/charms/precise/mysql/lp1293315
Merge into: lp:charms/mysql
Diff against target: 235 lines (+187/-4)
5 files modified
hooks/install (+1/-1)
hooks/master-relation-changed (+1/-1)
hooks/monitors-relation-departed (+1/-1)
hooks/monitors.common.bash (+1/-1)
lib/net.sh (+183/-0)
To merge this branch: bzr merge lp:~marcoceppi/charms/precise/mysql/lp1293315
Reviewer Review Type Date Requested Status
Charles Butler (community) Approve
Review via email: mp+211360@code.launchpad.net

Description of the change

Addresses lack of charm-helper-sh in releases other than precise

To post a comment you must log in.
Revision history for this message
Dave Cheney (dave-cheney) wrote :

LGTM. I'd like to see the install hook use set -e, there are more places where errors may happen that should terminate the hook early.

Revision history for this message
Matt Bruzek (mbruzek) wrote :

I branched this mp and called all the methods. They worked as described in the file.

+1 LGTM

Revision history for this message
Charles Butler (lazypower) wrote :

Approved

+1 LGTM

review: Approve

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 2013-11-12 16:47:49 +0000
3+++ hooks/install 2014-03-17 16:30:05 +0000
4@@ -14,7 +14,7 @@
5 fi
6
7 apt-get update
8-apt-get install -y debconf-utils python-mysqldb uuid pwgen dnsutils charm-helper-sh || exit 1
9+apt-get install -y debconf-utils python-mysqldb uuid pwgen dnsutils || exit 1
10
11 PASSFILE=/var/lib/mysql/mysql.passwd
12 if ! [ -f $PASSFILE ] ; then
13
14=== modified file 'hooks/master-relation-changed'
15--- hooks/master-relation-changed 2013-06-05 16:02:08 +0000
16+++ hooks/master-relation-changed 2014-03-17 16:30:05 +0000
17@@ -4,7 +4,7 @@
18
19 set -e
20
21-. /usr/share/charm-helper/sh/net.sh
22+. $CHARM_DIR/lib/net.sh
23
24 ROOTARGS="-uroot -p`cat /var/lib/mysql/mysql.passwd`"
25 snapdir=/var/www/snaps
26
27=== modified file 'hooks/monitors-relation-departed'
28--- hooks/monitors-relation-departed 2012-07-04 02:26:57 +0000
29+++ hooks/monitors-relation-departed 2014-03-17 16:30:05 +0000
30@@ -1,3 +1,3 @@
31 #!/bin/bash
32-. /usr/share/charm-helpers/sh/net.sh
33+
34 $MYSQL -e "REVOKE USAGE ON *.* FROM '${monitor_user}'@'${remote_addr}'"
35
36=== modified file 'hooks/monitors.common.bash'
37--- hooks/monitors.common.bash 2013-02-12 17:54:29 +0000
38+++ hooks/monitors.common.bash 2014-03-17 16:30:05 +0000
39@@ -1,6 +1,6 @@
40 MYSQL="mysql -uroot -p`cat /var/lib/mysql/mysql.passwd`"
41 monitor_user=monitors
42-. /usr/share/charm-helper/sh/net.sh
43+. $CHARM_DIR/lib/net.sh
44 if [ -n "$JUJU_REMOTE_UNIT" ] ; then
45 remote_addr=$(ch_get_ip $(relation-get private-address))
46 fi
47
48=== added directory 'lib'
49=== added file 'lib/net.sh'
50--- lib/net.sh 1970-01-01 00:00:00 +0000
51+++ lib/net.sh 2014-03-17 16:30:05 +0000
52@@ -0,0 +1,183 @@
53+#!/bin/sh
54+
55+##
56+# Copyright 2011 Marco Ceppi <marco@ceppi.net>
57+#
58+# This file is part of Charm Helpers.
59+#
60+# Charm Helpers is free software: you can redistribute it and/or modify
61+# it under the terms of the GNU General Public License as published by
62+# the Free Software Foundation, either version 3 of the License, or
63+# (at your option) any later version.
64+#
65+# Charm Helpers is distributed in the hope that it will be useful,
66+# but WITHOUT ANY WARRANTY; without even the implied warranty of
67+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68+# GNU General Public License for more details.
69+#
70+# You should have received a copy of the GNU General Public License
71+# along with Charm Helpers. If not, see <http://www.gnu.org/licenses/>.
72+##
73+
74+##
75+# Globally overridable settings. Make sure to set them before sourcing
76+# this file.
77+CH_WGET_ARGS=${CH_WGET_ARGS:-"-q --content-disposition"}
78+
79+##
80+# Get File
81+# Retrives a file and compares the file to a hash
82+#
83+# param FILE URL or Path to file
84+# param HASH URL, Path, or HASH string for file's hash
85+#
86+# return filepath|null
87+##
88+ch_get_file()
89+{
90+ local FILE=${1:-""}
91+ local HASH=${2:-""}
92+ local CH_DOWNLOAD_DIR=${CH_DOWNLOAD_DIR:-"`mktemp -d /tmp/ch-downloads.XXXXXX`"}
93+
94+ if [ `ch_is_url "$FILE"` ]; then
95+ wget $CH_WGET_ARGS --directory-prefix="$CH_DOWNLOAD_DIR/" "$FILE"
96+ FILE=$CH_DOWNLOAD_DIR/$(ls -tr $CH_DOWNLOAD_DIR|head -n 1)
97+ fi
98+
99+ if [ ! -f "$FILE" ]; then
100+ return 2
101+ fi
102+
103+ if [ -z "$HASH" ];then
104+ #echo "Warning, no has specified. The file will be downloaded but not cryptographically checked!" > 2
105+ echo "$FILE"
106+ return 0
107+ elif [ `ch_is_url "$HASH"` ]; then
108+ local HASHNAME=$(basename $HASH)
109+ wget $CH_WGET_ARGS "$HASH" -O /tmp/$HASHNAME
110+ HASH=$(cat /tmp/$HASHNAME | awk '{ print $1 }')
111+ elif [ -f "$HASH" ]; then
112+ HASH=$(cat "$HASH" | awk '{ print $1 }')
113+ fi
114+
115+ local HASH_TYPE=$(ch_type_hash $HASH)
116+
117+ if [ -z "$HASH_TYPE" ]; then
118+ return 3
119+ else
120+ local FILE_HASH=$(${HASH_TYPE}sum $FILE | awk '{ print $1 }')
121+
122+ if [ "$FILE_HASH" != "$HASH" ]; then
123+ return 4
124+ fi
125+ fi
126+
127+ echo "$FILE"
128+ return 0
129+}
130+
131+##
132+# Hash Type
133+# Determine, using best approximation, if the hash is valid and what type
134+# of hashing algorithm was used
135+#
136+# param HASH
137+#
138+# return type|false
139+##
140+ch_type_hash()
141+{
142+ local DIRTY="$1"
143+
144+ case $DIRTY in
145+ *[![:xdigit:]]* | "" )
146+ echo ""
147+ return 1
148+ ;;
149+ * )
150+ case ${#DIRTY} in
151+ 32 )
152+ echo md5
153+ ;;
154+ 40 )
155+ echo sha1
156+ ;;
157+ 64 )
158+ echo sha256
159+ ;;
160+ esac
161+ ;;
162+ esac
163+}
164+
165+##
166+# Is URL?
167+# Checks if the string passed is a valid URL (http(s), ftp)
168+#
169+# param URL The URL to be checked
170+#
171+# return boolean
172+##
173+ch_is_url()
174+{
175+ local DIRTY="$1"
176+
177+ case "$DIRTY" in
178+ "http://"* | "https://"* | "ftp://"*)
179+ echo true
180+ return 0
181+ ;;
182+ *)
183+ return 1
184+ ;;
185+ esac
186+}
187+
188+##
189+# Is IP?
190+# Checks if the string passed is an IP address
191+#
192+# param IP The IP addressed to be checked
193+#
194+# return boolean
195+##
196+ch_is_ip()
197+{
198+ local DIRTY="$1"
199+ local IP=$(echo $DIRTY | awk -F. '$1 <=255 && $2 <= 255 && $3 <= 255 && $4 <= 255 ')
200+
201+ if [ -z "$IP" ]; then
202+ return 1
203+ else
204+ echo true
205+ return 0
206+ fi
207+}
208+
209+##
210+# Get IP
211+# Returns the first IP match to the hostname provided
212+#
213+# param HOSTNAME Host for which to retrieve an IP
214+#
215+# return IP|false
216+##
217+ch_get_ip()
218+{
219+ local HOST="$1"
220+ #So, if there's multiple IP addresses, just grab the first
221+ # for now.
222+ local CHECK_IP=$(host -t A $HOST | awk 'NR==1{ print $4 }')
223+
224+ if [ ! `ch_is_ip "$CHECK_IP"` ]; then
225+ # Try a dig, why not?
226+ CHECK_IP=$(dig +short $HOST | awk 'NR==1{ print $1 }')
227+
228+ if [ ! `ch_is_ip "$CHECK_IP"` ]; then
229+ return 1
230+ fi
231+ fi
232+
233+ echo $CHECK_IP
234+ return 0
235+}

Subscribers

People subscribed via source and target branches

to all changes: