blob: cd0623316ab58b2665a02996d245e40a2e006fbb [file] [log] [blame]
Doug Hellmannf04178f2012-07-05 17:10:03 -04001# -*- mode: Shell-script -*-
Dean Troyer7f9aa712012-01-31 12:11:56 -06002# functions - Common functions used by DevStack components
Dean Troyer13dc5cc2012-03-27 14:50:45 -05003#
4# ENABLED_SERVICES is used by is_service_enabled()
5
Dean Troyer7f9aa712012-01-31 12:11:56 -06006
Dean Troyer27e32692012-03-16 16:16:56 -05007# Save trace setting
8XTRACE=$(set +o | grep xtrace)
9set +o xtrace
10
Dean Troyer7f9aa712012-01-31 12:11:56 -060011
Vishvananda Ishayac9ad14b2012-07-03 20:29:01 +000012# Exit 0 if address is in network or 1 if
13# address is not in network or netaddr library
14# is not installed.
15function address_in_net() {
16 python -c "
17import netaddr
18import sys
19sys.exit(netaddr.IPAddress('$1') not in netaddr.IPNetwork('$2'))
20"
21}
22
23
Dean Troyer7f9aa712012-01-31 12:11:56 -060024# apt-get wrapper to set arguments correctly
Dean Troyer13dc5cc2012-03-27 14:50:45 -050025# apt_get operation package [package ...]
Dean Troyer7f9aa712012-01-31 12:11:56 -060026function apt_get() {
Dean Troyerd0b21e22012-03-07 14:52:25 -060027 [[ "$OFFLINE" = "True" || -z "$@" ]] && return
Dean Troyer7f9aa712012-01-31 12:11:56 -060028 local sudo="sudo"
29 [[ "$(id -u)" = "0" ]] && sudo="env"
30 $sudo DEBIAN_FRONTEND=noninteractive \
31 http_proxy=$http_proxy https_proxy=$https_proxy \
Osamu Habuka7abe4f22012-07-25 12:39:32 +090032 no_proxy=$no_proxy \
Dean Troyer7f9aa712012-01-31 12:11:56 -060033 apt-get --option "Dpkg::Options::=--force-confold" --assume-yes "$@"
34}
35
36
37# Gracefully cp only if source file/dir exists
38# cp_it source destination
39function cp_it {
40 if [ -e $1 ] || [ -d $1 ]; then
41 cp -pRL $1 $2
42 fi
43}
44
45
Dean Troyer27e32692012-03-16 16:16:56 -050046# Prints "message" and exits
47# die "message"
48function die() {
Dean Troyer489bd2a2012-03-02 10:44:29 -060049 local exitcode=$?
Dean Troyer27e32692012-03-16 16:16:56 -050050 set +o xtrace
51 echo $@
52 exit $exitcode
Dean Troyer489bd2a2012-03-02 10:44:29 -060053}
54
55
56# Checks an environment variable is not set or has length 0 OR if the
57# exit code is non-zero and prints "message" and exits
58# NOTE: env-var is the variable name without a '$'
59# die_if_not_set env-var "message"
60function die_if_not_set() {
Dean Troyer27e32692012-03-16 16:16:56 -050061 (
62 local exitcode=$?
63 set +o xtrace
64 local evar=$1; shift
65 if ! is_set $evar || [ $exitcode != 0 ]; then
66 set +o xtrace
67 echo $@
68 exit -1
69 fi
70 )
Dean Troyer489bd2a2012-03-02 10:44:29 -060071}
72
73
74# Grab a numbered field from python prettytable output
75# Fields are numbered starting with 1
76# Reverse syntax is supported: -1 is the last field, -2 is second to last, etc.
77# get_field field-number
78function get_field() {
79 while read data; do
80 if [ "$1" -lt 0 ]; then
81 field="(\$(NF$1))"
82 else
83 field="\$$(($1 + 1))"
84 fi
85 echo "$data" | awk -F'[ \t]*\\|[ \t]*' "{print $field}"
86 done
87}
88
89
Dean Troyer7e270512012-06-14 15:23:24 -050090# get_packages() collects a list of package names of any type from the
91# prerequisite files in ``files/{apts|pips}``. The list is intended
92# to be passed to a package installer such as apt or pip.
93#
94# Only packages required for the services in ENABLED_SERVICES will be
95# included. Two bits of metadata are recognized in the prerequisite files:
96# - ``# NOPRIME`` defers installation to be performed later in stack.sh
97# - ``# dist:DISTRO`` or ``dist:DISTRO1,DISTRO2`` limits the selection
98# of the package to the distros listed. The distro names are case insensitive.
99#
100# get_packages dir
101function get_packages() {
102 local package_dir=$1
103 local file_to_parse
104 local service
105
106 if [[ -z "$package_dir" ]]; then
107 echo "No package directory supplied"
108 return 1
109 fi
110 if [[ -z "$DISTRO" ]]; then
111 echo "No distro set in DISTRO"
112 return 1
113 fi
114 for service in general ${ENABLED_SERVICES//,/ }; do
115 # Allow individual services to specify dependencies
116 if [[ -e ${package_dir}/${service} ]]; then
117 file_to_parse="${file_to_parse} $service"
118 fi
119 # NOTE(sdague) n-api needs glance for now because that's where
120 # glance client is
121 if [[ $service == n-api ]]; then
122 if [[ ! $file_to_parse =~ nova ]]; then
123 file_to_parse="${file_to_parse} nova"
124 fi
125 if [[ ! $file_to_parse =~ glance ]]; then
126 file_to_parse="${file_to_parse} glance"
127 fi
128 elif [[ $service == c-* ]]; then
129 if [[ ! $file_to_parse =~ cinder ]]; then
130 file_to_parse="${file_to_parse} cinder"
131 fi
John H. Tran93361642012-07-26 11:22:05 -0700132 elif [[ $service == ceilometer-* ]]; then
133 if [[ ! $file_to_parse =~ ceilometer ]]; then
134 file_to_parse="${file_to_parse} ceilometer"
135 fi
Dean Troyer7e270512012-06-14 15:23:24 -0500136 elif [[ $service == n-* ]]; then
137 if [[ ! $file_to_parse =~ nova ]]; then
138 file_to_parse="${file_to_parse} nova"
139 fi
140 elif [[ $service == g-* ]]; then
141 if [[ ! $file_to_parse =~ glance ]]; then
142 file_to_parse="${file_to_parse} glance"
143 fi
144 elif [[ $service == key* ]]; then
145 if [[ ! $file_to_parse =~ keystone ]]; then
146 file_to_parse="${file_to_parse} keystone"
147 fi
148 fi
149 done
150
151 for file in ${file_to_parse}; do
152 local fname=${package_dir}/${file}
153 local OIFS line package distros distro
154 [[ -e $fname ]] || continue
155
156 OIFS=$IFS
157 IFS=$'\n'
158 for line in $(<${fname}); do
159 if [[ $line =~ "NOPRIME" ]]; then
160 continue
161 fi
162
163 if [[ $line =~ (.*)#.*dist:([^ ]*) ]]; then
164 # We are using BASH regexp matching feature.
165 package=${BASH_REMATCH[1]}
166 distros=${BASH_REMATCH[2]}
167 # In bash ${VAR,,} will lowecase VAR
168 [[ ${distros,,} =~ ${DISTRO,,} ]] && echo $package
169 continue
170 fi
171
172 echo ${line%#*}
173 done
174 IFS=$OIFS
175 done
176}
177
178
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500179# Determine OS Vendor, Release and Update
180# Tested with OS/X, Ubuntu, RedHat, CentOS, Fedora
181# Returns results in global variables:
182# os_VENDOR - vendor name
183# os_RELEASE - release
184# os_UPDATE - update
185# os_PACKAGE - package type
186# os_CODENAME - vendor's codename for release
187# GetOSVersion
188GetOSVersion() {
189 # Figure out which vendor we are
190 if [[ -n "`which sw_vers 2>/dev/null`" ]]; then
191 # OS/X
192 os_VENDOR=`sw_vers -productName`
193 os_RELEASE=`sw_vers -productVersion`
194 os_UPDATE=${os_RELEASE##*.}
195 os_RELEASE=${os_RELEASE%.*}
196 os_PACKAGE=""
197 if [[ "$os_RELEASE" =~ "10.7" ]]; then
198 os_CODENAME="lion"
199 elif [[ "$os_RELEASE" =~ "10.6" ]]; then
200 os_CODENAME="snow leopard"
201 elif [[ "$os_RELEASE" =~ "10.5" ]]; then
202 os_CODENAME="leopard"
203 elif [[ "$os_RELEASE" =~ "10.4" ]]; then
204 os_CODENAME="tiger"
205 elif [[ "$os_RELEASE" =~ "10.3" ]]; then
206 os_CODENAME="panther"
207 else
208 os_CODENAME=""
209 fi
210 elif [[ -x $(which lsb_release 2>/dev/null) ]]; then
211 os_VENDOR=$(lsb_release -i -s)
212 os_RELEASE=$(lsb_release -r -s)
213 os_UPDATE=""
214 if [[ "Debian,Ubuntu" =~ $os_VENDOR ]]; then
215 os_PACKAGE="deb"
216 else
217 os_PACKAGE="rpm"
218 fi
219 os_CODENAME=$(lsb_release -c -s)
220 elif [[ -r /etc/redhat-release ]]; then
221 # Red Hat Enterprise Linux Server release 5.5 (Tikanga)
222 # CentOS release 5.5 (Final)
223 # CentOS Linux release 6.0 (Final)
224 # Fedora release 16 (Verne)
225 os_CODENAME=""
226 for r in "Red Hat" CentOS Fedora; do
227 os_VENDOR=$r
228 if [[ -n "`grep \"$r\" /etc/redhat-release`" ]]; then
229 ver=`sed -e 's/^.* \(.*\) (\(.*\)).*$/\1\|\2/' /etc/redhat-release`
230 os_CODENAME=${ver#*|}
231 os_RELEASE=${ver%|*}
232 os_UPDATE=${os_RELEASE##*.}
233 os_RELEASE=${os_RELEASE%.*}
234 break
235 fi
236 os_VENDOR=""
237 done
238 os_PACKAGE="rpm"
239 fi
240 export os_VENDOR os_RELEASE os_UPDATE os_PACKAGE os_CODENAME
241}
242
243
Dean Troyera9e0a482012-07-09 14:07:23 -0500244# Translate the OS version values into common nomenclature
245# Sets ``DISTRO`` from the ``os_*`` values
246function GetDistro() {
247 GetOSVersion
248 if [[ "$os_VENDOR" =~ (Ubuntu) ]]; then
249 # 'Everyone' refers to Ubuntu releases by the code name adjective
250 DISTRO=$os_CODENAME
251 elif [[ "$os_VENDOR" =~ (Fedora) ]]; then
252 # For Fedora, just use 'f' and the release
253 DISTRO="f$os_RELEASE"
254 else
255 # Catch-all for now is Vendor + Release + Update
256 DISTRO="$os_VENDOR-$os_RELEASE.$os_UPDATE"
257 fi
258 export DISTRO
259}
260
261
Dean Troyer7f9aa712012-01-31 12:11:56 -0600262# git clone only if directory doesn't exist already. Since ``DEST`` might not
263# be owned by the installation user, we create the directory and change the
264# ownership to the proper user.
265# Set global RECLONE=yes to simulate a clone when dest-dir exists
James E. Blair94cb9602012-06-22 15:28:29 -0700266# Set global ERROR_ON_CLONE=True to abort execution with an error if the git repo
267# does not exist (default is False, meaning the repo will be cloned).
Dean Troyer7f9aa712012-01-31 12:11:56 -0600268# git_clone remote dest-dir branch
269function git_clone {
270 [[ "$OFFLINE" = "True" ]] && return
271
272 GIT_REMOTE=$1
273 GIT_DEST=$2
274 GIT_BRANCH=$3
275
276 if echo $GIT_BRANCH | egrep -q "^refs"; then
277 # If our branch name is a gerrit style refs/changes/...
278 if [[ ! -d $GIT_DEST ]]; then
James E. Blair94cb9602012-06-22 15:28:29 -0700279 [[ "$ERROR_ON_CLONE" = "True" ]] && exit 1
Dean Troyer7f9aa712012-01-31 12:11:56 -0600280 git clone $GIT_REMOTE $GIT_DEST
281 fi
282 cd $GIT_DEST
283 git fetch $GIT_REMOTE $GIT_BRANCH && git checkout FETCH_HEAD
284 else
285 # do a full clone only if the directory doesn't exist
286 if [[ ! -d $GIT_DEST ]]; then
James E. Blair94cb9602012-06-22 15:28:29 -0700287 [[ "$ERROR_ON_CLONE" = "True" ]] && exit 1
Dean Troyer7f9aa712012-01-31 12:11:56 -0600288 git clone $GIT_REMOTE $GIT_DEST
289 cd $GIT_DEST
290 # This checkout syntax works for both branches and tags
291 git checkout $GIT_BRANCH
292 elif [[ "$RECLONE" == "yes" ]]; then
293 # if it does exist then simulate what clone does if asked to RECLONE
294 cd $GIT_DEST
295 # set the url to pull from and fetch
296 git remote set-url origin $GIT_REMOTE
297 git fetch origin
298 # remove the existing ignored files (like pyc) as they cause breakage
299 # (due to the py files having older timestamps than our pyc, so python
300 # thinks the pyc files are correct using them)
301 find $GIT_DEST -name '*.pyc' -delete
302 git checkout -f origin/$GIT_BRANCH
303 # a local branch might not exist
304 git branch -D $GIT_BRANCH || true
305 git checkout -b $GIT_BRANCH
306 fi
307 fi
308}
309
310
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500311# Comment an option in an INI file
Chmouel Boudjnahc7214e82012-06-06 13:56:39 +0200312# inicomment config-file section option
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500313function inicomment() {
314 local file=$1
315 local section=$2
316 local option=$3
317 sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=.*$\)|#\1|" $file
318}
319
Chmouel Boudjnahc7214e82012-06-06 13:56:39 +0200320# Uncomment an option in an INI file
321# iniuncomment config-file section option
322function iniuncomment() {
323 local file=$1
324 local section=$2
325 local option=$3
326 sed -i -e "/^\[$section\]/,/^\[.*\]/ s|[^ \t]*#[ \t]*\($option[ \t]*=.*$\)|\1|" $file
327}
328
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500329
330# Get an option from an INI file
Dean Troyer09e636e2012-03-19 16:31:12 -0500331# iniget config-file section option
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500332function iniget() {
333 local file=$1
334 local section=$2
335 local option=$3
336 local line
337 line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" $file)
338 echo ${line#*=}
339}
340
341
342# Set an option in an INI file
Dean Troyer09e636e2012-03-19 16:31:12 -0500343# iniset config-file section option value
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500344function iniset() {
345 local file=$1
346 local section=$2
347 local option=$3
348 local value=$4
Dean Troyer09e636e2012-03-19 16:31:12 -0500349 if ! grep -q "^\[$section\]" $file; then
350 # Add section at the end
351 echo -e "\n[$section]" >>$file
352 fi
353 if [[ -z "$(iniget $file $section $option)" ]]; then
354 # Add it
355 sed -i -e "/^\[$section\]/ a\\
356$option = $value
357" $file
358 else
359 # Replace it
360 sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=[ \t]*\).*$|\1$value|" $file
361 fi
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500362}
363
364
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000365# is_service_enabled() checks if the service(s) specified as arguments are
366# enabled by the user in **ENABLED_SERVICES**.
367#
368# If there are multiple services specified as arguments the test performs a
369# boolean OR or if any of the services specified on the command line
370# return true.
371#
372# There is a special cases for some 'catch-all' services::
373# **nova** returns true if any service enabled start with **n-**
374# **glance** returns true if any service enabled start with **g-**
375# **quantum** returns true if any service enabled start with **q-**
376function is_service_enabled() {
377 services=$@
378 for service in ${services}; do
379 [[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && return 0
380 [[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && return 0
Dean Troyer67787e62012-05-02 11:48:15 -0500381 [[ ${service} == "cinder" && ${ENABLED_SERVICES} =~ "c-" ]] && return 0
John H. Tran93361642012-07-26 11:22:05 -0700382 [[ ${service} == "ceilometer" && ${ENABLED_SERVICES} =~ "ceilometer-" ]] && return 0
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000383 [[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && return 0
384 [[ ${service} == "quantum" && ${ENABLED_SERVICES} =~ "q-" ]] && return 0
385 done
386 return 1
387}
388
Doug Hellmannf04178f2012-07-05 17:10:03 -0400389# remove extra commas from the input string (ENABLED_SERVICES)
390function _cleanup_service_list () {
391 echo "$1" | sed -e '
392 s/,,/,/g;
393 s/^,//;
394 s/,$//
395 '
396}
397
398# enable_service() adds the services passed as argument to the
399# **ENABLED_SERVICES** list, if they are not already present.
400#
401# For example:
402#
403# enable_service n-vol
404#
405# This function does not know about the special cases
406# for nova, glance, and quantum built into is_service_enabled().
407function enable_service() {
408 local tmpsvcs="${ENABLED_SERVICES}"
409 for service in $@; do
410 if ! is_service_enabled $service; then
411 tmpsvcs+=",$service"
412 fi
413 done
414 ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs")
415 disable_negated_services
416}
417
418# disable_service() removes the services passed as argument to the
419# **ENABLED_SERVICES** list, if they are present.
420#
421# For example:
422#
423# disable_service n-vol
424#
425# This function does not know about the special cases
426# for nova, glance, and quantum built into is_service_enabled().
427function disable_service() {
428 local tmpsvcs=",${ENABLED_SERVICES},"
429 local service
430 for service in $@; do
431 if is_service_enabled $service; then
432 tmpsvcs=${tmpsvcs//,$service,/,}
433 fi
434 done
435 ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs")
436}
437
438# disable_all_services() removes all current services
439# from **ENABLED_SERVICES** to reset the configuration
440# before a minimal installation
441function disable_all_services() {
442 ENABLED_SERVICES=""
443}
444
445# We are looking for services with a - at the beginning to force
446# excluding those services. For example if you want to install all the default
447# services but not nova-volume (n-vol) you can have this set in your localrc :
448# ENABLED_SERVICES+=",-n-vol"
449function disable_negated_services() {
450 local tmpsvcs="${ENABLED_SERVICES}"
451 local service
452 for service in ${tmpsvcs//,/ }; do
453 if [[ ${service} == -* ]]; then
454 tmpsvcs=$(echo ${tmpsvcs}|sed -r "s/(,)?(-)?${service#-}(,)?/,/g")
455 fi
456 done
457 ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs")
458}
Dean Troyer489bd2a2012-03-02 10:44:29 -0600459
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500460# Distro-agnostic package installer
461# install_package package [package ...]
462function install_package() {
463 if [[ -z "$os_PACKAGE" ]]; then
464 GetOSVersion
465 fi
466 if [[ "$os_PACKAGE" = "deb" ]]; then
467 apt_get install "$@"
468 else
469 yum_install "$@"
470 fi
471}
472
473
Dean Troyer489bd2a2012-03-02 10:44:29 -0600474# Test if the named environment variable is set and not zero length
475# is_set env-var
476function is_set() {
477 local var=\$"$1"
478 if eval "[ -z $var ]"; then
479 return 1
480 fi
481 return 0
482}
483
484
Dean Troyer7f9aa712012-01-31 12:11:56 -0600485# pip install wrapper to set cache and proxy environment variables
486# pip_install package [package ...]
487function pip_install {
Dean Troyerd0b21e22012-03-07 14:52:25 -0600488 [[ "$OFFLINE" = "True" || -z "$@" ]] && return
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500489 if [[ -z "$os_PACKAGE" ]]; then
490 GetOSVersion
491 fi
Monty Taylor47f02062012-07-26 11:09:24 -0500492 if [[ $TRACK_DEPENDS = True ]] ; then
493 source $DEST/.venv/bin/activate
494 CMD_PIP=$DEST/.venv/bin/pip
495 SUDO_PIP="env"
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500496 else
Monty Taylor47f02062012-07-26 11:09:24 -0500497 SUDO_PIP="sudo"
498 if [[ "$os_PACKAGE" = "deb" ]]; then
499 CMD_PIP=/usr/bin/pip
500 else
501 CMD_PIP=/usr/bin/pip-python
502 fi
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500503 fi
Monty Taylor47f02062012-07-26 11:09:24 -0500504 $SUDO_PIP PIP_DOWNLOAD_CACHE=${PIP_DOWNLOAD_CACHE:-/var/cache/pip} \
Dean Troyer7f9aa712012-01-31 12:11:56 -0600505 HTTP_PROXY=$http_proxy \
506 HTTPS_PROXY=$https_proxy \
Osamu Habuka7abe4f22012-07-25 12:39:32 +0900507 NO_PROXY=$no_proxy \
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500508 $CMD_PIP install --use-mirrors $@
509}
510
511
512# Service wrapper to restart services
513# restart_service service-name
514function restart_service() {
Dean Troyer5218d452012-02-04 02:13:23 -0600515 if [[ -z "$os_PACKAGE" ]]; then
516 GetOSVersion
517 fi
518 if [[ "$os_PACKAGE" = "deb" ]]; then
519 sudo /usr/sbin/service $1 restart
520 else
521 sudo /sbin/service $1 restart
522 fi
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500523}
524
525
Dean Troyerbbafb1b2012-06-11 16:51:39 -0500526# pip install the dependencies of the package before we do the setup.py
527# develop, so that pip and not distutils process the dependency chain
528# setup_develop directory
529function setup_develop() {
Monty Taylor47f02062012-07-26 11:09:24 -0500530 if [[ $TRACK_DEPENDS = True ]] ; then
531 SUDO_CMD="env"
532 else
533 SUDO_CMD="sudo"
534 fi
Dean Troyerbbafb1b2012-06-11 16:51:39 -0500535 (cd $1; \
536 python setup.py egg_info; \
537 raw_links=$(awk '/^.+/ {print "-f " $1}' *.egg-info/dependency_links.txt); \
538 depend_links=$(echo $raw_links | xargs); \
539 pip_install -r *-info/requires.txt $depend_links; \
Monty Taylor47f02062012-07-26 11:09:24 -0500540 $SUDO_CMD \
Dean Troyerbbafb1b2012-06-11 16:51:39 -0500541 HTTP_PROXY=$http_proxy \
542 HTTPS_PROXY=$https_proxy \
Osamu Habuka7abe4f22012-07-25 12:39:32 +0900543 NO_PROXY=$no_proxy \
Dean Troyerbbafb1b2012-06-11 16:51:39 -0500544 python setup.py develop \
545 )
546}
547
548
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500549# Service wrapper to start services
550# start_service service-name
551function start_service() {
Dean Troyer5218d452012-02-04 02:13:23 -0600552 if [[ -z "$os_PACKAGE" ]]; then
553 GetOSVersion
554 fi
555 if [[ "$os_PACKAGE" = "deb" ]]; then
556 sudo /usr/sbin/service $1 start
557 else
558 sudo /sbin/service $1 start
559 fi
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500560}
561
562
563# Service wrapper to stop services
564# stop_service service-name
565function stop_service() {
Dean Troyer5218d452012-02-04 02:13:23 -0600566 if [[ -z "$os_PACKAGE" ]]; then
567 GetOSVersion
568 fi
569 if [[ "$os_PACKAGE" = "deb" ]]; then
570 sudo /usr/sbin/service $1 stop
571 else
572 sudo /sbin/service $1 stop
573 fi
Dean Troyer7f9aa712012-01-31 12:11:56 -0600574}
575
576
577# Normalize config values to True or False
578# VAR=`trueorfalse default-value test-value`
579function trueorfalse() {
580 local default=$1
581 local testval=$2
582
583 [[ -z "$testval" ]] && { echo "$default"; return; }
584 [[ "0 no false False FALSE" =~ "$testval" ]] && { echo "False"; return; }
585 [[ "1 yes true True TRUE" =~ "$testval" ]] && { echo "True"; return; }
586 echo "$default"
587}
Dean Troyer27e32692012-03-16 16:16:56 -0500588
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500589
590# yum wrapper to set arguments correctly
591# yum_install package [package ...]
592function yum_install() {
593 [[ "$OFFLINE" = "True" ]] && return
594 local sudo="sudo"
595 [[ "$(id -u)" = "0" ]] && sudo="env"
596 $sudo http_proxy=$http_proxy https_proxy=$https_proxy \
Osamu Habuka7abe4f22012-07-25 12:39:32 +0900597 no_proxy=$no_proxy \
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500598 yum install -y "$@"
599}
600
601
Dean Troyer27e32692012-03-16 16:16:56 -0500602# Restore xtrace
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000603$XTRACE