blob: eca0f9be160dfe2e8e1683bb500fc2d3a06d0ec2 [file] [log] [blame]
Dean Troyer7f9aa712012-01-31 12:11:56 -06001# functions - Common functions used by DevStack components
Dean Troyer13dc5cc2012-03-27 14:50:45 -05002#
Dean Troyer4a43b7b2012-08-28 17:43:40 -05003# The following variables are assumed to be defined by certain functions:
Dean Troyer4a43b7b2012-08-28 17:43:40 -05004# ``ENABLED_SERVICES``
5# ``EROR_ON_CLONE``
6# ``FILES``
7# ``GLANCE_HOSTPORT``
8# ``OFFLINE``
9# ``PIP_DOWNLOAD_CACHE``
Maru Newby3a87edd2012-10-25 23:01:06 +000010# ``PIP_USE_MIRRORS``
Dean Troyer4a43b7b2012-08-28 17:43:40 -050011# ``RECLONE``
12# ``TRACK_DEPENDS``
13# ``http_proxy``, ``https_proxy``, ``no_proxy``
Dean Troyer13dc5cc2012-03-27 14:50:45 -050014
Dean Troyer7f9aa712012-01-31 12:11:56 -060015
Dean Troyer27e32692012-03-16 16:16:56 -050016# Save trace setting
17XTRACE=$(set +o | grep xtrace)
18set +o xtrace
19
Dean Troyer7f9aa712012-01-31 12:11:56 -060020
Dean Troyerd4f69b22013-07-24 12:24:43 -050021# Convert CIDR notation to a IPv4 netmask
22# cidr2netmask cidr-bits
23function cidr2netmask() {
24 local maskpat="255 255 255 255"
25 local maskdgt="254 252 248 240 224 192 128"
26 set -- ${maskpat:0:$(( ($1 / 8) * 4 ))}${maskdgt:$(( (7 - ($1 % 8)) * 4 )):3}
27 echo ${1-0}.${2-0}.${3-0}.${4-0}
28}
29
30
31# Return the network portion of the given IP address using netmask
32# netmask is in the traditional dotted-quad format
33# maskip ip-address netmask
34function maskip() {
35 local ip=$1
36 local mask=$2
37 local l="${ip%.*}"; local r="${ip#*.}"; local n="${mask%.*}"; local m="${mask#*.}"
38 local subnet=$((${ip%%.*}&${mask%%.*})).$((${r%%.*}&${m%%.*})).$((${l##*.}&${n##*.})).$((${ip##*.}&${mask##*.}))
39 echo $subnet
40}
41
42
43# Exit 0 if address is in network or 1 if address is not in network
44# ip-range is in CIDR notation: 1.2.3.4/20
Dean Troyer4a43b7b2012-08-28 17:43:40 -050045# address_in_net ip-address ip-range
Vishvananda Ishayac9ad14b2012-07-03 20:29:01 +000046function address_in_net() {
Dean Troyerd4f69b22013-07-24 12:24:43 -050047 local ip=$1
48 local range=$2
49 local masklen=${range#*/}
50 local network=$(maskip ${range%/*} $(cidr2netmask $masklen))
51 local subnet=$(maskip $ip $(cidr2netmask $masklen))
52 [[ $network == $subnet ]]
Vishvananda Ishayac9ad14b2012-07-03 20:29:01 +000053}
54
55
Dean Troyer4a43b7b2012-08-28 17:43:40 -050056# Wrapper for ``apt-get`` to set cache and proxy environment variables
57# Uses globals ``OFFLINE``, ``*_proxy`
Dean Troyer13dc5cc2012-03-27 14:50:45 -050058# apt_get operation package [package ...]
Dean Troyer7f9aa712012-01-31 12:11:56 -060059function apt_get() {
Dean Troyerd0b21e22012-03-07 14:52:25 -060060 [[ "$OFFLINE" = "True" || -z "$@" ]] && return
Dean Troyer7f9aa712012-01-31 12:11:56 -060061 local sudo="sudo"
62 [[ "$(id -u)" = "0" ]] && sudo="env"
63 $sudo DEBIAN_FRONTEND=noninteractive \
64 http_proxy=$http_proxy https_proxy=$https_proxy \
Osamu Habuka7abe4f22012-07-25 12:39:32 +090065 no_proxy=$no_proxy \
Dean Troyer7f9aa712012-01-31 12:11:56 -060066 apt-get --option "Dpkg::Options::=--force-confold" --assume-yes "$@"
67}
68
69
70# Gracefully cp only if source file/dir exists
71# cp_it source destination
72function cp_it {
73 if [ -e $1 ] || [ -d $1 ]; then
74 cp -pRL $1 $2
75 fi
76}
77
78
Kui Shi5e28a3e2013-08-02 17:26:28 +080079# Prints backtrace info
80# filename:lineno:function
81function backtrace {
82 local level=$1
83 local deep=$((${#BASH_SOURCE[@]} - 1))
84 echo "[Call Trace]"
85 while [ $level -le $deep ]; do
86 echo "${BASH_SOURCE[$deep]}:${BASH_LINENO[$deep-1]}:${FUNCNAME[$deep-1]}"
87 deep=$((deep - 1))
88 done
89}
90
91
Dean Troyerac93efb2013-03-13 14:30:54 -050092# Prints line number and "message" then exits
93# die $LINENO "message"
Dean Troyer27e32692012-03-16 16:16:56 -050094function die() {
Dean Troyer489bd2a2012-03-02 10:44:29 -060095 local exitcode=$?
Dean Troyer896eb662013-04-05 15:02:01 -050096 set +o xtrace
97 local line=$1; shift
Nachi Ueno07115eb2013-02-26 12:38:18 -080098 if [ $exitcode == 0 ]; then
99 exitcode=1
100 fi
Kui Shi5e28a3e2013-08-02 17:26:28 +0800101 backtrace 2
Dean Troyer896eb662013-04-05 15:02:01 -0500102 err $line "$*"
Dean Troyer27e32692012-03-16 16:16:56 -0500103 exit $exitcode
Dean Troyer489bd2a2012-03-02 10:44:29 -0600104}
105
106
107# Checks an environment variable is not set or has length 0 OR if the
108# exit code is non-zero and prints "message" and exits
109# NOTE: env-var is the variable name without a '$'
Dean Troyerac93efb2013-03-13 14:30:54 -0500110# die_if_not_set $LINENO env-var "message"
Dean Troyer489bd2a2012-03-02 10:44:29 -0600111function die_if_not_set() {
Dean Troyer896eb662013-04-05 15:02:01 -0500112 local exitcode=$?
113 FXTRACE=$(set +o | grep xtrace)
114 set +o xtrace
115 local line=$1; shift
116 local evar=$1; shift
117 if ! is_set $evar || [ $exitcode != 0 ]; then
118 die $line "$*"
119 fi
120 $FXTRACE
121}
122
123
124# Prints line number and "message" in error format
125# err $LINENO "message"
126function err() {
127 local exitcode=$?
128 errXTRACE=$(set +o | grep xtrace)
129 set +o xtrace
Kui Shi17df0772013-08-02 17:55:41 +0800130 local msg="[ERROR] ${BASH_SOURCE[2]}:$1 $2"
Dean Troyer896eb662013-04-05 15:02:01 -0500131 echo $msg 1>&2;
132 if [[ -n ${SCREEN_LOGDIR} ]]; then
133 echo $msg >> "${SCREEN_LOGDIR}/error.log"
134 fi
135 $errXTRACE
136 return $exitcode
137}
138
139
140# Checks an environment variable is not set or has length 0 OR if the
141# exit code is non-zero and prints "message"
142# NOTE: env-var is the variable name without a '$'
143# err_if_not_set $LINENO env-var "message"
144function err_if_not_set() {
145 local exitcode=$?
146 errinsXTRACE=$(set +o | grep xtrace)
147 set +o xtrace
148 local line=$1; shift
149 local evar=$1; shift
150 if ! is_set $evar || [ $exitcode != 0 ]; then
151 err $line "$*"
152 fi
153 $errinsXTRACE
154 return $exitcode
Dean Troyer489bd2a2012-03-02 10:44:29 -0600155}
156
157
Dean Troyer48352ee2012-12-12 12:50:38 -0600158# HTTP and HTTPS proxy servers are supported via the usual environment variables [1]
159# ``http_proxy``, ``https_proxy`` and ``no_proxy``. They can be set in
160# ``localrc`` or on the command line if necessary::
161#
162# [1] http://www.w3.org/Daemon/User/Proxies/ProxyClients.html
163#
164# http_proxy=http://proxy.example.com:3128/ no_proxy=repo.example.net ./stack.sh
165
166function export_proxy_variables() {
167 if [[ -n "$http_proxy" ]]; then
168 export http_proxy=$http_proxy
169 fi
170 if [[ -n "$https_proxy" ]]; then
171 export https_proxy=$https_proxy
172 fi
173 if [[ -n "$no_proxy" ]]; then
174 export no_proxy=$no_proxy
175 fi
176}
177
178
Dean Troyer489bd2a2012-03-02 10:44:29 -0600179# Grab a numbered field from python prettytable output
180# Fields are numbered starting with 1
181# Reverse syntax is supported: -1 is the last field, -2 is second to last, etc.
182# get_field field-number
183function get_field() {
184 while read data; do
185 if [ "$1" -lt 0 ]; then
186 field="(\$(NF$1))"
187 else
188 field="\$$(($1 + 1))"
189 fi
190 echo "$data" | awk -F'[ \t]*\\|[ \t]*' "{print $field}"
191 done
192}
193
194
Dean Troyerc892bde2013-03-13 14:06:13 -0500195# Get the default value for HOST_IP
196# get_default_host_ip fixed_range floating_range host_ip_iface host_ip
197function get_default_host_ip() {
198 local fixed_range=$1
199 local floating_range=$2
200 local host_ip_iface=$3
201 local host_ip=$4
202
203 # Find the interface used for the default route
204 host_ip_iface=${host_ip_iface:-$(ip route | sed -n '/^default/{ s/.*dev \(\w\+\)\s\+.*/\1/; p; }' | head -1)}
205 # Search for an IP unless an explicit is set by ``HOST_IP`` environment variable
206 if [ -z "$host_ip" -o "$host_ip" == "dhcp" ]; then
207 host_ip=""
208 host_ips=`LC_ALL=C ip -f inet addr show ${host_ip_iface} | awk '/inet/ {split($2,parts,"/"); print parts[1]}'`
209 for IP in $host_ips; do
210 # Attempt to filter out IP addresses that are part of the fixed and
211 # floating range. Note that this method only works if the ``netaddr``
212 # python library is installed. If it is not installed, an error
213 # will be printed and the first IP from the interface will be used.
214 # If that is not correct set ``HOST_IP`` in ``localrc`` to the correct
215 # address.
216 if ! (address_in_net $IP $fixed_range || address_in_net $IP $floating_range); then
217 host_ip=$IP
218 break;
219 fi
220 done
221 fi
222 echo $host_ip
223}
224
225
Isaku Yamahata8c438092013-02-12 22:30:56 +0900226function _get_package_dir() {
227 local pkg_dir
228 if is_ubuntu; then
229 pkg_dir=$FILES/apts
230 elif is_fedora; then
231 pkg_dir=$FILES/rpms
232 elif is_suse; then
233 pkg_dir=$FILES/rpms-suse
234 else
235 exit_distro_not_supported "list of packages"
236 fi
237 echo "$pkg_dir"
238}
239
Dean Troyer1a6d4492013-06-03 16:47:36 -0500240
Dean Troyer7e270512012-06-14 15:23:24 -0500241# get_packages() collects a list of package names of any type from the
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500242# prerequisite files in ``files/{apts|rpms}``. The list is intended
243# to be passed to a package installer such as apt or yum.
Dean Troyer7e270512012-06-14 15:23:24 -0500244#
Isaku Yamahata8c438092013-02-12 22:30:56 +0900245# Only packages required for the services in 1st argument will be
Dean Troyer7e270512012-06-14 15:23:24 -0500246# included. Two bits of metadata are recognized in the prerequisite files:
247# - ``# NOPRIME`` defers installation to be performed later in stack.sh
248# - ``# dist:DISTRO`` or ``dist:DISTRO1,DISTRO2`` limits the selection
249# of the package to the distros listed. The distro names are case insensitive.
Dean Troyer7e270512012-06-14 15:23:24 -0500250function get_packages() {
Isaku Yamahata8c438092013-02-12 22:30:56 +0900251 local services=$1
252 local package_dir=$(_get_package_dir)
Dean Troyer7e270512012-06-14 15:23:24 -0500253 local file_to_parse
254 local service
255
256 if [[ -z "$package_dir" ]]; then
257 echo "No package directory supplied"
258 return 1
259 fi
260 if [[ -z "$DISTRO" ]]; then
Vincent Untz855c5872012-10-04 13:36:46 +0200261 GetDistro
Dean Troyer7e270512012-06-14 15:23:24 -0500262 fi
Isaku Yamahata8c438092013-02-12 22:30:56 +0900263 for service in general ${services//,/ }; do
Dean Troyer7e270512012-06-14 15:23:24 -0500264 # Allow individual services to specify dependencies
265 if [[ -e ${package_dir}/${service} ]]; then
266 file_to_parse="${file_to_parse} $service"
267 fi
268 # NOTE(sdague) n-api needs glance for now because that's where
269 # glance client is
270 if [[ $service == n-api ]]; then
271 if [[ ! $file_to_parse =~ nova ]]; then
272 file_to_parse="${file_to_parse} nova"
273 fi
274 if [[ ! $file_to_parse =~ glance ]]; then
275 file_to_parse="${file_to_parse} glance"
276 fi
277 elif [[ $service == c-* ]]; then
278 if [[ ! $file_to_parse =~ cinder ]]; then
279 file_to_parse="${file_to_parse} cinder"
280 fi
John H. Tran93361642012-07-26 11:22:05 -0700281 elif [[ $service == ceilometer-* ]]; then
282 if [[ ! $file_to_parse =~ ceilometer ]]; then
283 file_to_parse="${file_to_parse} ceilometer"
284 fi
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100285 elif [[ $service == s-* ]]; then
286 if [[ ! $file_to_parse =~ swift ]]; then
287 file_to_parse="${file_to_parse} swift"
288 fi
Dean Troyer7e270512012-06-14 15:23:24 -0500289 elif [[ $service == n-* ]]; then
290 if [[ ! $file_to_parse =~ nova ]]; then
291 file_to_parse="${file_to_parse} nova"
292 fi
293 elif [[ $service == g-* ]]; then
294 if [[ ! $file_to_parse =~ glance ]]; then
295 file_to_parse="${file_to_parse} glance"
296 fi
297 elif [[ $service == key* ]]; then
298 if [[ ! $file_to_parse =~ keystone ]]; then
299 file_to_parse="${file_to_parse} keystone"
300 fi
Robert Collins0a9954f2012-11-20 11:34:25 +1300301 elif [[ $service == q-* ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400302 if [[ ! $file_to_parse =~ neutron ]]; then
303 file_to_parse="${file_to_parse} neutron"
Robert Collins0a9954f2012-11-20 11:34:25 +1300304 fi
Dean Troyer7e270512012-06-14 15:23:24 -0500305 fi
306 done
307
308 for file in ${file_to_parse}; do
309 local fname=${package_dir}/${file}
310 local OIFS line package distros distro
311 [[ -e $fname ]] || continue
312
313 OIFS=$IFS
314 IFS=$'\n'
315 for line in $(<${fname}); do
316 if [[ $line =~ "NOPRIME" ]]; then
317 continue
318 fi
319
Christian Berendt71d56302013-07-22 11:37:42 +0200320 # Assume we want this package
321 package=${line%#*}
322 inst_pkg=1
323
324 # Look for # dist:xxx in comment
Dean Troyer7e270512012-06-14 15:23:24 -0500325 if [[ $line =~ (.*)#.*dist:([^ ]*) ]]; then
326 # We are using BASH regexp matching feature.
327 package=${BASH_REMATCH[1]}
328 distros=${BASH_REMATCH[2]}
329 # In bash ${VAR,,} will lowecase VAR
Christian Berendt71d56302013-07-22 11:37:42 +0200330 # Look for a match in the distro list
331 if [[ ! ${distros,,} =~ ${DISTRO,,} ]]; then
332 # If no match then skip this package
333 inst_pkg=0
334 fi
Dean Troyer7e270512012-06-14 15:23:24 -0500335 fi
336
Christian Berendt71d56302013-07-22 11:37:42 +0200337 # Look for # testonly in comment
338 if [[ $line =~ (.*)#.*testonly.* ]]; then
339 package=${BASH_REMATCH[1]}
340 # Are we installing test packages? (test for the default value)
341 if [[ $INSTALL_TESTONLY_PACKAGES = "False" ]]; then
342 # If not installing test packages the skip this package
343 inst_pkg=0
344 fi
345 fi
346
347 if [[ $inst_pkg = 1 ]]; then
348 echo $package
349 fi
Dean Troyer7e270512012-06-14 15:23:24 -0500350 done
351 IFS=$OIFS
352 done
353}
354
355
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500356# Determine OS Vendor, Release and Update
357# Tested with OS/X, Ubuntu, RedHat, CentOS, Fedora
358# Returns results in global variables:
359# os_VENDOR - vendor name
360# os_RELEASE - release
361# os_UPDATE - update
362# os_PACKAGE - package type
363# os_CODENAME - vendor's codename for release
364# GetOSVersion
365GetOSVersion() {
366 # Figure out which vendor we are
Mehdi Abaakoukaee94122013-09-30 11:48:00 +0000367 if [[ -x "`which sw_vers 2>/dev/null`" ]]; then
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500368 # OS/X
369 os_VENDOR=`sw_vers -productName`
370 os_RELEASE=`sw_vers -productVersion`
371 os_UPDATE=${os_RELEASE##*.}
372 os_RELEASE=${os_RELEASE%.*}
373 os_PACKAGE=""
374 if [[ "$os_RELEASE" =~ "10.7" ]]; then
375 os_CODENAME="lion"
376 elif [[ "$os_RELEASE" =~ "10.6" ]]; then
377 os_CODENAME="snow leopard"
378 elif [[ "$os_RELEASE" =~ "10.5" ]]; then
379 os_CODENAME="leopard"
380 elif [[ "$os_RELEASE" =~ "10.4" ]]; then
381 os_CODENAME="tiger"
382 elif [[ "$os_RELEASE" =~ "10.3" ]]; then
383 os_CODENAME="panther"
384 else
385 os_CODENAME=""
386 fi
387 elif [[ -x $(which lsb_release 2>/dev/null) ]]; then
388 os_VENDOR=$(lsb_release -i -s)
389 os_RELEASE=$(lsb_release -r -s)
390 os_UPDATE=""
Attila Fazekasaf988fd2013-01-13 14:20:47 +0100391 os_PACKAGE="rpm"
Derek Morton4a8496e2013-04-08 23:46:08 -0500392 if [[ "Debian,Ubuntu,LinuxMint" =~ $os_VENDOR ]]; then
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500393 os_PACKAGE="deb"
Vincent Untz856a11e2012-11-21 16:04:12 +0100394 elif [[ "SUSE LINUX" =~ $os_VENDOR ]]; then
395 lsb_release -d -s | grep -q openSUSE
396 if [[ $? -eq 0 ]]; then
397 os_VENDOR="openSUSE"
398 fi
Vincent Untzcd1fe982013-03-12 18:04:29 +0100399 elif [[ $os_VENDOR == "openSUSE project" ]]; then
400 os_VENDOR="openSUSE"
Attila Fazekasaf988fd2013-01-13 14:20:47 +0100401 elif [[ $os_VENDOR =~ Red.*Hat ]]; then
402 os_VENDOR="Red Hat"
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500403 fi
404 os_CODENAME=$(lsb_release -c -s)
405 elif [[ -r /etc/redhat-release ]]; then
406 # Red Hat Enterprise Linux Server release 5.5 (Tikanga)
407 # CentOS release 5.5 (Final)
408 # CentOS Linux release 6.0 (Final)
409 # Fedora release 16 (Verne)
Bob Ball46691222013-08-12 17:28:50 +0100410 # XenServer release 6.2.0-70446c (xenenterprise)
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500411 os_CODENAME=""
Bob Ball46691222013-08-12 17:28:50 +0100412 for r in "Red Hat" CentOS Fedora XenServer; do
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500413 os_VENDOR=$r
414 if [[ -n "`grep \"$r\" /etc/redhat-release`" ]]; then
415 ver=`sed -e 's/^.* \(.*\) (\(.*\)).*$/\1\|\2/' /etc/redhat-release`
416 os_CODENAME=${ver#*|}
417 os_RELEASE=${ver%|*}
418 os_UPDATE=${os_RELEASE##*.}
419 os_RELEASE=${os_RELEASE%.*}
420 break
421 fi
422 os_VENDOR=""
423 done
424 os_PACKAGE="rpm"
Vincent Untz856a11e2012-11-21 16:04:12 +0100425 elif [[ -r /etc/SuSE-release ]]; then
426 for r in openSUSE "SUSE Linux"; do
427 if [[ "$r" = "SUSE Linux" ]]; then
428 os_VENDOR="SUSE LINUX"
429 else
430 os_VENDOR=$r
431 fi
432
433 if [[ -n "`grep \"$r\" /etc/SuSE-release`" ]]; then
434 os_CODENAME=`grep "CODENAME = " /etc/SuSE-release | sed 's:.* = ::g'`
435 os_RELEASE=`grep "VERSION = " /etc/SuSE-release | sed 's:.* = ::g'`
436 os_UPDATE=`grep "PATCHLEVEL = " /etc/SuSE-release | sed 's:.* = ::g'`
437 break
438 fi
439 os_VENDOR=""
440 done
441 os_PACKAGE="rpm"
Émilien Macchib2ef8902013-05-04 00:48:20 +0200442 # If lsb_release is not installed, we should be able to detect Debian OS
443 elif [[ -f /etc/debian_version ]] && [[ $(cat /proc/version) =~ "Debian" ]]; then
444 os_VENDOR="Debian"
445 os_PACKAGE="deb"
446 os_CODENAME=$(awk '/VERSION=/' /etc/os-release | sed 's/VERSION=//' | sed -r 's/\"|\(|\)//g' | awk '{print $2}')
447 os_RELEASE=$(awk '/VERSION_ID=/' /etc/os-release | sed 's/VERSION_ID=//' | sed 's/\"//g')
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500448 fi
449 export os_VENDOR os_RELEASE os_UPDATE os_PACKAGE os_CODENAME
450}
451
Andrew Laskif900bd72012-09-05 17:23:14 -0400452
Dean Troyera9e0a482012-07-09 14:07:23 -0500453# Translate the OS version values into common nomenclature
454# Sets ``DISTRO`` from the ``os_*`` values
455function GetDistro() {
456 GetOSVersion
Émilien Macchib2ef8902013-05-04 00:48:20 +0200457 if [[ "$os_VENDOR" =~ (Ubuntu) || "$os_VENDOR" =~ (Debian) ]]; then
458 # 'Everyone' refers to Ubuntu / Debian releases by the code name adjective
Dean Troyera9e0a482012-07-09 14:07:23 -0500459 DISTRO=$os_CODENAME
460 elif [[ "$os_VENDOR" =~ (Fedora) ]]; then
461 # For Fedora, just use 'f' and the release
462 DISTRO="f$os_RELEASE"
Vincent Untz856a11e2012-11-21 16:04:12 +0100463 elif [[ "$os_VENDOR" =~ (openSUSE) ]]; then
464 DISTRO="opensuse-$os_RELEASE"
465 elif [[ "$os_VENDOR" =~ (SUSE LINUX) ]]; then
466 # For SLE, also use the service pack
467 if [[ -z "$os_UPDATE" ]]; then
468 DISTRO="sle${os_RELEASE}"
469 else
470 DISTRO="sle${os_RELEASE}sp${os_UPDATE}"
471 fi
Ian Wienandd857f4b2013-03-20 14:51:06 +1100472 elif [[ "$os_VENDOR" =~ (Red Hat) || "$os_VENDOR" =~ (CentOS) ]]; then
473 # Drop the . release as we assume it's compatible
474 DISTRO="rhel${os_RELEASE::1}"
Bob Ball46691222013-08-12 17:28:50 +0100475 elif [[ "$os_VENDOR" =~ (XenServer) ]]; then
476 DISTRO="xs$os_RELEASE"
Dean Troyera9e0a482012-07-09 14:07:23 -0500477 else
478 # Catch-all for now is Vendor + Release + Update
479 DISTRO="$os_VENDOR-$os_RELEASE.$os_UPDATE"
480 fi
481 export DISTRO
482}
483
484
Vincent Untz00011c02012-12-06 09:56:32 +0100485# Determine if current distribution is a Fedora-based distribution
Dean Troyer1a6d4492013-06-03 16:47:36 -0500486# (Fedora, RHEL, CentOS, etc).
Vincent Untz00011c02012-12-06 09:56:32 +0100487# is_fedora
488function is_fedora {
489 if [[ -z "$os_VENDOR" ]]; then
490 GetOSVersion
491 fi
492
493 [ "$os_VENDOR" = "Fedora" ] || [ "$os_VENDOR" = "Red Hat" ] || [ "$os_VENDOR" = "CentOS" ]
494}
495
Dean Troyer1a6d4492013-06-03 16:47:36 -0500496
Vincent Untz856a11e2012-11-21 16:04:12 +0100497# Determine if current distribution is a SUSE-based distribution
498# (openSUSE, SLE).
499# is_suse
500function is_suse {
501 if [[ -z "$os_VENDOR" ]]; then
502 GetOSVersion
503 fi
504
Steve Baker1a7bbd22012-12-03 17:04:02 +1300505 [ "$os_VENDOR" = "openSUSE" ] || [ "$os_VENDOR" = "SUSE LINUX" ]
Vincent Untz856a11e2012-11-21 16:04:12 +0100506}
507
508
Dean Troyer1a6d4492013-06-03 16:47:36 -0500509# Determine if current distribution is an Ubuntu-based distribution
510# It will also detect non-Ubuntu but Debian-based distros
511# is_ubuntu
512function is_ubuntu {
513 if [[ -z "$os_PACKAGE" ]]; then
514 GetOSVersion
515 fi
516 [ "$os_PACKAGE" = "deb" ]
517}
518
519
Vincent Untz00011c02012-12-06 09:56:32 +0100520# Exit after outputting a message about the distribution not being supported.
521# exit_distro_not_supported [optional-string-telling-what-is-missing]
522function exit_distro_not_supported {
523 if [[ -z "$DISTRO" ]]; then
524 GetDistro
525 fi
526
527 if [ $# -gt 0 ]; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800528 die $LINENO "Support for $DISTRO is incomplete: no support for $@"
Vincent Untz00011c02012-12-06 09:56:32 +0100529 else
Nachi Ueno07115eb2013-02-26 12:38:18 -0800530 die $LINENO "Support for $DISTRO is incomplete."
Vincent Untz00011c02012-12-06 09:56:32 +0100531 fi
Vincent Untz00011c02012-12-06 09:56:32 +0100532}
533
Daniel Jonesfa868cb2013-06-18 15:28:01 -0500534# Utility function for checking machine architecture
535# is_arch arch-type
536function is_arch {
537 ARCH_TYPE=$1
538
539 [ "($uname -m)" = "$ARCH_TYPE" ]
540}
Vincent Untz00011c02012-12-06 09:56:32 +0100541
Dean Troyer7f9aa712012-01-31 12:11:56 -0600542# git clone only if directory doesn't exist already. Since ``DEST`` might not
543# be owned by the installation user, we create the directory and change the
544# ownership to the proper user.
545# Set global RECLONE=yes to simulate a clone when dest-dir exists
James E. Blair94cb9602012-06-22 15:28:29 -0700546# Set global ERROR_ON_CLONE=True to abort execution with an error if the git repo
547# does not exist (default is False, meaning the repo will be cloned).
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500548# Uses global ``OFFLINE``
Dean Troyer7f9aa712012-01-31 12:11:56 -0600549# git_clone remote dest-dir branch
550function git_clone {
Dean Troyer7f9aa712012-01-31 12:11:56 -0600551 GIT_REMOTE=$1
552 GIT_DEST=$2
Evgeniy Afonichev6a3912d2012-07-10 14:02:43 +0300553 GIT_REF=$3
Sirushti Murugesana8d41e32013-09-25 11:30:31 +0530554 RECLONE=$(trueorfalse False $RECLONE)
Dean Troyer7f9aa712012-01-31 12:11:56 -0600555
Sean Dague835db2f2013-09-23 14:17:06 -0400556 if [[ "$OFFLINE" = "True" ]]; then
557 echo "Running in offline mode, clones already exist"
558 # print out the results so we know what change was used in the logs
559 cd $GIT_DEST
Sean Dague45a21f02013-09-25 10:27:27 -0400560 git show --oneline | head -1
Sean Dague835db2f2013-09-23 14:17:06 -0400561 return
562 fi
563
Evgeniy Afonichev6a3912d2012-07-10 14:02:43 +0300564 if echo $GIT_REF | egrep -q "^refs"; then
Dean Troyer7f9aa712012-01-31 12:11:56 -0600565 # If our branch name is a gerrit style refs/changes/...
566 if [[ ! -d $GIT_DEST ]]; then
James E. Blair94cb9602012-06-22 15:28:29 -0700567 [[ "$ERROR_ON_CLONE" = "True" ]] && exit 1
Dean Troyer7f9aa712012-01-31 12:11:56 -0600568 git clone $GIT_REMOTE $GIT_DEST
569 fi
570 cd $GIT_DEST
Evgeniy Afonichev6a3912d2012-07-10 14:02:43 +0300571 git fetch $GIT_REMOTE $GIT_REF && git checkout FETCH_HEAD
Dean Troyer7f9aa712012-01-31 12:11:56 -0600572 else
573 # do a full clone only if the directory doesn't exist
574 if [[ ! -d $GIT_DEST ]]; then
James E. Blair94cb9602012-06-22 15:28:29 -0700575 [[ "$ERROR_ON_CLONE" = "True" ]] && exit 1
Dean Troyer7f9aa712012-01-31 12:11:56 -0600576 git clone $GIT_REMOTE $GIT_DEST
577 cd $GIT_DEST
578 # This checkout syntax works for both branches and tags
Evgeniy Afonichev6a3912d2012-07-10 14:02:43 +0300579 git checkout $GIT_REF
Sirushti Murugesana8d41e32013-09-25 11:30:31 +0530580 elif [[ "$RECLONE" = "True" ]]; then
Dean Troyer7f9aa712012-01-31 12:11:56 -0600581 # if it does exist then simulate what clone does if asked to RECLONE
582 cd $GIT_DEST
583 # set the url to pull from and fetch
584 git remote set-url origin $GIT_REMOTE
585 git fetch origin
586 # remove the existing ignored files (like pyc) as they cause breakage
587 # (due to the py files having older timestamps than our pyc, so python
588 # thinks the pyc files are correct using them)
589 find $GIT_DEST -name '*.pyc' -delete
Evgeniy Afonichev6a3912d2012-07-10 14:02:43 +0300590
591 # handle GIT_REF accordingly to type (tag, branch)
592 if [[ -n "`git show-ref refs/tags/$GIT_REF`" ]]; then
593 git_update_tag $GIT_REF
594 elif [[ -n "`git show-ref refs/heads/$GIT_REF`" ]]; then
595 git_update_branch $GIT_REF
Andrew Laskif900bd72012-09-05 17:23:14 -0400596 elif [[ -n "`git show-ref refs/remotes/origin/$GIT_REF`" ]]; then
597 git_update_remote_branch $GIT_REF
Evgeniy Afonichev6a3912d2012-07-10 14:02:43 +0300598 else
599 echo $GIT_REF is neither branch nor tag
600 exit 1
601 fi
602
Dean Troyer7f9aa712012-01-31 12:11:56 -0600603 fi
604 fi
Sean Dague835db2f2013-09-23 14:17:06 -0400605
606 # print out the results so we know what change was used in the logs
607 cd $GIT_DEST
Sean Dague45a21f02013-09-25 10:27:27 -0400608 git show --oneline | head -1
Dean Troyer7f9aa712012-01-31 12:11:56 -0600609}
610
611
Dean Troyer1a6d4492013-06-03 16:47:36 -0500612# git update using reference as a branch.
613# git_update_branch ref
614function git_update_branch() {
615
616 GIT_BRANCH=$1
617
618 git checkout -f origin/$GIT_BRANCH
619 # a local branch might not exist
620 git branch -D $GIT_BRANCH || true
621 git checkout -b $GIT_BRANCH
622}
623
624
625# git update using reference as a branch.
626# git_update_remote_branch ref
627function git_update_remote_branch() {
628
629 GIT_BRANCH=$1
630
631 git checkout -b $GIT_BRANCH -t origin/$GIT_BRANCH
632}
633
634
635# git update using reference as a tag. Be careful editing source at that repo
636# as working copy will be in a detached mode
637# git_update_tag ref
638function git_update_tag() {
639
640 GIT_TAG=$1
641
642 git tag -d $GIT_TAG
643 # fetching given tag only
644 git fetch origin tag $GIT_TAG
645 git checkout -f $GIT_TAG
646}
647
648
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500649# Comment an option in an INI file
Chmouel Boudjnahc7214e82012-06-06 13:56:39 +0200650# inicomment config-file section option
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500651function inicomment() {
652 local file=$1
653 local section=$2
654 local option=$3
Attila Fazekas588eb412012-12-20 10:57:16 +0100655 sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=.*$\)|#\1|" "$file"
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500656}
657
Dean Troyer896eb662013-04-05 15:02:01 -0500658
Chmouel Boudjnahc7214e82012-06-06 13:56:39 +0200659# Uncomment an option in an INI file
660# iniuncomment config-file section option
661function iniuncomment() {
662 local file=$1
663 local section=$2
664 local option=$3
Attila Fazekas588eb412012-12-20 10:57:16 +0100665 sed -i -e "/^\[$section\]/,/^\[.*\]/ s|[^ \t]*#[ \t]*\($option[ \t]*=.*$\)|\1|" "$file"
Chmouel Boudjnahc7214e82012-06-06 13:56:39 +0200666}
667
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500668
669# Get an option from an INI file
Dean Troyer09e636e2012-03-19 16:31:12 -0500670# iniget config-file section option
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500671function iniget() {
672 local file=$1
673 local section=$2
674 local option=$3
675 local line
Attila Fazekas588eb412012-12-20 10:57:16 +0100676 line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file")
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500677 echo ${line#*=}
678}
679
Dean Troyer896eb662013-04-05 15:02:01 -0500680
Attila Fazekas588eb412012-12-20 10:57:16 +0100681# Determinate is the given option present in the INI file
682# ini_has_option config-file section option
683function ini_has_option() {
684 local file=$1
685 local section=$2
686 local option=$3
687 local line
688 line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file")
689 [ -n "$line" ]
690}
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500691
Dean Troyer896eb662013-04-05 15:02:01 -0500692
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500693# Set an option in an INI file
Dean Troyer09e636e2012-03-19 16:31:12 -0500694# iniset config-file section option value
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500695function iniset() {
696 local file=$1
697 local section=$2
698 local option=$3
699 local value=$4
DennyZhangf43f3a52013-10-11 23:09:47 -0500700
701 if ! grep -q "^\[$section\]" "$file" 2>/dev/null; then
Dean Troyer09e636e2012-03-19 16:31:12 -0500702 # Add section at the end
Attila Fazekas588eb412012-12-20 10:57:16 +0100703 echo -e "\n[$section]" >>"$file"
Dean Troyer09e636e2012-03-19 16:31:12 -0500704 fi
Attila Fazekas588eb412012-12-20 10:57:16 +0100705 if ! ini_has_option "$file" "$section" "$option"; then
Dean Troyer09e636e2012-03-19 16:31:12 -0500706 # Add it
Attila Fazekas588eb412012-12-20 10:57:16 +0100707 sed -i -e "/^\[$section\]/ a\\
Dean Troyer09e636e2012-03-19 16:31:12 -0500708$option = $value
Attila Fazekas588eb412012-12-20 10:57:16 +0100709" "$file"
Dean Troyer09e636e2012-03-19 16:31:12 -0500710 else
711 # Replace it
Attila Fazekas588eb412012-12-20 10:57:16 +0100712 sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=[ \t]*\).*$|\1$value|" "$file"
Dean Troyer09e636e2012-03-19 16:31:12 -0500713 fi
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500714}
715
Dean Troyer896eb662013-04-05 15:02:01 -0500716
Lianhao Lu239f3242013-03-01 15:54:02 +0800717# Get a multiple line option from an INI file
718# iniget_multiline config-file section option
719function iniget_multiline() {
720 local file=$1
721 local section=$2
722 local option=$3
723 local values
724 values=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { s/^$option[ \t]*=[ \t]*//gp; }" "$file")
725 echo ${values}
726}
727
Dean Troyer896eb662013-04-05 15:02:01 -0500728
Lianhao Lu239f3242013-03-01 15:54:02 +0800729# Set a multiple line option in an INI file
730# iniset_multiline config-file section option value1 value2 valu3 ...
731function iniset_multiline() {
732 local file=$1
733 local section=$2
734 local option=$3
735 shift 3
736 local values
737 for v in $@; do
738 # The later sed command inserts each new value in the line next to
739 # the section identifier, which causes the values to be inserted in
740 # the reverse order. Do a reverse here to keep the original order.
741 values="$v ${values}"
742 done
743 if ! grep -q "^\[$section\]" "$file"; then
744 # Add section at the end
745 echo -e "\n[$section]" >>"$file"
746 else
747 # Remove old values
748 sed -i -e "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ d; }" "$file"
749 fi
750 # Add new ones
751 for v in $values; do
752 sed -i -e "/^\[$section\]/ a\\
753$option = $v
754" "$file"
755 done
756}
757
Dean Troyer896eb662013-04-05 15:02:01 -0500758
Lianhao Lu239f3242013-03-01 15:54:02 +0800759# Append a new option in an ini file without replacing the old value
760# iniadd config-file section option value1 value2 value3 ...
761function iniadd() {
762 local file=$1
763 local section=$2
764 local option=$3
765 shift 3
766 local values="$(iniget_multiline $file $section $option) $@"
767 iniset_multiline $file $section $option $values
768}
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500769
Dean Troyer896eb662013-04-05 15:02:01 -0500770# Find out if a process exists by partial name.
771# is_running name
772function is_running() {
773 local name=$1
774 ps auxw | grep -v grep | grep ${name} > /dev/null
775 RC=$?
776 # some times I really hate bash reverse binary logic
777 return $RC
778}
779
780
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000781# is_service_enabled() checks if the service(s) specified as arguments are
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500782# enabled by the user in ``ENABLED_SERVICES``.
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000783#
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500784# Multiple services specified as arguments are ``OR``'ed together; the test
785# is a short-circuit boolean, i.e it returns on the first match.
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000786#
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500787# There are special cases for some 'catch-all' services::
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000788# **nova** returns true if any service enabled start with **n-**
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500789# **cinder** returns true if any service enabled start with **c-**
790# **ceilometer** returns true if any service enabled start with **ceilometer**
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000791# **glance** returns true if any service enabled start with **g-**
Mark McClainb05c8762013-07-06 23:29:39 -0400792# **neutron** returns true if any service enabled start with **q-**
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100793# **swift** returns true if any service enabled start with **s-**
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700794# **trove** returns true if any service enabled start with **tr-**
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100795# For backward compatibility if we have **swift** in ENABLED_SERVICES all the
796# **s-** services will be enabled. This will be deprecated in the future.
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500797#
Chris Behrensc62c2b92013-07-24 03:56:13 -0700798# Cells within nova is enabled if **n-cell** is in ``ENABLED_SERVICES``.
799# We also need to make sure to treat **n-cell-region** and **n-cell-child**
800# as enabled in this case.
801#
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500802# Uses global ``ENABLED_SERVICES``
803# is_service_enabled service [service ...]
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000804function is_service_enabled() {
805 services=$@
806 for service in ${services}; do
807 [[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && return 0
Chris Behrensc62c2b92013-07-24 03:56:13 -0700808 [[ ${service} == n-cell-* && ${ENABLED_SERVICES} =~ "n-cell" ]] && return 0
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000809 [[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && return 0
Dean Troyer67787e62012-05-02 11:48:15 -0500810 [[ ${service} == "cinder" && ${ENABLED_SERVICES} =~ "c-" ]] && return 0
John H. Tran93361642012-07-26 11:22:05 -0700811 [[ ${service} == "ceilometer" && ${ENABLED_SERVICES} =~ "ceilometer-" ]] && return 0
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000812 [[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && return 0
Mark McClainb05c8762013-07-06 23:29:39 -0400813 [[ ${service} == "neutron" && ${ENABLED_SERVICES} =~ "q-" ]] && return 0
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700814 [[ ${service} == "trove" && ${ENABLED_SERVICES} =~ "tr-" ]] && return 0
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100815 [[ ${service} == "swift" && ${ENABLED_SERVICES} =~ "s-" ]] && return 0
816 [[ ${service} == s-* && ${ENABLED_SERVICES} =~ "swift" ]] && return 0
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000817 done
818 return 1
819}
820
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500821
822# remove extra commas from the input string (i.e. ``ENABLED_SERVICES``)
823# _cleanup_service_list service-list
Doug Hellmannf04178f2012-07-05 17:10:03 -0400824function _cleanup_service_list () {
Dean Troyerca0e3d02012-04-13 15:58:37 -0500825 echo "$1" | sed -e '
Doug Hellmannf04178f2012-07-05 17:10:03 -0400826 s/,,/,/g;
827 s/^,//;
828 s/,$//
829 '
830}
831
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500832
Doug Hellmannf04178f2012-07-05 17:10:03 -0400833# enable_service() adds the services passed as argument to the
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500834# ``ENABLED_SERVICES`` list, if they are not already present.
Doug Hellmannf04178f2012-07-05 17:10:03 -0400835#
836# For example:
Joe Gordon6fd28112012-11-13 16:55:41 -0800837# enable_service qpid
Doug Hellmannf04178f2012-07-05 17:10:03 -0400838#
839# This function does not know about the special cases
Mark McClainb05c8762013-07-06 23:29:39 -0400840# for nova, glance, and neutron built into is_service_enabled().
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500841# Uses global ``ENABLED_SERVICES``
842# enable_service service [service ...]
Doug Hellmannf04178f2012-07-05 17:10:03 -0400843function enable_service() {
844 local tmpsvcs="${ENABLED_SERVICES}"
845 for service in $@; do
846 if ! is_service_enabled $service; then
847 tmpsvcs+=",$service"
848 fi
849 done
850 ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs")
851 disable_negated_services
852}
853
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500854
Doug Hellmannf04178f2012-07-05 17:10:03 -0400855# disable_service() removes the services passed as argument to the
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500856# ``ENABLED_SERVICES`` list, if they are present.
Doug Hellmannf04178f2012-07-05 17:10:03 -0400857#
858# For example:
Joe Gordon6fd28112012-11-13 16:55:41 -0800859# disable_service rabbit
Doug Hellmannf04178f2012-07-05 17:10:03 -0400860#
861# This function does not know about the special cases
Mark McClainb05c8762013-07-06 23:29:39 -0400862# for nova, glance, and neutron built into is_service_enabled().
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500863# Uses global ``ENABLED_SERVICES``
864# disable_service service [service ...]
Doug Hellmannf04178f2012-07-05 17:10:03 -0400865function disable_service() {
866 local tmpsvcs=",${ENABLED_SERVICES},"
867 local service
868 for service in $@; do
869 if is_service_enabled $service; then
870 tmpsvcs=${tmpsvcs//,$service,/,}
871 fi
872 done
873 ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs")
874}
875
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500876
Doug Hellmannf04178f2012-07-05 17:10:03 -0400877# disable_all_services() removes all current services
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500878# from ``ENABLED_SERVICES`` to reset the configuration
Doug Hellmannf04178f2012-07-05 17:10:03 -0400879# before a minimal installation
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500880# Uses global ``ENABLED_SERVICES``
881# disable_all_services
Doug Hellmannf04178f2012-07-05 17:10:03 -0400882function disable_all_services() {
883 ENABLED_SERVICES=""
884}
885
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500886
887# Remove all services starting with '-'. For example, to install all default
Joe Gordon6fd28112012-11-13 16:55:41 -0800888# services except rabbit (rabbit) set in ``localrc``:
889# ENABLED_SERVICES+=",-rabbit"
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500890# Uses global ``ENABLED_SERVICES``
891# disable_negated_services
Doug Hellmannf04178f2012-07-05 17:10:03 -0400892function disable_negated_services() {
893 local tmpsvcs="${ENABLED_SERVICES}"
894 local service
895 for service in ${tmpsvcs//,/ }; do
896 if [[ ${service} == -* ]]; then
897 tmpsvcs=$(echo ${tmpsvcs}|sed -r "s/(,)?(-)?${service#-}(,)?/,/g")
898 fi
899 done
900 ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs")
901}
Dean Troyer489bd2a2012-03-02 10:44:29 -0600902
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500903
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500904# Distro-agnostic package installer
905# install_package package [package ...]
906function install_package() {
Vincent Untzc18b9652012-12-04 12:36:34 +0100907 if is_ubuntu; then
Vincent Untzc0482e62012-06-12 11:30:43 +0200908 [[ "$NO_UPDATE_REPOS" = "True" ]] || apt_get update
909 NO_UPDATE_REPOS=True
910
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500911 apt_get install "$@"
Vincent Untz00011c02012-12-06 09:56:32 +0100912 elif is_fedora; then
913 yum_install "$@"
914 elif is_suse; then
915 zypper_install "$@"
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500916 else
Vincent Untz00011c02012-12-06 09:56:32 +0100917 exit_distro_not_supported "installing packages"
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500918 fi
919}
920
921
Dean Troyer995eb922013-03-07 16:11:40 -0600922# Distro-agnostic package uninstaller
923# uninstall_package package [package ...]
924function uninstall_package() {
925 if is_ubuntu; then
926 apt_get purge "$@"
927 elif is_fedora; then
Ian Wienand2c678cc2013-03-20 13:00:44 +1100928 sudo yum remove -y "$@"
Dean Troyer995eb922013-03-07 16:11:40 -0600929 elif is_suse; then
Adam Spiers6d8fce72013-10-01 15:59:05 +0100930 sudo zypper rm "$@"
Dean Troyer995eb922013-03-07 16:11:40 -0600931 else
932 exit_distro_not_supported "uninstalling packages"
933 fi
934}
935
936
Vincent Untz71ebc6f2012-06-12 13:45:15 +0200937# Distro-agnostic function to tell if a package is installed
938# is_package_installed package [package ...]
939function is_package_installed() {
940 if [[ -z "$@" ]]; then
941 return 1
942 fi
943
944 if [[ -z "$os_PACKAGE" ]]; then
945 GetOSVersion
946 fi
Vincent Untzc18b9652012-12-04 12:36:34 +0100947
Vincent Untz71ebc6f2012-06-12 13:45:15 +0200948 if [[ "$os_PACKAGE" = "deb" ]]; then
Dean Troyer04762cd2013-08-27 17:06:14 -0500949 dpkg -s "$@" > /dev/null 2> /dev/null
Vincent Untz00011c02012-12-06 09:56:32 +0100950 elif [[ "$os_PACKAGE" = "rpm" ]]; then
Vincent Untz71ebc6f2012-06-12 13:45:15 +0200951 rpm --quiet -q "$@"
Vincent Untz00011c02012-12-06 09:56:32 +0100952 else
953 exit_distro_not_supported "finding if a package is installed"
Vincent Untz71ebc6f2012-06-12 13:45:15 +0200954 fi
955}
956
957
Dean Troyer489bd2a2012-03-02 10:44:29 -0600958# Test if the named environment variable is set and not zero length
959# is_set env-var
960function is_set() {
961 local var=\$"$1"
Attila Fazekas251d3b52012-12-16 15:05:44 +0100962 eval "[ -n \"$var\" ]" # For ex.: sh -c "[ -n \"$var\" ]" would be better, but several exercises depends on this
Dean Troyer489bd2a2012-03-02 10:44:29 -0600963}
964
965
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500966# Wrapper for ``pip install`` to set cache and proxy environment variables
Maru Newby3a87edd2012-10-25 23:01:06 +0000967# Uses globals ``OFFLINE``, ``PIP_DOWNLOAD_CACHE``, ``PIP_USE_MIRRORS``,
968# ``TRACK_DEPENDS``, ``*_proxy`
Dean Troyer7f9aa712012-01-31 12:11:56 -0600969# pip_install package [package ...]
970function pip_install {
Dean Troyerd0b21e22012-03-07 14:52:25 -0600971 [[ "$OFFLINE" = "True" || -z "$@" ]] && return
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500972 if [[ -z "$os_PACKAGE" ]]; then
973 GetOSVersion
974 fi
Dean Troyercc6b4432013-04-08 15:38:03 -0500975 if [[ $TRACK_DEPENDS = True ]]; then
Monty Taylor47f02062012-07-26 11:09:24 -0500976 source $DEST/.venv/bin/activate
977 CMD_PIP=$DEST/.venv/bin/pip
978 SUDO_PIP="env"
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500979 else
Monty Taylor47f02062012-07-26 11:09:24 -0500980 SUDO_PIP="sudo"
Vincent Untz8ec27222012-11-29 09:25:31 +0100981 CMD_PIP=$(get_pip_command)
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500982 fi
Ian Wienandd67dd872013-04-11 11:14:36 +1000983
Roman Gorodeckij99405a42013-08-07 09:20:36 -0400984 # Mirror option not needed anymore because pypi has CDN available,
985 # but it's useful in certain circumstances
986 PIP_USE_MIRRORS=${PIP_USE_MIRRORS:-False}
Maru Newby3a87edd2012-10-25 23:01:06 +0000987 if [[ "$PIP_USE_MIRRORS" != "False" ]]; then
988 PIP_MIRROR_OPT="--use-mirrors"
989 fi
Ian Wienandd67dd872013-04-11 11:14:36 +1000990
Ian Wienand31dcd3e2013-07-16 13:36:34 +1000991 # pip < 1.4 has a bug where it will use an already existing build
992 # directory unconditionally. Say an earlier component installs
993 # foo v1.1; pip will have built foo's source in
994 # /tmp/$USER-pip-build. Even if a later component specifies foo <
995 # 1.1, the existing extracted build will be used and cause
996 # confusing errors. By creating unique build directories we avoid
997 # this problem. See
998 # https://github.com/pypa/pip/issues/709
999 local pip_build_tmp=$(mktemp --tmpdir -d pip-build.XXXXX)
1000
Monty Taylor47f02062012-07-26 11:09:24 -05001001 $SUDO_PIP PIP_DOWNLOAD_CACHE=${PIP_DOWNLOAD_CACHE:-/var/cache/pip} \
Dean Troyer7f9aa712012-01-31 12:11:56 -06001002 HTTP_PROXY=$http_proxy \
1003 HTTPS_PROXY=$https_proxy \
Osamu Habuka7abe4f22012-07-25 12:39:32 +09001004 NO_PROXY=$no_proxy \
Ian Wienand31dcd3e2013-07-16 13:36:34 +10001005 $CMD_PIP install --build=${pip_build_tmp} \
1006 $PIP_MIRROR_OPT $@ \
1007 && $SUDO_PIP rm -rf ${pip_build_tmp}
Dean Troyer13dc5cc2012-03-27 14:50:45 -05001008}
1009
1010
Ian Wienand31dcd3e2013-07-16 13:36:34 +10001011# Cleanup anything from /tmp on unstack
1012# clean_tmp
1013function cleanup_tmp {
1014 local tmp_dir=${TMPDIR:-/tmp}
1015
1016 # see comments in pip_install
1017 sudo rm -rf ${tmp_dir}/pip-build.*
1018}
1019
Dean Troyer13dc5cc2012-03-27 14:50:45 -05001020# Service wrapper to restart services
1021# restart_service service-name
1022function restart_service() {
Vincent Untzc18b9652012-12-04 12:36:34 +01001023 if is_ubuntu; then
Dean Troyer5218d452012-02-04 02:13:23 -06001024 sudo /usr/sbin/service $1 restart
1025 else
1026 sudo /sbin/service $1 restart
1027 fi
Dean Troyer13dc5cc2012-03-27 14:50:45 -05001028}
1029
1030
Dean Troyer681f3fd2013-02-27 19:00:39 -06001031# _run_process() is designed to be backgrounded by run_process() to simulate a
1032# fork. It includes the dirty work of closing extra filehandles and preparing log
1033# files to produce the same logs as screen_it(). The log filename is derived
1034# from the service name and global-and-now-misnamed SCREEN_LOGDIR
1035# _run_process service "command-line"
1036function _run_process() {
1037 local service=$1
1038 local command="$2"
1039
1040 # Undo logging redirections and close the extra descriptors
1041 exec 1>&3
1042 exec 2>&3
1043 exec 3>&-
1044 exec 6>&-
1045
1046 if [[ -n ${SCREEN_LOGDIR} ]]; then
1047 exec 1>&${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log 2>&1
1048 ln -sf ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log ${SCREEN_LOGDIR}/screen-${1}.log
1049
1050 # TODO(dtroyer): Hack to get stdout from the Python interpreter for the logs.
1051 export PYTHONUNBUFFERED=1
1052 fi
1053
1054 exec /bin/bash -c "$command"
1055 die "$service exec failure: $command"
1056}
1057
1058
1059# run_process() launches a child process that closes all file descriptors and
1060# then exec's the passed in command. This is meant to duplicate the semantics
1061# of screen_it() without screen. PIDs are written to
1062# $SERVICE_DIR/$SCREEN_NAME/$service.pid
1063# run_process service "command-line"
1064function run_process() {
1065 local service=$1
1066 local command="$2"
1067
1068 # Spawn the child process
1069 _run_process "$service" "$command" &
1070 echo $!
1071}
1072
1073
Dean Troyer15733352012-09-06 11:51:30 -05001074# Helper to launch a service in a named screen
1075# screen_it service "command-line"
1076function screen_it {
Dean Troyer15733352012-09-06 11:51:30 -05001077 SCREEN_NAME=${SCREEN_NAME:-stack}
jiajun xua9414242012-12-06 16:30:57 +08001078 SERVICE_DIR=${SERVICE_DIR:-${DEST}/status}
Dean Troyer681f3fd2013-02-27 19:00:39 -06001079 USE_SCREEN=$(trueorfalse True $USE_SCREEN)
jiajun xua9414242012-12-06 16:30:57 +08001080
Dean Troyer15733352012-09-06 11:51:30 -05001081 if is_service_enabled $1; then
1082 # Append the service to the screen rc file
1083 screen_rc "$1" "$2"
1084
Dean Troyer681f3fd2013-02-27 19:00:39 -06001085 if [[ "$USE_SCREEN" = "True" ]]; then
1086 screen -S $SCREEN_NAME -X screen -t $1
Jeremy Stanley25ebbcd2013-02-17 15:45:55 +00001087
Dean Troyer681f3fd2013-02-27 19:00:39 -06001088 if [[ -n ${SCREEN_LOGDIR} ]]; then
1089 screen -S $SCREEN_NAME -p $1 -X logfile ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log
1090 screen -S $SCREEN_NAME -p $1 -X log on
1091 ln -sf ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log ${SCREEN_LOGDIR}/screen-${1}.log
1092 fi
Jeremy Stanley25ebbcd2013-02-17 15:45:55 +00001093
Vishvananda Ishaya58e21342013-02-11 16:48:12 -08001094 # sleep to allow bash to be ready to be send the command - we are
1095 # creating a new window in screen and then sends characters, so if
1096 # bash isn't running by the time we send the command, nothing happens
1097 sleep 1.5
Dean Troyer15733352012-09-06 11:51:30 -05001098
Vishvananda Ishaya58e21342013-02-11 16:48:12 -08001099 NL=`echo -ne '\015'`
Clark Boylan41815cd2013-08-16 14:57:38 -07001100 screen -S $SCREEN_NAME -p $1 -X stuff "$2 || echo \"$1 failed to start\" | tee \"$SERVICE_DIR/$SCREEN_NAME/$1.failure\"$NL"
Vishvananda Ishaya58e21342013-02-11 16:48:12 -08001101 else
Dean Troyer681f3fd2013-02-27 19:00:39 -06001102 # Spawn directly without screen
1103 run_process "$1" "$2" >$SERVICE_DIR/$SCREEN_NAME/$service.pid
Dean Troyer15733352012-09-06 11:51:30 -05001104 fi
Dean Troyer15733352012-09-06 11:51:30 -05001105 fi
1106}
1107
1108
1109# Screen rc file builder
1110# screen_rc service "command-line"
1111function screen_rc {
1112 SCREEN_NAME=${SCREEN_NAME:-stack}
1113 SCREENRC=$TOP_DIR/$SCREEN_NAME-screenrc
1114 if [[ ! -e $SCREENRC ]]; then
1115 # Name the screen session
1116 echo "sessionname $SCREEN_NAME" > $SCREENRC
1117 # Set a reasonable statusbar
1118 echo "hardstatus alwayslastline '$SCREEN_HARDSTATUS'" >> $SCREENRC
Steven Dake30396572013-06-30 16:11:54 -07001119 # Some distributions override PROMPT_COMMAND for the screen terminal type - turn that off
1120 echo "setenv PROMPT_COMMAND /bin/true" >> $SCREENRC
Dean Troyer15733352012-09-06 11:51:30 -05001121 echo "screen -t shell bash" >> $SCREENRC
1122 fi
1123 # If this service doesn't already exist in the screenrc file
1124 if ! grep $1 $SCREENRC 2>&1 > /dev/null; then
1125 NL=`echo -ne '\015'`
1126 echo "screen -t $1 bash" >> $SCREENRC
1127 echo "stuff \"$2$NL\"" >> $SCREENRC
1128 fi
1129}
1130
Dean Troyer1a6d4492013-06-03 16:47:36 -05001131
jiajun xua9414242012-12-06 16:30:57 +08001132# Helper to remove the *.failure files under $SERVICE_DIR/$SCREEN_NAME
1133# This is used for service_check when all the screen_it are called finished
1134# init_service_check
1135function init_service_check() {
1136 SCREEN_NAME=${SCREEN_NAME:-stack}
1137 SERVICE_DIR=${SERVICE_DIR:-${DEST}/status}
1138
1139 if [[ ! -d "$SERVICE_DIR/$SCREEN_NAME" ]]; then
1140 mkdir -p "$SERVICE_DIR/$SCREEN_NAME"
1141 fi
1142
1143 rm -f "$SERVICE_DIR/$SCREEN_NAME"/*.failure
1144}
1145
Dean Troyer1a6d4492013-06-03 16:47:36 -05001146
jiajun xua9414242012-12-06 16:30:57 +08001147# Helper to get the status of each running service
1148# service_check
1149function service_check() {
1150 local service
1151 local failures
1152 SCREEN_NAME=${SCREEN_NAME:-stack}
1153 SERVICE_DIR=${SERVICE_DIR:-${DEST}/status}
1154
1155
1156 if [[ ! -d "$SERVICE_DIR/$SCREEN_NAME" ]]; then
1157 echo "No service status directory found"
1158 return
1159 fi
1160
1161 # Check if there is any falure flag file under $SERVICE_DIR/$SCREEN_NAME
1162 failures=`ls "$SERVICE_DIR/$SCREEN_NAME"/*.failure 2>/dev/null`
1163
1164 for service in $failures; do
1165 service=`basename $service`
Bob Ball46287d82013-07-30 09:43:17 +01001166 service=${service%.failure}
jiajun xua9414242012-12-06 16:30:57 +08001167 echo "Error: Service $service is not running"
1168 done
1169
1170 if [ -n "$failures" ]; then
1171 echo "More details about the above errors can be found with screen, with ./rejoin-stack.sh"
1172 fi
1173}
Dean Troyer15733352012-09-06 11:51:30 -05001174
Doug Hellmanne7002672013-09-05 08:10:07 -04001175# Returns true if the directory is on a filesystem mounted via NFS.
1176function is_nfs_directory() {
1177 local mount_type=`stat -f -L -c %T $1`
1178 test "$mount_type" == "nfs"
1179}
1180
1181# Only run the command if the target file (the last arg) is not on an
1182# NFS filesystem.
1183function _safe_permission_operation() {
1184 local args=( $@ )
1185 local last
1186 local sudo_cmd
1187 local dir_to_check
1188
1189 let last="${#args[*]} - 1"
1190
1191 dir_to_check=${args[$last]}
1192 if [ ! -d "$dir_to_check" ]; then
1193 dir_to_check=`dirname "$dir_to_check"`
1194 fi
1195
1196 if is_nfs_directory "$dir_to_check" ; then
1197 return 0
1198 fi
1199
1200 if [[ $TRACK_DEPENDS = True ]]; then
1201 sudo_cmd="env"
1202 else
1203 sudo_cmd="sudo"
1204 fi
1205
1206 $sudo_cmd $@
1207}
1208
1209# Only change ownership of a file or directory if it is not on an NFS
1210# filesystem.
1211function safe_chown() {
1212 _safe_permission_operation chown $@
1213}
1214
1215# Only change permissions of a file or directory if it is not on an
1216# NFS filesystem.
1217function safe_chmod() {
1218 _safe_permission_operation chmod $@
1219}
Dean Troyer1a6d4492013-06-03 16:47:36 -05001220
Monty Taylor408a4a72013-08-02 15:43:47 -04001221# ``pip install -e`` the package, which processes the dependencies
1222# using pip before running `setup.py develop`
Monty Taylorb5bbaac2013-08-06 10:35:02 -03001223# Uses globals ``STACK_USER``, ``TRACK_DEPENDS``, ``REQUIREMENTS_DIR``
Dean Troyerbbafb1b2012-06-11 16:51:39 -05001224# setup_develop directory
1225function setup_develop() {
Sean Dague6c844632013-07-31 06:50:14 -04001226 local project_dir=$1
Sean Dague6c844632013-07-31 06:50:14 -04001227
1228 echo "cd $REQUIREMENTS_DIR; $SUDO_CMD python update.py $project_dir"
1229
Dean Troyer62d1d692013-08-01 17:40:40 -05001230 # Don't update repo if local changes exist
Doug Hellmannc3431bf2013-09-06 15:30:22 -04001231 (cd $project_dir && git diff --quiet)
1232 local update_requirements=$?
1233
1234 if [ $update_requirements -eq 0 ]; then
Dean Troyer62d1d692013-08-01 17:40:40 -05001235 (cd $REQUIREMENTS_DIR; \
1236 $SUDO_CMD python update.py $project_dir)
1237 fi
Sean Dague6c844632013-07-31 06:50:14 -04001238
Monty Taylorb5bbaac2013-08-06 10:35:02 -03001239 pip_install -e $project_dir
1240 # ensure that further actions can do things like setup.py sdist
Doug Hellmanne7002672013-09-05 08:10:07 -04001241 safe_chown -R $STACK_USER $1/*.egg-info
Doug Hellmannc3431bf2013-09-06 15:30:22 -04001242
1243 # Undo requirements changes, if we made them
1244 if [ $update_requirements -eq 0 ]; then
1245 (cd $project_dir && git checkout -- requirements.txt test-requirements.txt setup.py)
1246 fi
Dean Troyerbbafb1b2012-06-11 16:51:39 -05001247}
1248
1249
Dean Troyer13dc5cc2012-03-27 14:50:45 -05001250# Service wrapper to start services
1251# start_service service-name
1252function start_service() {
Vincent Untzc18b9652012-12-04 12:36:34 +01001253 if is_ubuntu; then
Dean Troyer5218d452012-02-04 02:13:23 -06001254 sudo /usr/sbin/service $1 start
1255 else
1256 sudo /sbin/service $1 start
1257 fi
Dean Troyer13dc5cc2012-03-27 14:50:45 -05001258}
1259
1260
1261# Service wrapper to stop services
1262# stop_service service-name
1263function stop_service() {
Vincent Untzc18b9652012-12-04 12:36:34 +01001264 if is_ubuntu; then
Dean Troyer5218d452012-02-04 02:13:23 -06001265 sudo /usr/sbin/service $1 stop
1266 else
1267 sudo /sbin/service $1 stop
1268 fi
Dean Troyer7f9aa712012-01-31 12:11:56 -06001269}
1270
1271
1272# Normalize config values to True or False
Sirushti Murugesana8d41e32013-09-25 11:30:31 +05301273# Accepts as False: 0 no No NO false False FALSE
1274# Accepts as True: 1 yes Yes YES true True TRUE
Dean Troyer4a43b7b2012-08-28 17:43:40 -05001275# VAR=$(trueorfalse default-value test-value)
Dean Troyer7f9aa712012-01-31 12:11:56 -06001276function trueorfalse() {
1277 local default=$1
1278 local testval=$2
1279
1280 [[ -z "$testval" ]] && { echo "$default"; return; }
Sirushti Murugesana8d41e32013-09-25 11:30:31 +05301281 [[ "0 no No NO false False FALSE" =~ "$testval" ]] && { echo "False"; return; }
1282 [[ "1 yes Yes YES true True TRUE" =~ "$testval" ]] && { echo "True"; return; }
Dean Troyer7f9aa712012-01-31 12:11:56 -06001283 echo "$default"
1284}
Dean Troyer27e32692012-03-16 16:16:56 -05001285
Dean Troyer13dc5cc2012-03-27 14:50:45 -05001286
Dean Troyerca0e3d02012-04-13 15:58:37 -05001287# Retrieve an image from a URL and upload into Glance
1288# Uses the following variables:
Dean Troyer4a43b7b2012-08-28 17:43:40 -05001289# ``FILES`` must be set to the cache dir
1290# ``GLANCE_HOSTPORT``
Dean Troyerca0e3d02012-04-13 15:58:37 -05001291# upload_image image-url glance-token
1292function upload_image() {
1293 local image_url=$1
1294 local token=$2
1295
1296 # Create a directory for the downloaded image tarballs.
1297 mkdir -p $FILES/images
1298
1299 # Downloads the image (uec ami+aki style), then extracts it.
1300 IMAGE_FNAME=`basename "$image_url"`
1301 if [[ ! -f $FILES/$IMAGE_FNAME || "$(stat -c "%s" $FILES/$IMAGE_FNAME)" = "0" ]]; then
1302 wget -c $image_url -O $FILES/$IMAGE_FNAME
1303 if [[ $? -ne 0 ]]; then
1304 echo "Not found: $image_url"
1305 return
1306 fi
1307 fi
1308
1309 # OpenVZ-format images are provided as .tar.gz, but not decompressed prior to loading
1310 if [[ "$image_url" =~ 'openvz' ]]; then
1311 IMAGE="$FILES/${IMAGE_FNAME}"
1312 IMAGE_NAME="${IMAGE_FNAME%.tar.gz}"
1313 glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT image-create --name "$IMAGE_NAME" --is-public=True --container-format ami --disk-format ami < "${IMAGE}"
1314 return
1315 fi
1316
Sreeram Yerrapragadacbaff862013-07-24 19:49:23 -07001317 # vmdk format images
1318 if [[ "$image_url" =~ '.vmdk' ]]; then
1319 IMAGE="$FILES/${IMAGE_FNAME}"
1320 IMAGE_NAME="${IMAGE_FNAME%.vmdk}"
Ryan Hsua6273b92013-09-04 23:51:29 -07001321
1322 # Before we can upload vmdk type images to glance, we need to know it's
1323 # disk type, storage adapter, and networking adapter. These values are
1324 # passed to glance as custom properties. We take these values from the
1325 # vmdk filename, which is expected in the following format:
1326 #
1327 # <name>-<disk type>:<storage adapter>:<network adapter>
1328 #
1329 # If the filename does not follow the above format then the vsphere
1330 # driver will supply default values.
1331 property_string=`echo "$IMAGE_NAME" | grep -oP '(?<=-)(?!.*-).+:.+:.+$'`
1332 if [[ ! -z "$property_string" ]]; then
1333 IFS=':' read -a props <<< "$property_string"
1334 vmdk_disktype="${props[0]}"
1335 vmdk_adapter_type="${props[1]}"
1336 vmdk_net_adapter="${props[2]}"
1337 fi
1338
Ryan Hsu49f44862013-10-03 22:27:03 -07001339 glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT image-create --name "$IMAGE_NAME" --is-public=True --container-format bare --disk-format vmdk --property vmware_disktype="$vmdk_disktype" --property vmware_adaptertype="$vmdk_adapter_type" --property hw_vif_model="$vmdk_net_adapter" < "${IMAGE}"
Sreeram Yerrapragadacbaff862013-07-24 19:49:23 -07001340 return
1341 fi
1342
Mate Lakatbc2ef922013-08-15 18:06:59 +01001343 # XenServer-vhd-ovf-format images are provided as .vhd.tgz
Davanum Srinivas316ed6c2013-02-06 15:29:49 -05001344 # and should not be decompressed prior to loading
1345 if [[ "$image_url" =~ '.vhd.tgz' ]]; then
1346 IMAGE="$FILES/${IMAGE_FNAME}"
1347 IMAGE_NAME="${IMAGE_FNAME%.vhd.tgz}"
1348 glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT image-create --name "$IMAGE_NAME" --is-public=True --container-format=ovf --disk-format=vhd < "${IMAGE}"
1349 return
1350 fi
1351
Mate Lakatbc2ef922013-08-15 18:06:59 +01001352 # .xen-raw.tgz suggests a Xen capable raw image inside a tgz.
1353 # and should not be decompressed prior to loading.
1354 # Setting metadata, so PV mode is used.
1355 if [[ "$image_url" =~ '.xen-raw.tgz' ]]; then
1356 IMAGE="$FILES/${IMAGE_FNAME}"
1357 IMAGE_NAME="${IMAGE_FNAME%.xen-raw.tgz}"
1358 glance \
1359 --os-auth-token $token \
1360 --os-image-url http://$GLANCE_HOSTPORT \
1361 image-create \
1362 --name "$IMAGE_NAME" --is-public=True \
1363 --container-format=tgz --disk-format=raw \
1364 --property vm_mode=xen < "${IMAGE}"
1365 return
1366 fi
1367
Dean Troyerca0e3d02012-04-13 15:58:37 -05001368 KERNEL=""
1369 RAMDISK=""
1370 DISK_FORMAT=""
1371 CONTAINER_FORMAT=""
1372 UNPACK=""
1373 case "$IMAGE_FNAME" in
1374 *.tar.gz|*.tgz)
1375 # Extract ami and aki files
1376 [ "${IMAGE_FNAME%.tar.gz}" != "$IMAGE_FNAME" ] &&
1377 IMAGE_NAME="${IMAGE_FNAME%.tar.gz}" ||
1378 IMAGE_NAME="${IMAGE_FNAME%.tgz}"
1379 xdir="$FILES/images/$IMAGE_NAME"
1380 rm -Rf "$xdir";
1381 mkdir "$xdir"
1382 tar -zxf $FILES/$IMAGE_FNAME -C "$xdir"
1383 KERNEL=$(for f in "$xdir/"*-vmlinuz* "$xdir/"aki-*/image; do
1384 [ -f "$f" ] && echo "$f" && break; done; true)
1385 RAMDISK=$(for f in "$xdir/"*-initrd* "$xdir/"ari-*/image; do
1386 [ -f "$f" ] && echo "$f" && break; done; true)
1387 IMAGE=$(for f in "$xdir/"*.img "$xdir/"ami-*/image; do
1388 [ -f "$f" ] && echo "$f" && break; done; true)
1389 if [[ -z "$IMAGE_NAME" ]]; then
1390 IMAGE_NAME=$(basename "$IMAGE" ".img")
1391 fi
1392 ;;
1393 *.img)
1394 IMAGE="$FILES/$IMAGE_FNAME";
1395 IMAGE_NAME=$(basename "$IMAGE" ".img")
Dean Troyer636a3ff2012-09-14 11:36:07 -05001396 format=$(qemu-img info ${IMAGE} | awk '/^file format/ { print $3; exit }')
1397 if [[ ",qcow2,raw,vdi,vmdk,vpc," =~ ",$format," ]]; then
1398 DISK_FORMAT=$format
1399 else
1400 DISK_FORMAT=raw
1401 fi
Dean Troyerca0e3d02012-04-13 15:58:37 -05001402 CONTAINER_FORMAT=bare
1403 ;;
1404 *.img.gz)
1405 IMAGE="$FILES/${IMAGE_FNAME}"
1406 IMAGE_NAME=$(basename "$IMAGE" ".img.gz")
1407 DISK_FORMAT=raw
1408 CONTAINER_FORMAT=bare
1409 UNPACK=zcat
1410 ;;
1411 *.qcow2)
1412 IMAGE="$FILES/${IMAGE_FNAME}"
1413 IMAGE_NAME=$(basename "$IMAGE" ".qcow2")
1414 DISK_FORMAT=qcow2
1415 CONTAINER_FORMAT=bare
1416 ;;
Jonathan Michalon06802042013-03-21 14:29:58 +01001417 *.iso)
1418 IMAGE="$FILES/${IMAGE_FNAME}"
1419 IMAGE_NAME=$(basename "$IMAGE" ".iso")
1420 DISK_FORMAT=iso
1421 CONTAINER_FORMAT=bare
1422 ;;
Dean Troyerca0e3d02012-04-13 15:58:37 -05001423 *) echo "Do not know what to do with $IMAGE_FNAME"; false;;
1424 esac
1425
1426 if [ "$CONTAINER_FORMAT" = "bare" ]; then
1427 if [ "$UNPACK" = "zcat" ]; then
Christian Berendta7a219a2013-07-30 18:22:32 +02001428 glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT image-create --name "$IMAGE_NAME" --is-public True --container-format=$CONTAINER_FORMAT --disk-format $DISK_FORMAT < <(zcat --force "${IMAGE}")
Dean Troyerca0e3d02012-04-13 15:58:37 -05001429 else
Christian Berendta7a219a2013-07-30 18:22:32 +02001430 glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT image-create --name "$IMAGE_NAME" --is-public True --container-format=$CONTAINER_FORMAT --disk-format $DISK_FORMAT < "${IMAGE}"
Dean Troyerca0e3d02012-04-13 15:58:37 -05001431 fi
1432 else
1433 # Use glance client to add the kernel the root filesystem.
1434 # We parse the results of the first upload to get the glance ID of the
1435 # kernel for use when uploading the root filesystem.
1436 KERNEL_ID=""; RAMDISK_ID="";
1437 if [ -n "$KERNEL" ]; then
Christian Berendta7a219a2013-07-30 18:22:32 +02001438 KERNEL_ID=$(glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT image-create --name "$IMAGE_NAME-kernel" --is-public True --container-format aki --disk-format aki < "$KERNEL" | grep ' id ' | get_field 2)
Dean Troyerca0e3d02012-04-13 15:58:37 -05001439 fi
1440 if [ -n "$RAMDISK" ]; then
Christian Berendta7a219a2013-07-30 18:22:32 +02001441 RAMDISK_ID=$(glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT image-create --name "$IMAGE_NAME-ramdisk" --is-public True --container-format ari --disk-format ari < "$RAMDISK" | grep ' id ' | get_field 2)
Dean Troyerca0e3d02012-04-13 15:58:37 -05001442 fi
Christian Berendta7a219a2013-07-30 18:22:32 +02001443 glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT image-create --name "${IMAGE_NAME%.img}" --is-public True --container-format ami --disk-format ami ${KERNEL_ID:+--property kernel_id=$KERNEL_ID} ${RAMDISK_ID:+--property ramdisk_id=$RAMDISK_ID} < "${IMAGE}"
Dean Troyerca0e3d02012-04-13 15:58:37 -05001444 fi
1445}
1446
Dean Troyer1a6d4492013-06-03 16:47:36 -05001447
Dean Troyerc1b486a2012-11-05 14:26:09 -06001448# Set the database backend to use
1449# When called from stackrc/localrc DATABASE_BACKENDS has not been
1450# initialized yet, just save the configuration selection and call back later
1451# to validate it.
1452# $1 The name of the database backend to use (mysql, postgresql, ...)
1453function use_database {
1454 if [[ -z "$DATABASE_BACKENDS" ]]; then
Dean Troyerafc29fe2013-02-07 15:56:24 -06001455 # No backends registered means this is likely called from ``localrc``
1456 # This is now deprecated usage
Dean Troyerc1b486a2012-11-05 14:26:09 -06001457 DATABASE_TYPE=$1
Bob Ball3aa88872013-02-28 17:39:41 +00001458 DEPRECATED_TEXT="$DEPRECATED_TEXT\nThe database backend needs to be properly set in ENABLED_SERVICES; use_database is deprecated localrc\n"
Attila Fazekas251d3b52012-12-16 15:05:44 +01001459 else
Dean Troyerafc29fe2013-02-07 15:56:24 -06001460 # This should no longer get called...here for posterity
Attila Fazekas251d3b52012-12-16 15:05:44 +01001461 use_exclusive_service DATABASE_BACKENDS DATABASE_TYPE $1
Dean Troyerc1b486a2012-11-05 14:26:09 -06001462 fi
Dean Troyerc1b486a2012-11-05 14:26:09 -06001463}
1464
Dean Troyer1a6d4492013-06-03 16:47:36 -05001465
Terry Wilson428af5a2012-11-01 16:12:39 -04001466# Toggle enable/disable_service for services that must run exclusive of each other
1467# $1 The name of a variable containing a space-separated list of services
1468# $2 The name of a variable in which to store the enabled service's name
1469# $3 The name of the service to enable
1470function use_exclusive_service {
1471 local options=${!1}
1472 local selection=$3
1473 out=$2
1474 [ -z $selection ] || [[ ! "$options" =~ "$selection" ]] && return 1
1475 for opt in $options;do
1476 [[ "$opt" = "$selection" ]] && enable_service $opt || disable_service $opt
1477 done
1478 eval "$out=$selection"
1479 return 0
1480}
Dean Troyerca0e3d02012-04-13 15:58:37 -05001481
Dean Troyer1a6d4492013-06-03 16:47:36 -05001482
Dean Troyer3a3a2ba2012-12-11 15:26:24 -06001483# Wait for an HTTP server to start answering requests
1484# wait_for_service timeout url
1485function wait_for_service() {
1486 local timeout=$1
1487 local url=$2
JUN JIE NAN0aa85342013-09-13 15:47:09 +08001488 timeout $timeout sh -c "while ! curl --noproxy '*' -s $url >/dev/null; do sleep 1; done"
Dean Troyer3a3a2ba2012-12-11 15:26:24 -06001489}
1490
Dean Troyer1a6d4492013-06-03 16:47:36 -05001491
Dean Troyer4a43b7b2012-08-28 17:43:40 -05001492# Wrapper for ``yum`` to set proxy environment variables
1493# Uses globals ``OFFLINE``, ``*_proxy`
Dean Troyer13dc5cc2012-03-27 14:50:45 -05001494# yum_install package [package ...]
1495function yum_install() {
1496 [[ "$OFFLINE" = "True" ]] && return
1497 local sudo="sudo"
1498 [[ "$(id -u)" = "0" ]] && sudo="env"
1499 $sudo http_proxy=$http_proxy https_proxy=$https_proxy \
Osamu Habuka7abe4f22012-07-25 12:39:32 +09001500 no_proxy=$no_proxy \
Dean Troyer13dc5cc2012-03-27 14:50:45 -05001501 yum install -y "$@"
1502}
1503
Dean Troyer1a6d4492013-06-03 16:47:36 -05001504
1505# zypper wrapper to set arguments correctly
1506# zypper_install package [package ...]
1507function zypper_install() {
1508 [[ "$OFFLINE" = "True" ]] && return
1509 local sudo="sudo"
1510 [[ "$(id -u)" = "0" ]] && sudo="env"
1511 $sudo http_proxy=$http_proxy https_proxy=$https_proxy \
1512 zypper --non-interactive install --auto-agree-with-licenses "$@"
1513}
1514
1515
Nachi Uenofda946e2012-10-24 17:26:02 -07001516# ping check
1517# Uses globals ``ENABLED_SERVICES``
Dean Troyer1a6d4492013-06-03 16:47:36 -05001518# ping_check from-net ip boot-timeout expected
Nachi Uenofda946e2012-10-24 17:26:02 -07001519function ping_check() {
Mark McClainb05c8762013-07-06 23:29:39 -04001520 if is_service_enabled neutron; then
1521 _ping_check_neutron "$1" $2 $3 $4
Nachi Ueno5db5bfa2012-10-29 11:25:29 -07001522 return
1523 fi
1524 _ping_check_novanet "$1" $2 $3 $4
Nachi Uenofda946e2012-10-24 17:26:02 -07001525}
1526
1527# ping check for nova
1528# Uses globals ``MULTI_HOST``, ``PRIVATE_NETWORK``
1529function _ping_check_novanet() {
1530 local from_net=$1
1531 local ip=$2
1532 local boot_timeout=$3
Nachi Ueno5db5bfa2012-10-29 11:25:29 -07001533 local expected=${4:-"True"}
1534 local check_command=""
Nachi Uenofda946e2012-10-24 17:26:02 -07001535 MULTI_HOST=`trueorfalse False $MULTI_HOST`
1536 if [[ "$MULTI_HOST" = "True" && "$from_net" = "$PRIVATE_NETWORK_NAME" ]]; then
Nachi Uenofda946e2012-10-24 17:26:02 -07001537 return
1538 fi
Nachi Ueno5db5bfa2012-10-29 11:25:29 -07001539 if [[ "$expected" = "True" ]]; then
1540 check_command="while ! ping -c1 -w1 $ip; do sleep 1; done"
1541 else
1542 check_command="while ping -c1 -w1 $ip; do sleep 1; done"
1543 fi
1544 if ! timeout $boot_timeout sh -c "$check_command"; then
1545 if [[ "$expected" = "True" ]]; then
Nachi Ueno07115eb2013-02-26 12:38:18 -08001546 die $LINENO "[Fail] Couldn't ping server"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -07001547 else
Nachi Ueno07115eb2013-02-26 12:38:18 -08001548 die $LINENO "[Fail] Could ping server"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -07001549 fi
Nachi Uenofda946e2012-10-24 17:26:02 -07001550 exit 1
1551 fi
1552}
1553
Nachi Ueno6769b162013-08-12 18:18:56 -07001554# Get ip of instance
1555function get_instance_ip(){
1556 local vm_id=$1
1557 local network_name=$2
1558 local nova_result="$(nova show $vm_id)"
1559 local ip=$(echo "$nova_result" | grep "$network_name" | get_field 2)
1560 if [[ $ip = "" ]];then
1561 echo "$nova_result"
1562 die $LINENO "[Fail] Coudn't get ipaddress of VM"
1563 exit 1
1564 fi
1565 echo $ip
1566}
Dean Troyer1a6d4492013-06-03 16:47:36 -05001567
Nachi Uenofda946e2012-10-24 17:26:02 -07001568# ssh check
Nachi Ueno5db5bfa2012-10-29 11:25:29 -07001569
Dean Troyer1a6d4492013-06-03 16:47:36 -05001570# ssh_check net-name key-file floating-ip default-user active-timeout
Nachi Uenofda946e2012-10-24 17:26:02 -07001571function ssh_check() {
Mark McClainb05c8762013-07-06 23:29:39 -04001572 if is_service_enabled neutron; then
1573 _ssh_check_neutron "$1" $2 $3 $4 $5
Nachi Ueno5db5bfa2012-10-29 11:25:29 -07001574 return
1575 fi
1576 _ssh_check_novanet "$1" $2 $3 $4 $5
1577}
1578
1579function _ssh_check_novanet() {
Nachi Uenofda946e2012-10-24 17:26:02 -07001580 local NET_NAME=$1
1581 local KEY_FILE=$2
1582 local FLOATING_IP=$3
1583 local DEFAULT_INSTANCE_USER=$4
1584 local ACTIVE_TIMEOUT=$5
Dean Troyer6931c132012-11-07 16:51:21 -06001585 local probe_cmd=""
Dean Troyercc6b4432013-04-08 15:38:03 -05001586 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! ssh -o StrictHostKeyChecking=no -i $KEY_FILE ${DEFAULT_INSTANCE_USER}@$FLOATING_IP echo success; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -08001587 die $LINENO "server didn't become ssh-able!"
Nachi Uenofda946e2012-10-24 17:26:02 -07001588 fi
1589}
Dean Troyer13dc5cc2012-03-27 14:50:45 -05001590
Vincent Untz856a11e2012-11-21 16:04:12 +01001591
Vincent Untz856a11e2012-11-21 16:04:12 +01001592# Add a user to a group.
1593# add_user_to_group user group
1594function add_user_to_group() {
1595 local user=$1
1596 local group=$2
1597
1598 if [[ -z "$os_VENDOR" ]]; then
1599 GetOSVersion
1600 fi
1601
1602 # SLE11 and openSUSE 12.2 don't have the usual usermod
1603 if ! is_suse || [[ "$os_VENDOR" = "openSUSE" && "$os_RELEASE" != "12.2" ]]; then
1604 sudo usermod -a -G "$group" "$user"
1605 else
1606 sudo usermod -A "$group" "$user"
1607 fi
1608}
1609
1610
Jakub Ruzicka4196d552013-01-30 15:35:54 +01001611# Get the path to the direcotry where python executables are installed.
1612# get_python_exec_prefix
1613function get_python_exec_prefix() {
Martin Vidner4f9b33d2013-06-27 13:11:22 +00001614 if is_fedora || is_suse; then
Jakub Ruzicka4196d552013-01-30 15:35:54 +01001615 echo "/usr/bin"
1616 else
1617 echo "/usr/local/bin"
1618 fi
1619}
1620
Dean Troyer1a6d4492013-06-03 16:47:36 -05001621
Vincent Untz856a11e2012-11-21 16:04:12 +01001622# Get the location of the $module-rootwrap executables, where module is cinder
1623# or nova.
1624# get_rootwrap_location module
1625function get_rootwrap_location() {
1626 local module=$1
1627
Jakub Ruzicka4196d552013-01-30 15:35:54 +01001628 echo "$(get_python_exec_prefix)/$module-rootwrap"
Vincent Untz856a11e2012-11-21 16:04:12 +01001629}
1630
Dean Troyer1a6d4492013-06-03 16:47:36 -05001631
Vincent Untz8ec27222012-11-29 09:25:31 +01001632# Get the path to the pip command.
1633# get_pip_command
1634function get_pip_command() {
Dean Troyerd2cfcaa2013-08-01 14:17:27 -05001635 which pip || which pip-python
Ian Wienand535a8142013-05-15 09:25:27 +10001636
1637 if [ $? -ne 0 ]; then
1638 die $LINENO "Unable to find pip; cannot continue"
1639 fi
Vincent Untz8ec27222012-11-29 09:25:31 +01001640}
Vincent Untz856a11e2012-11-21 16:04:12 +01001641
Dean Troyer1a6d4492013-06-03 16:47:36 -05001642
Ian Wienand0488edd2013-04-11 12:04:36 +10001643# Path permissions sanity check
1644# check_path_perm_sanity path
1645function check_path_perm_sanity() {
1646 # Ensure no element of the path has 0700 permissions, which is very
1647 # likely to cause issues for daemons. Inspired by default 0700
1648 # homedir permissions on RHEL and common practice of making DEST in
1649 # the stack user's homedir.
1650
1651 local real_path=$(readlink -f $1)
1652 local rebuilt_path=""
1653 for i in $(echo ${real_path} | tr "/" " "); do
1654 rebuilt_path=$rebuilt_path"/"$i
1655
1656 if [[ $(stat -c '%a' ${rebuilt_path}) = 700 ]]; then
1657 echo "*** DEST path element"
1658 echo "*** ${rebuilt_path}"
1659 echo "*** appears to have 0700 permissions."
1660 echo "*** This is very likely to cause fatal issues for devstack daemons."
1661
1662 if [[ -n "$SKIP_PATH_SANITY" ]]; then
1663 return
1664 else
1665 echo "*** Set SKIP_PATH_SANITY to skip this check"
1666 die $LINENO "Invalid path permissions"
1667 fi
1668 fi
1669 done
1670}
1671
Dean Troyer1a6d4492013-06-03 16:47:36 -05001672
Kyle Mestery51a3f1f2013-06-13 11:47:56 +00001673# This function recursively compares versions, and is not meant to be
1674# called by anything other than vercmp_numbers below. This function does
1675# not work with alphabetic versions.
1676#
1677# _vercmp_r sep ver1 ver2
1678function _vercmp_r {
1679 typeset sep
1680 typeset -a ver1=() ver2=()
1681 sep=$1; shift
1682 ver1=("${@:1:sep}")
1683 ver2=("${@:sep+1}")
1684
1685 if ((ver1 > ver2)); then
1686 echo 1; return 0
1687 elif ((ver2 > ver1)); then
1688 echo -1; return 0
1689 fi
1690
1691 if ((sep <= 1)); then
1692 echo 0; return 0
1693 fi
1694
1695 _vercmp_r $((sep-1)) "${ver1[@]:1}" "${ver2[@]:1}"
1696}
1697
1698
1699# This function compares two versions and is meant to be called by
1700# external callers. Please note the function assumes non-alphabetic
1701# versions. For example, this will work:
1702#
1703# vercmp_numbers 1.10 1.4
1704#
1705# The above will return "1", as 1.10 is greater than 1.4.
1706#
1707# vercmp_numbers 5.2 6.4
1708#
1709# The above will return "-1", as 5.2 is less than 6.4.
1710#
1711# vercmp_numbers 4.0 4.0
1712#
1713# The above will return "0", as the versions are equal.
1714#
1715# vercmp_numbers ver1 ver2
1716vercmp_numbers() {
1717 typeset v1=$1 v2=$2 sep
1718 typeset -a ver1 ver2
1719
1720 IFS=. read -ra ver1 <<< "$v1"
1721 IFS=. read -ra ver2 <<< "$v2"
1722
1723 _vercmp_r "${#ver1[@]}" "${ver1[@]}" "${ver2[@]}"
1724}
1725
1726
Dean Troyer533e14d2013-08-30 15:11:22 -05001727# ``policy_add policy_file policy_name policy_permissions``
1728#
1729# Add a policy to a policy.json file
1730# Do nothing if the policy already exists
1731
1732function policy_add() {
1733 local policy_file=$1
1734 local policy_name=$2
1735 local policy_perm=$3
1736
1737 if grep -q ${policy_name} ${policy_file}; then
1738 echo "Policy ${policy_name} already exists in ${policy_file}"
1739 return
1740 fi
1741
1742 # Add a terminating comma to policy lines without one
1743 # Remove the closing '}' and all lines following to the end-of-file
1744 local tmpfile=$(mktemp)
1745 uniq ${policy_file} | sed -e '
1746 s/]$/],/
1747 /^[}]/,$d
1748 ' > ${tmpfile}
1749
1750 # Append policy and closing brace
1751 echo " \"${policy_name}\": ${policy_perm}" >>${tmpfile}
1752 echo "}" >>${tmpfile}
1753
1754 mv ${tmpfile} ${policy_file}
1755}
1756
1757
Salvatore Orlando05ae8332013-08-20 14:51:08 -07001758# This function sets log formatting options for colorizing log
1759# output to stdout. It is meant to be called by lib modules.
1760# The last two parameters are optional and can be used to specify
1761# non-default value for project and user format variables.
1762# Defaults are respectively 'project_name' and 'user_name'
1763#
1764# setup_colorized_logging something.conf SOMESECTION
1765function setup_colorized_logging() {
1766 local conf_file=$1
1767 local conf_section=$2
1768 local project_var=${3:-"project_name"}
1769 local user_var=${4:-"user_name"}
1770 # Add color to logging output
1771 iniset $conf_file $conf_section logging_context_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [%(request_id)s %("$user_var")s %("$project_var")s%(color)s] %(instance)s%(color)s%(message)s"
1772 iniset $conf_file $conf_section logging_default_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s"
1773 iniset $conf_file $conf_section logging_debug_format_suffix "from (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d"
1774 iniset $conf_file $conf_section logging_exception_prefix "%(color)s%(asctime)s.%(msecs)03d TRACE %(name)s %(instance)s"
1775}
1776
Dean Troyer27e32692012-03-16 16:16:56 -05001777# Restore xtrace
Chmouel Boudjnah408b0092012-03-15 23:21:55 +00001778$XTRACE
Dean Troyer4a43b7b2012-08-28 17:43:40 -05001779
1780
1781# Local variables:
Sean Dague584d90e2013-03-29 14:34:53 -04001782# mode: shell-script
Andrew Laskif900bd72012-09-05 17:23:14 -04001783# End: