blob: 86f4dd13e43d655dc9e9f2802db3dc8786d0b312 [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
132 elif [[ $service == n-* ]]; then
133 if [[ ! $file_to_parse =~ nova ]]; then
134 file_to_parse="${file_to_parse} nova"
135 fi
136 elif [[ $service == g-* ]]; then
137 if [[ ! $file_to_parse =~ glance ]]; then
138 file_to_parse="${file_to_parse} glance"
139 fi
140 elif [[ $service == key* ]]; then
141 if [[ ! $file_to_parse =~ keystone ]]; then
142 file_to_parse="${file_to_parse} keystone"
143 fi
144 fi
145 done
146
147 for file in ${file_to_parse}; do
148 local fname=${package_dir}/${file}
149 local OIFS line package distros distro
150 [[ -e $fname ]] || continue
151
152 OIFS=$IFS
153 IFS=$'\n'
154 for line in $(<${fname}); do
155 if [[ $line =~ "NOPRIME" ]]; then
156 continue
157 fi
158
159 if [[ $line =~ (.*)#.*dist:([^ ]*) ]]; then
160 # We are using BASH regexp matching feature.
161 package=${BASH_REMATCH[1]}
162 distros=${BASH_REMATCH[2]}
163 # In bash ${VAR,,} will lowecase VAR
164 [[ ${distros,,} =~ ${DISTRO,,} ]] && echo $package
165 continue
166 fi
167
168 echo ${line%#*}
169 done
170 IFS=$OIFS
171 done
172}
173
174
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500175# Determine OS Vendor, Release and Update
176# Tested with OS/X, Ubuntu, RedHat, CentOS, Fedora
177# Returns results in global variables:
178# os_VENDOR - vendor name
179# os_RELEASE - release
180# os_UPDATE - update
181# os_PACKAGE - package type
182# os_CODENAME - vendor's codename for release
183# GetOSVersion
184GetOSVersion() {
185 # Figure out which vendor we are
186 if [[ -n "`which sw_vers 2>/dev/null`" ]]; then
187 # OS/X
188 os_VENDOR=`sw_vers -productName`
189 os_RELEASE=`sw_vers -productVersion`
190 os_UPDATE=${os_RELEASE##*.}
191 os_RELEASE=${os_RELEASE%.*}
192 os_PACKAGE=""
193 if [[ "$os_RELEASE" =~ "10.7" ]]; then
194 os_CODENAME="lion"
195 elif [[ "$os_RELEASE" =~ "10.6" ]]; then
196 os_CODENAME="snow leopard"
197 elif [[ "$os_RELEASE" =~ "10.5" ]]; then
198 os_CODENAME="leopard"
199 elif [[ "$os_RELEASE" =~ "10.4" ]]; then
200 os_CODENAME="tiger"
201 elif [[ "$os_RELEASE" =~ "10.3" ]]; then
202 os_CODENAME="panther"
203 else
204 os_CODENAME=""
205 fi
206 elif [[ -x $(which lsb_release 2>/dev/null) ]]; then
207 os_VENDOR=$(lsb_release -i -s)
208 os_RELEASE=$(lsb_release -r -s)
209 os_UPDATE=""
210 if [[ "Debian,Ubuntu" =~ $os_VENDOR ]]; then
211 os_PACKAGE="deb"
212 else
213 os_PACKAGE="rpm"
214 fi
215 os_CODENAME=$(lsb_release -c -s)
216 elif [[ -r /etc/redhat-release ]]; then
217 # Red Hat Enterprise Linux Server release 5.5 (Tikanga)
218 # CentOS release 5.5 (Final)
219 # CentOS Linux release 6.0 (Final)
220 # Fedora release 16 (Verne)
221 os_CODENAME=""
222 for r in "Red Hat" CentOS Fedora; do
223 os_VENDOR=$r
224 if [[ -n "`grep \"$r\" /etc/redhat-release`" ]]; then
225 ver=`sed -e 's/^.* \(.*\) (\(.*\)).*$/\1\|\2/' /etc/redhat-release`
226 os_CODENAME=${ver#*|}
227 os_RELEASE=${ver%|*}
228 os_UPDATE=${os_RELEASE##*.}
229 os_RELEASE=${os_RELEASE%.*}
230 break
231 fi
232 os_VENDOR=""
233 done
234 os_PACKAGE="rpm"
235 fi
236 export os_VENDOR os_RELEASE os_UPDATE os_PACKAGE os_CODENAME
237}
238
Evgeniy Afonichev6a3912d2012-07-10 14:02:43 +0300239# git update using reference as a branch.
240function git_update_branch() {
241
242 GIT_BRANCH=$1
243
244 git checkout -f origin/$GIT_BRANCH
245 # a local branch might not exist
246 git branch -D $GIT_BRANCH || true
247 git checkout -b $GIT_BRANCH
248}
249
250
251# git update using reference as a tag. Be careful editing source at that repo
252# as working copy will be in a detached mode
253function git_update_tag() {
254
255 GIT_TAG=$1
256
257 git tag -d $GIT_TAG
258 # fetching given tag only
259 git fetch origin tag $GIT_TAG
260 git checkout -f $GIT_TAG
261}
262
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500263
Dean Troyera9e0a482012-07-09 14:07:23 -0500264# Translate the OS version values into common nomenclature
265# Sets ``DISTRO`` from the ``os_*`` values
266function GetDistro() {
267 GetOSVersion
268 if [[ "$os_VENDOR" =~ (Ubuntu) ]]; then
269 # 'Everyone' refers to Ubuntu releases by the code name adjective
270 DISTRO=$os_CODENAME
271 elif [[ "$os_VENDOR" =~ (Fedora) ]]; then
272 # For Fedora, just use 'f' and the release
273 DISTRO="f$os_RELEASE"
274 else
275 # Catch-all for now is Vendor + Release + Update
276 DISTRO="$os_VENDOR-$os_RELEASE.$os_UPDATE"
277 fi
278 export DISTRO
279}
280
281
Dean Troyer7f9aa712012-01-31 12:11:56 -0600282# git clone only if directory doesn't exist already. Since ``DEST`` might not
283# be owned by the installation user, we create the directory and change the
284# ownership to the proper user.
285# Set global RECLONE=yes to simulate a clone when dest-dir exists
James E. Blair94cb9602012-06-22 15:28:29 -0700286# Set global ERROR_ON_CLONE=True to abort execution with an error if the git repo
287# does not exist (default is False, meaning the repo will be cloned).
Dean Troyer7f9aa712012-01-31 12:11:56 -0600288# git_clone remote dest-dir branch
289function git_clone {
290 [[ "$OFFLINE" = "True" ]] && return
291
292 GIT_REMOTE=$1
293 GIT_DEST=$2
Evgeniy Afonichev6a3912d2012-07-10 14:02:43 +0300294 GIT_REF=$3
Dean Troyer7f9aa712012-01-31 12:11:56 -0600295
Evgeniy Afonichev6a3912d2012-07-10 14:02:43 +0300296 if echo $GIT_REF | egrep -q "^refs"; then
Dean Troyer7f9aa712012-01-31 12:11:56 -0600297 # If our branch name is a gerrit style refs/changes/...
298 if [[ ! -d $GIT_DEST ]]; then
James E. Blair94cb9602012-06-22 15:28:29 -0700299 [[ "$ERROR_ON_CLONE" = "True" ]] && exit 1
Dean Troyer7f9aa712012-01-31 12:11:56 -0600300 git clone $GIT_REMOTE $GIT_DEST
301 fi
302 cd $GIT_DEST
Evgeniy Afonichev6a3912d2012-07-10 14:02:43 +0300303 git fetch $GIT_REMOTE $GIT_REF && git checkout FETCH_HEAD
Dean Troyer7f9aa712012-01-31 12:11:56 -0600304 else
305 # do a full clone only if the directory doesn't exist
306 if [[ ! -d $GIT_DEST ]]; then
James E. Blair94cb9602012-06-22 15:28:29 -0700307 [[ "$ERROR_ON_CLONE" = "True" ]] && exit 1
Dean Troyer7f9aa712012-01-31 12:11:56 -0600308 git clone $GIT_REMOTE $GIT_DEST
309 cd $GIT_DEST
310 # This checkout syntax works for both branches and tags
Evgeniy Afonichev6a3912d2012-07-10 14:02:43 +0300311 git checkout $GIT_REF
Dean Troyer7f9aa712012-01-31 12:11:56 -0600312 elif [[ "$RECLONE" == "yes" ]]; then
313 # if it does exist then simulate what clone does if asked to RECLONE
314 cd $GIT_DEST
315 # set the url to pull from and fetch
316 git remote set-url origin $GIT_REMOTE
317 git fetch origin
318 # remove the existing ignored files (like pyc) as they cause breakage
319 # (due to the py files having older timestamps than our pyc, so python
320 # thinks the pyc files are correct using them)
321 find $GIT_DEST -name '*.pyc' -delete
Evgeniy Afonichev6a3912d2012-07-10 14:02:43 +0300322
323 # handle GIT_REF accordingly to type (tag, branch)
324 if [[ -n "`git show-ref refs/tags/$GIT_REF`" ]]; then
325 git_update_tag $GIT_REF
326 elif [[ -n "`git show-ref refs/heads/$GIT_REF`" ]]; then
327 git_update_branch $GIT_REF
328 else
329 echo $GIT_REF is neither branch nor tag
330 exit 1
331 fi
332
Dean Troyer7f9aa712012-01-31 12:11:56 -0600333 fi
334 fi
335}
336
337
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500338# Comment an option in an INI file
Chmouel Boudjnahc7214e82012-06-06 13:56:39 +0200339# inicomment config-file section option
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500340function inicomment() {
341 local file=$1
342 local section=$2
343 local option=$3
344 sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=.*$\)|#\1|" $file
345}
346
Chmouel Boudjnahc7214e82012-06-06 13:56:39 +0200347# Uncomment an option in an INI file
348# iniuncomment config-file section option
349function iniuncomment() {
350 local file=$1
351 local section=$2
352 local option=$3
353 sed -i -e "/^\[$section\]/,/^\[.*\]/ s|[^ \t]*#[ \t]*\($option[ \t]*=.*$\)|\1|" $file
354}
355
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500356
357# Get an option from an INI file
Dean Troyer09e636e2012-03-19 16:31:12 -0500358# iniget config-file section option
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500359function iniget() {
360 local file=$1
361 local section=$2
362 local option=$3
363 local line
364 line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" $file)
365 echo ${line#*=}
366}
367
368
369# Set an option in an INI file
Dean Troyer09e636e2012-03-19 16:31:12 -0500370# iniset config-file section option value
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500371function iniset() {
372 local file=$1
373 local section=$2
374 local option=$3
375 local value=$4
Dean Troyer09e636e2012-03-19 16:31:12 -0500376 if ! grep -q "^\[$section\]" $file; then
377 # Add section at the end
378 echo -e "\n[$section]" >>$file
379 fi
380 if [[ -z "$(iniget $file $section $option)" ]]; then
381 # Add it
382 sed -i -e "/^\[$section\]/ a\\
383$option = $value
384" $file
385 else
386 # Replace it
387 sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=[ \t]*\).*$|\1$value|" $file
388 fi
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500389}
390
391
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000392# is_service_enabled() checks if the service(s) specified as arguments are
393# enabled by the user in **ENABLED_SERVICES**.
394#
395# If there are multiple services specified as arguments the test performs a
396# boolean OR or if any of the services specified on the command line
397# return true.
398#
399# There is a special cases for some 'catch-all' services::
400# **nova** returns true if any service enabled start with **n-**
401# **glance** returns true if any service enabled start with **g-**
402# **quantum** returns true if any service enabled start with **q-**
403function is_service_enabled() {
404 services=$@
405 for service in ${services}; do
406 [[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && return 0
407 [[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && return 0
Dean Troyer67787e62012-05-02 11:48:15 -0500408 [[ ${service} == "cinder" && ${ENABLED_SERVICES} =~ "c-" ]] && return 0
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000409 [[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && return 0
410 [[ ${service} == "quantum" && ${ENABLED_SERVICES} =~ "q-" ]] && return 0
411 done
412 return 1
413}
414
Doug Hellmannf04178f2012-07-05 17:10:03 -0400415# remove extra commas from the input string (ENABLED_SERVICES)
416function _cleanup_service_list () {
417 echo "$1" | sed -e '
418 s/,,/,/g;
419 s/^,//;
420 s/,$//
421 '
422}
423
424# enable_service() adds the services passed as argument to the
425# **ENABLED_SERVICES** list, if they are not already present.
426#
427# For example:
428#
429# enable_service n-vol
430#
431# This function does not know about the special cases
432# for nova, glance, and quantum built into is_service_enabled().
433function enable_service() {
434 local tmpsvcs="${ENABLED_SERVICES}"
435 for service in $@; do
436 if ! is_service_enabled $service; then
437 tmpsvcs+=",$service"
438 fi
439 done
440 ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs")
441 disable_negated_services
442}
443
444# disable_service() removes the services passed as argument to the
445# **ENABLED_SERVICES** list, if they are present.
446#
447# For example:
448#
449# disable_service n-vol
450#
451# This function does not know about the special cases
452# for nova, glance, and quantum built into is_service_enabled().
453function disable_service() {
454 local tmpsvcs=",${ENABLED_SERVICES},"
455 local service
456 for service in $@; do
457 if is_service_enabled $service; then
458 tmpsvcs=${tmpsvcs//,$service,/,}
459 fi
460 done
461 ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs")
462}
463
464# disable_all_services() removes all current services
465# from **ENABLED_SERVICES** to reset the configuration
466# before a minimal installation
467function disable_all_services() {
468 ENABLED_SERVICES=""
469}
470
471# We are looking for services with a - at the beginning to force
472# excluding those services. For example if you want to install all the default
473# services but not nova-volume (n-vol) you can have this set in your localrc :
474# ENABLED_SERVICES+=",-n-vol"
475function disable_negated_services() {
476 local tmpsvcs="${ENABLED_SERVICES}"
477 local service
478 for service in ${tmpsvcs//,/ }; do
479 if [[ ${service} == -* ]]; then
480 tmpsvcs=$(echo ${tmpsvcs}|sed -r "s/(,)?(-)?${service#-}(,)?/,/g")
481 fi
482 done
483 ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs")
484}
Dean Troyer489bd2a2012-03-02 10:44:29 -0600485
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500486# Distro-agnostic package installer
487# install_package package [package ...]
488function install_package() {
489 if [[ -z "$os_PACKAGE" ]]; then
490 GetOSVersion
491 fi
492 if [[ "$os_PACKAGE" = "deb" ]]; then
493 apt_get install "$@"
494 else
495 yum_install "$@"
496 fi
497}
498
499
Dean Troyer489bd2a2012-03-02 10:44:29 -0600500# Test if the named environment variable is set and not zero length
501# is_set env-var
502function is_set() {
503 local var=\$"$1"
504 if eval "[ -z $var ]"; then
505 return 1
506 fi
507 return 0
508}
509
510
Dean Troyer7f9aa712012-01-31 12:11:56 -0600511# pip install wrapper to set cache and proxy environment variables
512# pip_install package [package ...]
513function pip_install {
Dean Troyerd0b21e22012-03-07 14:52:25 -0600514 [[ "$OFFLINE" = "True" || -z "$@" ]] && return
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500515 if [[ -z "$os_PACKAGE" ]]; then
516 GetOSVersion
517 fi
Monty Taylor47f02062012-07-26 11:09:24 -0500518 if [[ $TRACK_DEPENDS = True ]] ; then
519 source $DEST/.venv/bin/activate
520 CMD_PIP=$DEST/.venv/bin/pip
521 SUDO_PIP="env"
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500522 else
Monty Taylor47f02062012-07-26 11:09:24 -0500523 SUDO_PIP="sudo"
524 if [[ "$os_PACKAGE" = "deb" ]]; then
525 CMD_PIP=/usr/bin/pip
526 else
527 CMD_PIP=/usr/bin/pip-python
528 fi
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500529 fi
Monty Taylor47f02062012-07-26 11:09:24 -0500530 $SUDO_PIP PIP_DOWNLOAD_CACHE=${PIP_DOWNLOAD_CACHE:-/var/cache/pip} \
Dean Troyer7f9aa712012-01-31 12:11:56 -0600531 HTTP_PROXY=$http_proxy \
532 HTTPS_PROXY=$https_proxy \
Osamu Habuka7abe4f22012-07-25 12:39:32 +0900533 NO_PROXY=$no_proxy \
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500534 $CMD_PIP install --use-mirrors $@
535}
536
537
538# Service wrapper to restart services
539# restart_service service-name
540function restart_service() {
Dean Troyer5218d452012-02-04 02:13:23 -0600541 if [[ -z "$os_PACKAGE" ]]; then
542 GetOSVersion
543 fi
544 if [[ "$os_PACKAGE" = "deb" ]]; then
545 sudo /usr/sbin/service $1 restart
546 else
547 sudo /sbin/service $1 restart
548 fi
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500549}
550
551
Dean Troyerbbafb1b2012-06-11 16:51:39 -0500552# pip install the dependencies of the package before we do the setup.py
553# develop, so that pip and not distutils process the dependency chain
554# setup_develop directory
555function setup_develop() {
Monty Taylor47f02062012-07-26 11:09:24 -0500556 if [[ $TRACK_DEPENDS = True ]] ; then
557 SUDO_CMD="env"
558 else
559 SUDO_CMD="sudo"
560 fi
Dean Troyerbbafb1b2012-06-11 16:51:39 -0500561 (cd $1; \
562 python setup.py egg_info; \
563 raw_links=$(awk '/^.+/ {print "-f " $1}' *.egg-info/dependency_links.txt); \
564 depend_links=$(echo $raw_links | xargs); \
565 pip_install -r *-info/requires.txt $depend_links; \
Monty Taylor47f02062012-07-26 11:09:24 -0500566 $SUDO_CMD \
Dean Troyerbbafb1b2012-06-11 16:51:39 -0500567 HTTP_PROXY=$http_proxy \
568 HTTPS_PROXY=$https_proxy \
Osamu Habuka7abe4f22012-07-25 12:39:32 +0900569 NO_PROXY=$no_proxy \
Dean Troyerbbafb1b2012-06-11 16:51:39 -0500570 python setup.py develop \
571 )
572}
573
574
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500575# Service wrapper to start services
576# start_service service-name
577function start_service() {
Dean Troyer5218d452012-02-04 02:13:23 -0600578 if [[ -z "$os_PACKAGE" ]]; then
579 GetOSVersion
580 fi
581 if [[ "$os_PACKAGE" = "deb" ]]; then
582 sudo /usr/sbin/service $1 start
583 else
584 sudo /sbin/service $1 start
585 fi
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500586}
587
588
589# Service wrapper to stop services
590# stop_service service-name
591function stop_service() {
Dean Troyer5218d452012-02-04 02:13:23 -0600592 if [[ -z "$os_PACKAGE" ]]; then
593 GetOSVersion
594 fi
595 if [[ "$os_PACKAGE" = "deb" ]]; then
596 sudo /usr/sbin/service $1 stop
597 else
598 sudo /sbin/service $1 stop
599 fi
Dean Troyer7f9aa712012-01-31 12:11:56 -0600600}
601
602
603# Normalize config values to True or False
604# VAR=`trueorfalse default-value test-value`
605function trueorfalse() {
606 local default=$1
607 local testval=$2
608
609 [[ -z "$testval" ]] && { echo "$default"; return; }
610 [[ "0 no false False FALSE" =~ "$testval" ]] && { echo "False"; return; }
611 [[ "1 yes true True TRUE" =~ "$testval" ]] && { echo "True"; return; }
612 echo "$default"
613}
Dean Troyer27e32692012-03-16 16:16:56 -0500614
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500615
616# yum wrapper to set arguments correctly
617# yum_install package [package ...]
618function yum_install() {
619 [[ "$OFFLINE" = "True" ]] && return
620 local sudo="sudo"
621 [[ "$(id -u)" = "0" ]] && sudo="env"
622 $sudo http_proxy=$http_proxy https_proxy=$https_proxy \
Osamu Habuka7abe4f22012-07-25 12:39:32 +0900623 no_proxy=$no_proxy \
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500624 yum install -y "$@"
625}
626
627
Dean Troyer27e32692012-03-16 16:16:56 -0500628# Restore xtrace
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000629$XTRACE