| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 1 | # functions - Common functions used by DevStack components | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 2 | # | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 3 | # The following variables are assumed to be defined by certain functions: | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 4 | # ``ENABLED_SERVICES`` | 
| DennyZhang | b5e11ff | 2013-10-14 00:53:37 -0500 | [diff] [blame] | 5 | # ``ERROR_ON_CLONE`` | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 6 | # ``FILES`` | 
|  | 7 | # ``GLANCE_HOSTPORT`` | 
|  | 8 | # ``OFFLINE`` | 
|  | 9 | # ``PIP_DOWNLOAD_CACHE`` | 
| Maru Newby | 3a87edd | 2012-10-25 23:01:06 +0000 | [diff] [blame] | 10 | # ``PIP_USE_MIRRORS`` | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 11 | # ``RECLONE`` | 
|  | 12 | # ``TRACK_DEPENDS`` | 
|  | 13 | # ``http_proxy``, ``https_proxy``, ``no_proxy`` | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 14 |  | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 15 |  | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 16 | # Save trace setting | 
|  | 17 | XTRACE=$(set +o | grep xtrace) | 
|  | 18 | set +o xtrace | 
|  | 19 |  | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 20 |  | 
| Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 21 | # Convert CIDR notation to a IPv4 netmask | 
|  | 22 | # cidr2netmask cidr-bits | 
|  | 23 | function 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 | 
|  | 34 | function 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 Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 45 | # address_in_net ip-address ip-range | 
| Vishvananda Ishaya | c9ad14b | 2012-07-03 20:29:01 +0000 | [diff] [blame] | 46 | function address_in_net() { | 
| Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 47 | 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 Ishaya | c9ad14b | 2012-07-03 20:29:01 +0000 | [diff] [blame] | 53 | } | 
|  | 54 |  | 
|  | 55 |  | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 56 | # Wrapper for ``apt-get`` to set cache and proxy environment variables | 
|  | 57 | # Uses globals ``OFFLINE``, ``*_proxy` | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 58 | # apt_get operation package [package ...] | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 59 | function apt_get() { | 
| Dean Troyer | d0b21e2 | 2012-03-07 14:52:25 -0600 | [diff] [blame] | 60 | [[ "$OFFLINE" = "True" || -z "$@" ]] && return | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 61 | local sudo="sudo" | 
|  | 62 | [[ "$(id -u)" = "0" ]] && sudo="env" | 
|  | 63 | $sudo DEBIAN_FRONTEND=noninteractive \ | 
|  | 64 | http_proxy=$http_proxy https_proxy=$https_proxy \ | 
| Osamu Habuka | 7abe4f2 | 2012-07-25 12:39:32 +0900 | [diff] [blame] | 65 | no_proxy=$no_proxy \ | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 66 | 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 | 
|  | 72 | function cp_it { | 
|  | 73 | if [ -e $1 ] || [ -d $1 ]; then | 
|  | 74 | cp -pRL $1 $2 | 
|  | 75 | fi | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 |  | 
| Kui Shi | 5e28a3e | 2013-08-02 17:26:28 +0800 | [diff] [blame] | 79 | # Prints backtrace info | 
|  | 80 | # filename:lineno:function | 
|  | 81 | function 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 Troyer | ac93efb | 2013-03-13 14:30:54 -0500 | [diff] [blame] | 92 | # Prints line number and "message" then exits | 
|  | 93 | # die $LINENO "message" | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 94 | function die() { | 
| Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 95 | local exitcode=$? | 
| Dean Troyer | 896eb66 | 2013-04-05 15:02:01 -0500 | [diff] [blame] | 96 | set +o xtrace | 
|  | 97 | local line=$1; shift | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 98 | if [ $exitcode == 0 ]; then | 
|  | 99 | exitcode=1 | 
|  | 100 | fi | 
| Kui Shi | 5e28a3e | 2013-08-02 17:26:28 +0800 | [diff] [blame] | 101 | backtrace 2 | 
| Dean Troyer | 896eb66 | 2013-04-05 15:02:01 -0500 | [diff] [blame] | 102 | err $line "$*" | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 103 | exit $exitcode | 
| Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 104 | } | 
|  | 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 Troyer | ac93efb | 2013-03-13 14:30:54 -0500 | [diff] [blame] | 110 | # die_if_not_set $LINENO env-var "message" | 
| Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 111 | function die_if_not_set() { | 
| Dean Troyer | 896eb66 | 2013-04-05 15:02:01 -0500 | [diff] [blame] | 112 | 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" | 
|  | 126 | function err() { | 
|  | 127 | local exitcode=$? | 
|  | 128 | errXTRACE=$(set +o | grep xtrace) | 
|  | 129 | set +o xtrace | 
| Kui Shi | 17df077 | 2013-08-02 17:55:41 +0800 | [diff] [blame] | 130 | local msg="[ERROR] ${BASH_SOURCE[2]}:$1 $2" | 
| Dean Troyer | 896eb66 | 2013-04-05 15:02:01 -0500 | [diff] [blame] | 131 | 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" | 
|  | 144 | function 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 Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 155 | } | 
|  | 156 |  | 
|  | 157 |  | 
| Dean Troyer | 893e663 | 2013-09-13 15:05:51 -0500 | [diff] [blame] | 158 | # Prints line number and "message" in warning format | 
|  | 159 | # warn $LINENO "message" | 
|  | 160 | function warn() { | 
|  | 161 | local exitcode=$? | 
|  | 162 | errXTRACE=$(set +o | grep xtrace) | 
|  | 163 | set +o xtrace | 
|  | 164 | local msg="[WARNING] ${BASH_SOURCE[2]}:$1 $2" | 
|  | 165 | echo $msg 1>&2; | 
|  | 166 | if [[ -n ${SCREEN_LOGDIR} ]]; then | 
|  | 167 | echo $msg >> "${SCREEN_LOGDIR}/error.log" | 
|  | 168 | fi | 
|  | 169 | $errXTRACE | 
|  | 170 | return $exitcode | 
|  | 171 | } | 
|  | 172 |  | 
|  | 173 |  | 
| Dean Troyer | 48352ee | 2012-12-12 12:50:38 -0600 | [diff] [blame] | 174 | # HTTP and HTTPS proxy servers are supported via the usual environment variables [1] | 
|  | 175 | # ``http_proxy``, ``https_proxy`` and ``no_proxy``. They can be set in | 
|  | 176 | # ``localrc`` or on the command line if necessary:: | 
|  | 177 | # | 
|  | 178 | # [1] http://www.w3.org/Daemon/User/Proxies/ProxyClients.html | 
|  | 179 | # | 
|  | 180 | #     http_proxy=http://proxy.example.com:3128/ no_proxy=repo.example.net ./stack.sh | 
|  | 181 |  | 
|  | 182 | function export_proxy_variables() { | 
|  | 183 | if [[ -n "$http_proxy" ]]; then | 
|  | 184 | export http_proxy=$http_proxy | 
|  | 185 | fi | 
|  | 186 | if [[ -n "$https_proxy" ]]; then | 
|  | 187 | export https_proxy=$https_proxy | 
|  | 188 | fi | 
|  | 189 | if [[ -n "$no_proxy" ]]; then | 
|  | 190 | export no_proxy=$no_proxy | 
|  | 191 | fi | 
|  | 192 | } | 
|  | 193 |  | 
|  | 194 |  | 
| Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 195 | # Grab a numbered field from python prettytable output | 
|  | 196 | # Fields are numbered starting with 1 | 
|  | 197 | # Reverse syntax is supported: -1 is the last field, -2 is second to last, etc. | 
|  | 198 | # get_field field-number | 
|  | 199 | function get_field() { | 
|  | 200 | while read data; do | 
|  | 201 | if [ "$1" -lt 0 ]; then | 
|  | 202 | field="(\$(NF$1))" | 
|  | 203 | else | 
|  | 204 | field="\$$(($1 + 1))" | 
|  | 205 | fi | 
|  | 206 | echo "$data" | awk -F'[ \t]*\\|[ \t]*' "{print $field}" | 
|  | 207 | done | 
|  | 208 | } | 
|  | 209 |  | 
|  | 210 |  | 
| Dean Troyer | c892bde | 2013-03-13 14:06:13 -0500 | [diff] [blame] | 211 | # Get the default value for HOST_IP | 
|  | 212 | # get_default_host_ip fixed_range floating_range host_ip_iface host_ip | 
|  | 213 | function get_default_host_ip() { | 
|  | 214 | local fixed_range=$1 | 
|  | 215 | local floating_range=$2 | 
|  | 216 | local host_ip_iface=$3 | 
|  | 217 | local host_ip=$4 | 
|  | 218 |  | 
|  | 219 | # Find the interface used for the default route | 
|  | 220 | host_ip_iface=${host_ip_iface:-$(ip route | sed -n '/^default/{ s/.*dev \(\w\+\)\s\+.*/\1/; p; }' | head -1)} | 
|  | 221 | # Search for an IP unless an explicit is set by ``HOST_IP`` environment variable | 
|  | 222 | if [ -z "$host_ip" -o "$host_ip" == "dhcp" ]; then | 
|  | 223 | host_ip="" | 
|  | 224 | host_ips=`LC_ALL=C ip -f inet addr show ${host_ip_iface} | awk '/inet/ {split($2,parts,"/");  print parts[1]}'` | 
|  | 225 | for IP in $host_ips; do | 
|  | 226 | # Attempt to filter out IP addresses that are part of the fixed and | 
|  | 227 | # floating range. Note that this method only works if the ``netaddr`` | 
|  | 228 | # python library is installed. If it is not installed, an error | 
|  | 229 | # will be printed and the first IP from the interface will be used. | 
|  | 230 | # If that is not correct set ``HOST_IP`` in ``localrc`` to the correct | 
|  | 231 | # address. | 
|  | 232 | if ! (address_in_net $IP $fixed_range || address_in_net $IP $floating_range); then | 
|  | 233 | host_ip=$IP | 
|  | 234 | break; | 
|  | 235 | fi | 
|  | 236 | done | 
|  | 237 | fi | 
|  | 238 | echo $host_ip | 
|  | 239 | } | 
|  | 240 |  | 
|  | 241 |  | 
| Isaku Yamahata | 8c43809 | 2013-02-12 22:30:56 +0900 | [diff] [blame] | 242 | function _get_package_dir() { | 
|  | 243 | local pkg_dir | 
|  | 244 | if is_ubuntu; then | 
|  | 245 | pkg_dir=$FILES/apts | 
|  | 246 | elif is_fedora; then | 
|  | 247 | pkg_dir=$FILES/rpms | 
|  | 248 | elif is_suse; then | 
|  | 249 | pkg_dir=$FILES/rpms-suse | 
|  | 250 | else | 
|  | 251 | exit_distro_not_supported "list of packages" | 
|  | 252 | fi | 
|  | 253 | echo "$pkg_dir" | 
|  | 254 | } | 
|  | 255 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 256 |  | 
| Dean Troyer | 7e27051 | 2012-06-14 15:23:24 -0500 | [diff] [blame] | 257 | # get_packages() collects a list of package names of any type from the | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 258 | # prerequisite files in ``files/{apts|rpms}``.  The list is intended | 
|  | 259 | # to be passed to a package installer such as apt or yum. | 
| Dean Troyer | 7e27051 | 2012-06-14 15:23:24 -0500 | [diff] [blame] | 260 | # | 
| Isaku Yamahata | 8c43809 | 2013-02-12 22:30:56 +0900 | [diff] [blame] | 261 | # Only packages required for the services in 1st argument will be | 
| Dean Troyer | 7e27051 | 2012-06-14 15:23:24 -0500 | [diff] [blame] | 262 | # included.  Two bits of metadata are recognized in the prerequisite files: | 
|  | 263 | # - ``# NOPRIME`` defers installation to be performed later in stack.sh | 
|  | 264 | # - ``# dist:DISTRO`` or ``dist:DISTRO1,DISTRO2`` limits the selection | 
|  | 265 | #   of the package to the distros listed.  The distro names are case insensitive. | 
| Dean Troyer | 7e27051 | 2012-06-14 15:23:24 -0500 | [diff] [blame] | 266 | function get_packages() { | 
| Dean Troyer | ca5af86 | 2013-10-04 13:33:07 -0500 | [diff] [blame] | 267 | local services=$@ | 
| Isaku Yamahata | 8c43809 | 2013-02-12 22:30:56 +0900 | [diff] [blame] | 268 | local package_dir=$(_get_package_dir) | 
| Dean Troyer | 7e27051 | 2012-06-14 15:23:24 -0500 | [diff] [blame] | 269 | local file_to_parse | 
|  | 270 | local service | 
|  | 271 |  | 
|  | 272 | if [[ -z "$package_dir" ]]; then | 
|  | 273 | echo "No package directory supplied" | 
|  | 274 | return 1 | 
|  | 275 | fi | 
|  | 276 | if [[ -z "$DISTRO" ]]; then | 
| Vincent Untz | 855c587 | 2012-10-04 13:36:46 +0200 | [diff] [blame] | 277 | GetDistro | 
| Dean Troyer | 7e27051 | 2012-06-14 15:23:24 -0500 | [diff] [blame] | 278 | fi | 
| Dean Troyer | ca5af86 | 2013-10-04 13:33:07 -0500 | [diff] [blame] | 279 | for service in ${services//,/ }; do | 
| Dean Troyer | 7e27051 | 2012-06-14 15:23:24 -0500 | [diff] [blame] | 280 | # Allow individual services to specify dependencies | 
|  | 281 | if [[ -e ${package_dir}/${service} ]]; then | 
|  | 282 | file_to_parse="${file_to_parse} $service" | 
|  | 283 | fi | 
|  | 284 | # NOTE(sdague) n-api needs glance for now because that's where | 
|  | 285 | # glance client is | 
|  | 286 | if [[ $service == n-api ]]; then | 
|  | 287 | if [[ ! $file_to_parse =~ nova ]]; then | 
|  | 288 | file_to_parse="${file_to_parse} nova" | 
|  | 289 | fi | 
|  | 290 | if [[ ! $file_to_parse =~ glance ]]; then | 
|  | 291 | file_to_parse="${file_to_parse} glance" | 
|  | 292 | fi | 
|  | 293 | elif [[ $service == c-* ]]; then | 
|  | 294 | if [[ ! $file_to_parse =~ cinder ]]; then | 
|  | 295 | file_to_parse="${file_to_parse} cinder" | 
|  | 296 | fi | 
| John H. Tran | 9336164 | 2012-07-26 11:22:05 -0700 | [diff] [blame] | 297 | elif [[ $service == ceilometer-* ]]; then | 
|  | 298 | if [[ ! $file_to_parse =~ ceilometer ]]; then | 
|  | 299 | file_to_parse="${file_to_parse} ceilometer" | 
|  | 300 | fi | 
| Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 301 | elif [[ $service == s-* ]]; then | 
|  | 302 | if [[ ! $file_to_parse =~ swift ]]; then | 
|  | 303 | file_to_parse="${file_to_parse} swift" | 
|  | 304 | fi | 
| Dean Troyer | 7e27051 | 2012-06-14 15:23:24 -0500 | [diff] [blame] | 305 | elif [[ $service == n-* ]]; then | 
|  | 306 | if [[ ! $file_to_parse =~ nova ]]; then | 
|  | 307 | file_to_parse="${file_to_parse} nova" | 
|  | 308 | fi | 
|  | 309 | elif [[ $service == g-* ]]; then | 
|  | 310 | if [[ ! $file_to_parse =~ glance ]]; then | 
|  | 311 | file_to_parse="${file_to_parse} glance" | 
|  | 312 | fi | 
|  | 313 | elif [[ $service == key* ]]; then | 
|  | 314 | if [[ ! $file_to_parse =~ keystone ]]; then | 
|  | 315 | file_to_parse="${file_to_parse} keystone" | 
|  | 316 | fi | 
| Robert Collins | 0a9954f | 2012-11-20 11:34:25 +1300 | [diff] [blame] | 317 | elif [[ $service == q-* ]]; then | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 318 | if [[ ! $file_to_parse =~ neutron ]]; then | 
|  | 319 | file_to_parse="${file_to_parse} neutron" | 
| Robert Collins | 0a9954f | 2012-11-20 11:34:25 +1300 | [diff] [blame] | 320 | fi | 
| Dean Troyer | 7e27051 | 2012-06-14 15:23:24 -0500 | [diff] [blame] | 321 | fi | 
|  | 322 | done | 
|  | 323 |  | 
|  | 324 | for file in ${file_to_parse}; do | 
|  | 325 | local fname=${package_dir}/${file} | 
|  | 326 | local OIFS line package distros distro | 
|  | 327 | [[ -e $fname ]] || continue | 
|  | 328 |  | 
|  | 329 | OIFS=$IFS | 
|  | 330 | IFS=$'\n' | 
|  | 331 | for line in $(<${fname}); do | 
|  | 332 | if [[ $line =~ "NOPRIME" ]]; then | 
|  | 333 | continue | 
|  | 334 | fi | 
|  | 335 |  | 
| Christian Berendt | 71d5630 | 2013-07-22 11:37:42 +0200 | [diff] [blame] | 336 | # Assume we want this package | 
|  | 337 | package=${line%#*} | 
|  | 338 | inst_pkg=1 | 
|  | 339 |  | 
|  | 340 | # Look for # dist:xxx in comment | 
| Dean Troyer | 7e27051 | 2012-06-14 15:23:24 -0500 | [diff] [blame] | 341 | if [[ $line =~ (.*)#.*dist:([^ ]*) ]]; then | 
|  | 342 | # We are using BASH regexp matching feature. | 
|  | 343 | package=${BASH_REMATCH[1]} | 
|  | 344 | distros=${BASH_REMATCH[2]} | 
|  | 345 | # In bash ${VAR,,} will lowecase VAR | 
| Christian Berendt | 71d5630 | 2013-07-22 11:37:42 +0200 | [diff] [blame] | 346 | # Look for a match in the distro list | 
|  | 347 | if [[ ! ${distros,,} =~ ${DISTRO,,} ]]; then | 
|  | 348 | # If no match then skip this package | 
|  | 349 | inst_pkg=0 | 
|  | 350 | fi | 
| Dean Troyer | 7e27051 | 2012-06-14 15:23:24 -0500 | [diff] [blame] | 351 | fi | 
|  | 352 |  | 
| Christian Berendt | 71d5630 | 2013-07-22 11:37:42 +0200 | [diff] [blame] | 353 | # Look for # testonly in comment | 
|  | 354 | if [[ $line =~ (.*)#.*testonly.* ]]; then | 
|  | 355 | package=${BASH_REMATCH[1]} | 
|  | 356 | # Are we installing test packages? (test for the default value) | 
|  | 357 | if [[ $INSTALL_TESTONLY_PACKAGES = "False" ]]; then | 
|  | 358 | # If not installing test packages the skip this package | 
|  | 359 | inst_pkg=0 | 
|  | 360 | fi | 
|  | 361 | fi | 
|  | 362 |  | 
|  | 363 | if [[ $inst_pkg = 1 ]]; then | 
|  | 364 | echo $package | 
|  | 365 | fi | 
| Dean Troyer | 7e27051 | 2012-06-14 15:23:24 -0500 | [diff] [blame] | 366 | done | 
|  | 367 | IFS=$OIFS | 
|  | 368 | done | 
|  | 369 | } | 
|  | 370 |  | 
|  | 371 |  | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 372 | # Determine OS Vendor, Release and Update | 
|  | 373 | # Tested with OS/X, Ubuntu, RedHat, CentOS, Fedora | 
|  | 374 | # Returns results in global variables: | 
|  | 375 | # os_VENDOR - vendor name | 
|  | 376 | # os_RELEASE - release | 
|  | 377 | # os_UPDATE - update | 
|  | 378 | # os_PACKAGE - package type | 
|  | 379 | # os_CODENAME - vendor's codename for release | 
|  | 380 | # GetOSVersion | 
|  | 381 | GetOSVersion() { | 
|  | 382 | # Figure out which vendor we are | 
| Mehdi Abaakouk | aee9412 | 2013-09-30 11:48:00 +0000 | [diff] [blame] | 383 | if [[ -x "`which sw_vers 2>/dev/null`" ]]; then | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 384 | # OS/X | 
|  | 385 | os_VENDOR=`sw_vers -productName` | 
|  | 386 | os_RELEASE=`sw_vers -productVersion` | 
|  | 387 | os_UPDATE=${os_RELEASE##*.} | 
|  | 388 | os_RELEASE=${os_RELEASE%.*} | 
|  | 389 | os_PACKAGE="" | 
|  | 390 | if [[ "$os_RELEASE" =~ "10.7" ]]; then | 
|  | 391 | os_CODENAME="lion" | 
|  | 392 | elif [[ "$os_RELEASE" =~ "10.6" ]]; then | 
|  | 393 | os_CODENAME="snow leopard" | 
|  | 394 | elif [[ "$os_RELEASE" =~ "10.5" ]]; then | 
|  | 395 | os_CODENAME="leopard" | 
|  | 396 | elif [[ "$os_RELEASE" =~ "10.4" ]]; then | 
|  | 397 | os_CODENAME="tiger" | 
|  | 398 | elif [[ "$os_RELEASE" =~ "10.3" ]]; then | 
|  | 399 | os_CODENAME="panther" | 
|  | 400 | else | 
|  | 401 | os_CODENAME="" | 
|  | 402 | fi | 
|  | 403 | elif [[ -x $(which lsb_release 2>/dev/null) ]]; then | 
|  | 404 | os_VENDOR=$(lsb_release -i -s) | 
|  | 405 | os_RELEASE=$(lsb_release -r -s) | 
|  | 406 | os_UPDATE="" | 
| Attila Fazekas | af988fd | 2013-01-13 14:20:47 +0100 | [diff] [blame] | 407 | os_PACKAGE="rpm" | 
| Derek Morton | 4a8496e | 2013-04-08 23:46:08 -0500 | [diff] [blame] | 408 | if [[ "Debian,Ubuntu,LinuxMint" =~ $os_VENDOR ]]; then | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 409 | os_PACKAGE="deb" | 
| Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 410 | elif [[ "SUSE LINUX" =~ $os_VENDOR ]]; then | 
|  | 411 | lsb_release -d -s | grep -q openSUSE | 
|  | 412 | if [[ $? -eq 0 ]]; then | 
|  | 413 | os_VENDOR="openSUSE" | 
|  | 414 | fi | 
| Vincent Untz | cd1fe98 | 2013-03-12 18:04:29 +0100 | [diff] [blame] | 415 | elif [[ $os_VENDOR == "openSUSE project" ]]; then | 
|  | 416 | os_VENDOR="openSUSE" | 
| Attila Fazekas | af988fd | 2013-01-13 14:20:47 +0100 | [diff] [blame] | 417 | elif [[ $os_VENDOR =~ Red.*Hat ]]; then | 
|  | 418 | os_VENDOR="Red Hat" | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 419 | fi | 
|  | 420 | os_CODENAME=$(lsb_release -c -s) | 
|  | 421 | elif [[ -r /etc/redhat-release ]]; then | 
|  | 422 | # Red Hat Enterprise Linux Server release 5.5 (Tikanga) | 
|  | 423 | # CentOS release 5.5 (Final) | 
|  | 424 | # CentOS Linux release 6.0 (Final) | 
|  | 425 | # Fedora release 16 (Verne) | 
| Bob Ball | 4669122 | 2013-08-12 17:28:50 +0100 | [diff] [blame] | 426 | # XenServer release 6.2.0-70446c (xenenterprise) | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 427 | os_CODENAME="" | 
| Bob Ball | 4669122 | 2013-08-12 17:28:50 +0100 | [diff] [blame] | 428 | for r in "Red Hat" CentOS Fedora XenServer; do | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 429 | os_VENDOR=$r | 
|  | 430 | if [[ -n "`grep \"$r\" /etc/redhat-release`" ]]; then | 
|  | 431 | ver=`sed -e 's/^.* \(.*\) (\(.*\)).*$/\1\|\2/' /etc/redhat-release` | 
|  | 432 | os_CODENAME=${ver#*|} | 
|  | 433 | os_RELEASE=${ver%|*} | 
|  | 434 | os_UPDATE=${os_RELEASE##*.} | 
|  | 435 | os_RELEASE=${os_RELEASE%.*} | 
|  | 436 | break | 
|  | 437 | fi | 
|  | 438 | os_VENDOR="" | 
|  | 439 | done | 
|  | 440 | os_PACKAGE="rpm" | 
| Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 441 | elif [[ -r /etc/SuSE-release ]]; then | 
|  | 442 | for r in openSUSE "SUSE Linux"; do | 
|  | 443 | if [[ "$r" = "SUSE Linux" ]]; then | 
|  | 444 | os_VENDOR="SUSE LINUX" | 
|  | 445 | else | 
|  | 446 | os_VENDOR=$r | 
|  | 447 | fi | 
|  | 448 |  | 
|  | 449 | if [[ -n "`grep \"$r\" /etc/SuSE-release`" ]]; then | 
|  | 450 | os_CODENAME=`grep "CODENAME = " /etc/SuSE-release | sed 's:.* = ::g'` | 
|  | 451 | os_RELEASE=`grep "VERSION = " /etc/SuSE-release | sed 's:.* = ::g'` | 
|  | 452 | os_UPDATE=`grep "PATCHLEVEL = " /etc/SuSE-release | sed 's:.* = ::g'` | 
|  | 453 | break | 
|  | 454 | fi | 
|  | 455 | os_VENDOR="" | 
|  | 456 | done | 
|  | 457 | os_PACKAGE="rpm" | 
| Émilien Macchi | b2ef890 | 2013-05-04 00:48:20 +0200 | [diff] [blame] | 458 | # If lsb_release is not installed, we should be able to detect Debian OS | 
|  | 459 | elif [[ -f /etc/debian_version ]] && [[ $(cat /proc/version) =~ "Debian" ]]; then | 
|  | 460 | os_VENDOR="Debian" | 
|  | 461 | os_PACKAGE="deb" | 
|  | 462 | os_CODENAME=$(awk '/VERSION=/' /etc/os-release | sed 's/VERSION=//' | sed -r 's/\"|\(|\)//g' | awk '{print $2}') | 
|  | 463 | os_RELEASE=$(awk '/VERSION_ID=/' /etc/os-release | sed 's/VERSION_ID=//' | sed 's/\"//g') | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 464 | fi | 
|  | 465 | export os_VENDOR os_RELEASE os_UPDATE os_PACKAGE os_CODENAME | 
|  | 466 | } | 
|  | 467 |  | 
| Andrew Laski | f900bd7 | 2012-09-05 17:23:14 -0400 | [diff] [blame] | 468 |  | 
| Dean Troyer | a9e0a48 | 2012-07-09 14:07:23 -0500 | [diff] [blame] | 469 | # Translate the OS version values into common nomenclature | 
|  | 470 | # Sets ``DISTRO`` from the ``os_*`` values | 
|  | 471 | function GetDistro() { | 
|  | 472 | GetOSVersion | 
| Émilien Macchi | b2ef890 | 2013-05-04 00:48:20 +0200 | [diff] [blame] | 473 | if [[ "$os_VENDOR" =~ (Ubuntu) || "$os_VENDOR" =~ (Debian) ]]; then | 
|  | 474 | # 'Everyone' refers to Ubuntu / Debian releases by the code name adjective | 
| Dean Troyer | a9e0a48 | 2012-07-09 14:07:23 -0500 | [diff] [blame] | 475 | DISTRO=$os_CODENAME | 
|  | 476 | elif [[ "$os_VENDOR" =~ (Fedora) ]]; then | 
|  | 477 | # For Fedora, just use 'f' and the release | 
|  | 478 | DISTRO="f$os_RELEASE" | 
| Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 479 | elif [[ "$os_VENDOR" =~ (openSUSE) ]]; then | 
|  | 480 | DISTRO="opensuse-$os_RELEASE" | 
|  | 481 | elif [[ "$os_VENDOR" =~ (SUSE LINUX) ]]; then | 
|  | 482 | # For SLE, also use the service pack | 
|  | 483 | if [[ -z "$os_UPDATE" ]]; then | 
|  | 484 | DISTRO="sle${os_RELEASE}" | 
|  | 485 | else | 
|  | 486 | DISTRO="sle${os_RELEASE}sp${os_UPDATE}" | 
|  | 487 | fi | 
| Ian Wienand | d857f4b | 2013-03-20 14:51:06 +1100 | [diff] [blame] | 488 | elif [[ "$os_VENDOR" =~ (Red Hat) || "$os_VENDOR" =~ (CentOS) ]]; then | 
|  | 489 | # Drop the . release as we assume it's compatible | 
|  | 490 | DISTRO="rhel${os_RELEASE::1}" | 
| Bob Ball | 4669122 | 2013-08-12 17:28:50 +0100 | [diff] [blame] | 491 | elif [[ "$os_VENDOR" =~ (XenServer) ]]; then | 
|  | 492 | DISTRO="xs$os_RELEASE" | 
| Dean Troyer | a9e0a48 | 2012-07-09 14:07:23 -0500 | [diff] [blame] | 493 | else | 
|  | 494 | # Catch-all for now is Vendor + Release + Update | 
|  | 495 | DISTRO="$os_VENDOR-$os_RELEASE.$os_UPDATE" | 
|  | 496 | fi | 
|  | 497 | export DISTRO | 
|  | 498 | } | 
|  | 499 |  | 
|  | 500 |  | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 501 | # Determine if current distribution is a Fedora-based distribution | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 502 | # (Fedora, RHEL, CentOS, etc). | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 503 | # is_fedora | 
|  | 504 | function is_fedora { | 
|  | 505 | if [[ -z "$os_VENDOR" ]]; then | 
|  | 506 | GetOSVersion | 
|  | 507 | fi | 
|  | 508 |  | 
|  | 509 | [ "$os_VENDOR" = "Fedora" ] || [ "$os_VENDOR" = "Red Hat" ] || [ "$os_VENDOR" = "CentOS" ] | 
|  | 510 | } | 
|  | 511 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 512 |  | 
| Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 513 | # Determine if current distribution is a SUSE-based distribution | 
|  | 514 | # (openSUSE, SLE). | 
|  | 515 | # is_suse | 
|  | 516 | function is_suse { | 
|  | 517 | if [[ -z "$os_VENDOR" ]]; then | 
|  | 518 | GetOSVersion | 
|  | 519 | fi | 
|  | 520 |  | 
| Steve Baker | 1a7bbd2 | 2012-12-03 17:04:02 +1300 | [diff] [blame] | 521 | [ "$os_VENDOR" = "openSUSE" ] || [ "$os_VENDOR" = "SUSE LINUX" ] | 
| Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 522 | } | 
|  | 523 |  | 
|  | 524 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 525 | # Determine if current distribution is an Ubuntu-based distribution | 
|  | 526 | # It will also detect non-Ubuntu but Debian-based distros | 
|  | 527 | # is_ubuntu | 
|  | 528 | function is_ubuntu { | 
|  | 529 | if [[ -z "$os_PACKAGE" ]]; then | 
|  | 530 | GetOSVersion | 
|  | 531 | fi | 
|  | 532 | [ "$os_PACKAGE" = "deb" ] | 
|  | 533 | } | 
|  | 534 |  | 
|  | 535 |  | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 536 | # Exit after outputting a message about the distribution not being supported. | 
|  | 537 | # exit_distro_not_supported [optional-string-telling-what-is-missing] | 
|  | 538 | function exit_distro_not_supported { | 
|  | 539 | if [[ -z "$DISTRO" ]]; then | 
|  | 540 | GetDistro | 
|  | 541 | fi | 
|  | 542 |  | 
|  | 543 | if [ $# -gt 0 ]; then | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 544 | die $LINENO "Support for $DISTRO is incomplete: no support for $@" | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 545 | else | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 546 | die $LINENO "Support for $DISTRO is incomplete." | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 547 | fi | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 548 | } | 
|  | 549 |  | 
| Daniel Jones | fa868cb | 2013-06-18 15:28:01 -0500 | [diff] [blame] | 550 | # Utility function for checking machine architecture | 
|  | 551 | # is_arch arch-type | 
|  | 552 | function is_arch { | 
|  | 553 | ARCH_TYPE=$1 | 
|  | 554 |  | 
|  | 555 | [ "($uname -m)" = "$ARCH_TYPE" ] | 
|  | 556 | } | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 557 |  | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 558 | # git clone only if directory doesn't exist already.  Since ``DEST`` might not | 
|  | 559 | # be owned by the installation user, we create the directory and change the | 
|  | 560 | # ownership to the proper user. | 
|  | 561 | # Set global RECLONE=yes to simulate a clone when dest-dir exists | 
| James E. Blair | 94cb960 | 2012-06-22 15:28:29 -0700 | [diff] [blame] | 562 | # Set global ERROR_ON_CLONE=True to abort execution with an error if the git repo | 
|  | 563 | # does not exist (default is False, meaning the repo will be cloned). | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 564 | # Uses global ``OFFLINE`` | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 565 | # git_clone remote dest-dir branch | 
|  | 566 | function git_clone { | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 567 | GIT_REMOTE=$1 | 
|  | 568 | GIT_DEST=$2 | 
| Evgeniy Afonichev | 6a3912d | 2012-07-10 14:02:43 +0300 | [diff] [blame] | 569 | GIT_REF=$3 | 
| Sirushti Murugesan | a8d41e3 | 2013-09-25 11:30:31 +0530 | [diff] [blame] | 570 | RECLONE=$(trueorfalse False $RECLONE) | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 571 |  | 
| Sean Dague | 835db2f | 2013-09-23 14:17:06 -0400 | [diff] [blame] | 572 | if [[ "$OFFLINE" = "True" ]]; then | 
|  | 573 | echo "Running in offline mode, clones already exist" | 
|  | 574 | # print out the results so we know what change was used in the logs | 
|  | 575 | cd $GIT_DEST | 
| Sean Dague | 45a21f0 | 2013-09-25 10:27:27 -0400 | [diff] [blame] | 576 | git show --oneline | head -1 | 
| Sean Dague | 835db2f | 2013-09-23 14:17:06 -0400 | [diff] [blame] | 577 | return | 
|  | 578 | fi | 
|  | 579 |  | 
| Evgeniy Afonichev | 6a3912d | 2012-07-10 14:02:43 +0300 | [diff] [blame] | 580 | if echo $GIT_REF | egrep -q "^refs"; then | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 581 | # If our branch name is a gerrit style refs/changes/... | 
|  | 582 | if [[ ! -d $GIT_DEST ]]; then | 
| James E. Blair | 94cb960 | 2012-06-22 15:28:29 -0700 | [diff] [blame] | 583 | [[ "$ERROR_ON_CLONE" = "True" ]] && exit 1 | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 584 | git clone $GIT_REMOTE $GIT_DEST | 
|  | 585 | fi | 
|  | 586 | cd $GIT_DEST | 
| Evgeniy Afonichev | 6a3912d | 2012-07-10 14:02:43 +0300 | [diff] [blame] | 587 | git fetch $GIT_REMOTE $GIT_REF && git checkout FETCH_HEAD | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 588 | else | 
|  | 589 | # do a full clone only if the directory doesn't exist | 
|  | 590 | if [[ ! -d $GIT_DEST ]]; then | 
| James E. Blair | 94cb960 | 2012-06-22 15:28:29 -0700 | [diff] [blame] | 591 | [[ "$ERROR_ON_CLONE" = "True" ]] && exit 1 | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 592 | git clone $GIT_REMOTE $GIT_DEST | 
|  | 593 | cd $GIT_DEST | 
|  | 594 | # This checkout syntax works for both branches and tags | 
| Evgeniy Afonichev | 6a3912d | 2012-07-10 14:02:43 +0300 | [diff] [blame] | 595 | git checkout $GIT_REF | 
| Sirushti Murugesan | a8d41e3 | 2013-09-25 11:30:31 +0530 | [diff] [blame] | 596 | elif [[ "$RECLONE" = "True" ]]; then | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 597 | # if it does exist then simulate what clone does if asked to RECLONE | 
|  | 598 | cd $GIT_DEST | 
|  | 599 | # set the url to pull from and fetch | 
|  | 600 | git remote set-url origin $GIT_REMOTE | 
|  | 601 | git fetch origin | 
|  | 602 | # remove the existing ignored files (like pyc) as they cause breakage | 
|  | 603 | # (due to the py files having older timestamps than our pyc, so python | 
|  | 604 | # thinks the pyc files are correct using them) | 
|  | 605 | find $GIT_DEST -name '*.pyc' -delete | 
| Evgeniy Afonichev | 6a3912d | 2012-07-10 14:02:43 +0300 | [diff] [blame] | 606 |  | 
|  | 607 | # handle GIT_REF accordingly to type (tag, branch) | 
|  | 608 | if [[ -n "`git show-ref refs/tags/$GIT_REF`" ]]; then | 
|  | 609 | git_update_tag $GIT_REF | 
|  | 610 | elif [[ -n "`git show-ref refs/heads/$GIT_REF`" ]]; then | 
|  | 611 | git_update_branch $GIT_REF | 
| Andrew Laski | f900bd7 | 2012-09-05 17:23:14 -0400 | [diff] [blame] | 612 | elif [[ -n "`git show-ref refs/remotes/origin/$GIT_REF`" ]]; then | 
|  | 613 | git_update_remote_branch $GIT_REF | 
| Evgeniy Afonichev | 6a3912d | 2012-07-10 14:02:43 +0300 | [diff] [blame] | 614 | else | 
|  | 615 | echo $GIT_REF is neither branch nor tag | 
|  | 616 | exit 1 | 
|  | 617 | fi | 
|  | 618 |  | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 619 | fi | 
|  | 620 | fi | 
| Sean Dague | 835db2f | 2013-09-23 14:17:06 -0400 | [diff] [blame] | 621 |  | 
|  | 622 | # print out the results so we know what change was used in the logs | 
|  | 623 | cd $GIT_DEST | 
| Sean Dague | 45a21f0 | 2013-09-25 10:27:27 -0400 | [diff] [blame] | 624 | git show --oneline | head -1 | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 625 | } | 
|  | 626 |  | 
|  | 627 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 628 | # git update using reference as a branch. | 
|  | 629 | # git_update_branch ref | 
|  | 630 | function git_update_branch() { | 
|  | 631 |  | 
|  | 632 | GIT_BRANCH=$1 | 
|  | 633 |  | 
|  | 634 | git checkout -f origin/$GIT_BRANCH | 
|  | 635 | # a local branch might not exist | 
|  | 636 | git branch -D $GIT_BRANCH || true | 
|  | 637 | git checkout -b $GIT_BRANCH | 
|  | 638 | } | 
|  | 639 |  | 
|  | 640 |  | 
|  | 641 | # git update using reference as a branch. | 
|  | 642 | # git_update_remote_branch ref | 
|  | 643 | function git_update_remote_branch() { | 
|  | 644 |  | 
|  | 645 | GIT_BRANCH=$1 | 
|  | 646 |  | 
|  | 647 | git checkout -b $GIT_BRANCH -t origin/$GIT_BRANCH | 
|  | 648 | } | 
|  | 649 |  | 
|  | 650 |  | 
|  | 651 | # git update using reference as a tag. Be careful editing source at that repo | 
|  | 652 | # as working copy will be in a detached mode | 
|  | 653 | # git_update_tag ref | 
|  | 654 | function git_update_tag() { | 
|  | 655 |  | 
|  | 656 | GIT_TAG=$1 | 
|  | 657 |  | 
|  | 658 | git tag -d $GIT_TAG | 
|  | 659 | # fetching given tag only | 
|  | 660 | git fetch origin tag $GIT_TAG | 
|  | 661 | git checkout -f $GIT_TAG | 
|  | 662 | } | 
|  | 663 |  | 
|  | 664 |  | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 665 | # Comment an option in an INI file | 
| Chmouel Boudjnah | c7214e8 | 2012-06-06 13:56:39 +0200 | [diff] [blame] | 666 | # inicomment config-file section option | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 667 | function inicomment() { | 
|  | 668 | local file=$1 | 
|  | 669 | local section=$2 | 
|  | 670 | local option=$3 | 
| Attila Fazekas | 588eb41 | 2012-12-20 10:57:16 +0100 | [diff] [blame] | 671 | sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=.*$\)|#\1|" "$file" | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 672 | } | 
|  | 673 |  | 
| Dean Troyer | 896eb66 | 2013-04-05 15:02:01 -0500 | [diff] [blame] | 674 |  | 
| Chmouel Boudjnah | c7214e8 | 2012-06-06 13:56:39 +0200 | [diff] [blame] | 675 | # Uncomment an option in an INI file | 
|  | 676 | # iniuncomment config-file section option | 
|  | 677 | function iniuncomment() { | 
|  | 678 | local file=$1 | 
|  | 679 | local section=$2 | 
|  | 680 | local option=$3 | 
| Attila Fazekas | 588eb41 | 2012-12-20 10:57:16 +0100 | [diff] [blame] | 681 | sed -i -e "/^\[$section\]/,/^\[.*\]/ s|[^ \t]*#[ \t]*\($option[ \t]*=.*$\)|\1|" "$file" | 
| Chmouel Boudjnah | c7214e8 | 2012-06-06 13:56:39 +0200 | [diff] [blame] | 682 | } | 
|  | 683 |  | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 684 |  | 
|  | 685 | # Get an option from an INI file | 
| Dean Troyer | 09e636e | 2012-03-19 16:31:12 -0500 | [diff] [blame] | 686 | # iniget config-file section option | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 687 | function iniget() { | 
|  | 688 | local file=$1 | 
|  | 689 | local section=$2 | 
|  | 690 | local option=$3 | 
|  | 691 | local line | 
| Attila Fazekas | 588eb41 | 2012-12-20 10:57:16 +0100 | [diff] [blame] | 692 | line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file") | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 693 | echo ${line#*=} | 
|  | 694 | } | 
|  | 695 |  | 
| Dean Troyer | 896eb66 | 2013-04-05 15:02:01 -0500 | [diff] [blame] | 696 |  | 
| Attila Fazekas | 588eb41 | 2012-12-20 10:57:16 +0100 | [diff] [blame] | 697 | # Determinate is the given option present in the INI file | 
|  | 698 | # ini_has_option config-file section option | 
|  | 699 | function ini_has_option() { | 
|  | 700 | local file=$1 | 
|  | 701 | local section=$2 | 
|  | 702 | local option=$3 | 
|  | 703 | local line | 
|  | 704 | line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file") | 
|  | 705 | [ -n "$line" ] | 
|  | 706 | } | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 707 |  | 
| Dean Troyer | 896eb66 | 2013-04-05 15:02:01 -0500 | [diff] [blame] | 708 |  | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 709 | # Set an option in an INI file | 
| Dean Troyer | 09e636e | 2012-03-19 16:31:12 -0500 | [diff] [blame] | 710 | # iniset config-file section option value | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 711 | function iniset() { | 
|  | 712 | local file=$1 | 
|  | 713 | local section=$2 | 
|  | 714 | local option=$3 | 
|  | 715 | local value=$4 | 
| Attila Fazekas | 588eb41 | 2012-12-20 10:57:16 +0100 | [diff] [blame] | 716 | if ! grep -q "^\[$section\]" "$file"; then | 
| Dean Troyer | 09e636e | 2012-03-19 16:31:12 -0500 | [diff] [blame] | 717 | # Add section at the end | 
| Attila Fazekas | 588eb41 | 2012-12-20 10:57:16 +0100 | [diff] [blame] | 718 | echo -e "\n[$section]" >>"$file" | 
| Dean Troyer | 09e636e | 2012-03-19 16:31:12 -0500 | [diff] [blame] | 719 | fi | 
| Attila Fazekas | 588eb41 | 2012-12-20 10:57:16 +0100 | [diff] [blame] | 720 | if ! ini_has_option "$file" "$section" "$option"; then | 
| Dean Troyer | 09e636e | 2012-03-19 16:31:12 -0500 | [diff] [blame] | 721 | # Add it | 
| Attila Fazekas | 588eb41 | 2012-12-20 10:57:16 +0100 | [diff] [blame] | 722 | sed -i -e "/^\[$section\]/ a\\ | 
| Dean Troyer | 09e636e | 2012-03-19 16:31:12 -0500 | [diff] [blame] | 723 | $option = $value | 
| Attila Fazekas | 588eb41 | 2012-12-20 10:57:16 +0100 | [diff] [blame] | 724 | " "$file" | 
| Dean Troyer | 09e636e | 2012-03-19 16:31:12 -0500 | [diff] [blame] | 725 | else | 
|  | 726 | # Replace it | 
| Attila Fazekas | 588eb41 | 2012-12-20 10:57:16 +0100 | [diff] [blame] | 727 | sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=[ \t]*\).*$|\1$value|" "$file" | 
| Dean Troyer | 09e636e | 2012-03-19 16:31:12 -0500 | [diff] [blame] | 728 | fi | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 729 | } | 
|  | 730 |  | 
| Dean Troyer | 896eb66 | 2013-04-05 15:02:01 -0500 | [diff] [blame] | 731 |  | 
| Lianhao Lu | 239f324 | 2013-03-01 15:54:02 +0800 | [diff] [blame] | 732 | # Get a multiple line option from an INI file | 
|  | 733 | # iniget_multiline config-file section option | 
|  | 734 | function iniget_multiline() { | 
|  | 735 | local file=$1 | 
|  | 736 | local section=$2 | 
|  | 737 | local option=$3 | 
|  | 738 | local values | 
|  | 739 | values=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { s/^$option[ \t]*=[ \t]*//gp; }" "$file") | 
|  | 740 | echo ${values} | 
|  | 741 | } | 
|  | 742 |  | 
| Dean Troyer | 896eb66 | 2013-04-05 15:02:01 -0500 | [diff] [blame] | 743 |  | 
| Lianhao Lu | 239f324 | 2013-03-01 15:54:02 +0800 | [diff] [blame] | 744 | # Set a multiple line option in an INI file | 
|  | 745 | # iniset_multiline config-file section option value1 value2 valu3 ... | 
|  | 746 | function iniset_multiline() { | 
|  | 747 | local file=$1 | 
|  | 748 | local section=$2 | 
|  | 749 | local option=$3 | 
|  | 750 | shift 3 | 
|  | 751 | local values | 
|  | 752 | for v in $@; do | 
|  | 753 | # The later sed command inserts each new value in the line next to | 
|  | 754 | # the section identifier, which causes the values to be inserted in | 
|  | 755 | # the reverse order. Do a reverse here to keep the original order. | 
|  | 756 | values="$v ${values}" | 
|  | 757 | done | 
|  | 758 | if ! grep -q "^\[$section\]" "$file"; then | 
|  | 759 | # Add section at the end | 
|  | 760 | echo -e "\n[$section]" >>"$file" | 
|  | 761 | else | 
|  | 762 | # Remove old values | 
|  | 763 | sed -i -e "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ d; }" "$file" | 
|  | 764 | fi | 
|  | 765 | # Add new ones | 
|  | 766 | for v in $values; do | 
|  | 767 | sed -i -e "/^\[$section\]/ a\\ | 
|  | 768 | $option = $v | 
|  | 769 | " "$file" | 
|  | 770 | done | 
|  | 771 | } | 
|  | 772 |  | 
| Dean Troyer | 896eb66 | 2013-04-05 15:02:01 -0500 | [diff] [blame] | 773 |  | 
| Lianhao Lu | 239f324 | 2013-03-01 15:54:02 +0800 | [diff] [blame] | 774 | # Append a new option in an ini file without replacing the old value | 
|  | 775 | # iniadd config-file section option value1 value2 value3 ... | 
|  | 776 | function iniadd() { | 
|  | 777 | local file=$1 | 
|  | 778 | local section=$2 | 
|  | 779 | local option=$3 | 
|  | 780 | shift 3 | 
|  | 781 | local values="$(iniget_multiline $file $section $option) $@" | 
|  | 782 | iniset_multiline $file $section $option $values | 
|  | 783 | } | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 784 |  | 
| Dean Troyer | 896eb66 | 2013-04-05 15:02:01 -0500 | [diff] [blame] | 785 | # Find out if a process exists by partial name. | 
|  | 786 | # is_running name | 
|  | 787 | function is_running() { | 
|  | 788 | local name=$1 | 
|  | 789 | ps auxw | grep -v grep | grep ${name} > /dev/null | 
|  | 790 | RC=$? | 
|  | 791 | # some times I really hate bash reverse binary logic | 
|  | 792 | return $RC | 
|  | 793 | } | 
|  | 794 |  | 
|  | 795 |  | 
| Chmouel Boudjnah | 408b009 | 2012-03-15 23:21:55 +0000 | [diff] [blame] | 796 | # is_service_enabled() checks if the service(s) specified as arguments are | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 797 | # enabled by the user in ``ENABLED_SERVICES``. | 
| Chmouel Boudjnah | 408b009 | 2012-03-15 23:21:55 +0000 | [diff] [blame] | 798 | # | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 799 | # Multiple services specified as arguments are ``OR``'ed together; the test | 
|  | 800 | # is a short-circuit boolean, i.e it returns on the first match. | 
| Chmouel Boudjnah | 408b009 | 2012-03-15 23:21:55 +0000 | [diff] [blame] | 801 | # | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 802 | # There are special cases for some 'catch-all' services:: | 
| Chmouel Boudjnah | 408b009 | 2012-03-15 23:21:55 +0000 | [diff] [blame] | 803 | #   **nova** returns true if any service enabled start with **n-** | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 804 | #   **cinder** returns true if any service enabled start with **c-** | 
|  | 805 | #   **ceilometer** returns true if any service enabled start with **ceilometer** | 
| Chmouel Boudjnah | 408b009 | 2012-03-15 23:21:55 +0000 | [diff] [blame] | 806 | #   **glance** returns true if any service enabled start with **g-** | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 807 | #   **neutron** returns true if any service enabled start with **q-** | 
| Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 808 | #   **swift** returns true if any service enabled start with **s-** | 
| Nikhil Manchanda | 0cccad4 | 2012-12-03 18:15:09 -0700 | [diff] [blame] | 809 | #   **trove** returns true if any service enabled start with **tr-** | 
| Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 810 | #   For backward compatibility if we have **swift** in ENABLED_SERVICES all the | 
|  | 811 | #   **s-** services will be enabled. This will be deprecated in the future. | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 812 | # | 
| Chris Behrens | c62c2b9 | 2013-07-24 03:56:13 -0700 | [diff] [blame] | 813 | # Cells within nova is enabled if **n-cell** is in ``ENABLED_SERVICES``. | 
|  | 814 | # We also need to make sure to treat **n-cell-region** and **n-cell-child** | 
|  | 815 | # as enabled in this case. | 
|  | 816 | # | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 817 | # Uses global ``ENABLED_SERVICES`` | 
|  | 818 | # is_service_enabled service [service ...] | 
| Chmouel Boudjnah | 408b009 | 2012-03-15 23:21:55 +0000 | [diff] [blame] | 819 | function is_service_enabled() { | 
|  | 820 | services=$@ | 
|  | 821 | for service in ${services}; do | 
|  | 822 | [[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && return 0 | 
| Chris Behrens | c62c2b9 | 2013-07-24 03:56:13 -0700 | [diff] [blame] | 823 | [[ ${service} == n-cell-* && ${ENABLED_SERVICES} =~ "n-cell" ]] && return 0 | 
| Chmouel Boudjnah | 408b009 | 2012-03-15 23:21:55 +0000 | [diff] [blame] | 824 | [[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && return 0 | 
| Dean Troyer | 67787e6 | 2012-05-02 11:48:15 -0500 | [diff] [blame] | 825 | [[ ${service} == "cinder" && ${ENABLED_SERVICES} =~ "c-" ]] && return 0 | 
| John H. Tran | 9336164 | 2012-07-26 11:22:05 -0700 | [diff] [blame] | 826 | [[ ${service} == "ceilometer" && ${ENABLED_SERVICES} =~ "ceilometer-" ]] && return 0 | 
| Chmouel Boudjnah | 408b009 | 2012-03-15 23:21:55 +0000 | [diff] [blame] | 827 | [[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && return 0 | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 828 | [[ ${service} == "neutron" && ${ENABLED_SERVICES} =~ "q-" ]] && return 0 | 
| Nikhil Manchanda | 0cccad4 | 2012-12-03 18:15:09 -0700 | [diff] [blame] | 829 | [[ ${service} == "trove" && ${ENABLED_SERVICES} =~ "tr-" ]] && return 0 | 
| Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 830 | [[ ${service} == "swift" && ${ENABLED_SERVICES} =~ "s-" ]] && return 0 | 
|  | 831 | [[ ${service} == s-* && ${ENABLED_SERVICES} =~ "swift" ]] && return 0 | 
| Chmouel Boudjnah | 408b009 | 2012-03-15 23:21:55 +0000 | [diff] [blame] | 832 | done | 
|  | 833 | return 1 | 
|  | 834 | } | 
|  | 835 |  | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 836 |  | 
|  | 837 | # remove extra commas from the input string (i.e. ``ENABLED_SERVICES``) | 
|  | 838 | # _cleanup_service_list service-list | 
| Doug Hellmann | f04178f | 2012-07-05 17:10:03 -0400 | [diff] [blame] | 839 | function _cleanup_service_list () { | 
| Dean Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 840 | echo "$1" | sed -e ' | 
| Doug Hellmann | f04178f | 2012-07-05 17:10:03 -0400 | [diff] [blame] | 841 | s/,,/,/g; | 
|  | 842 | s/^,//; | 
|  | 843 | s/,$// | 
|  | 844 | ' | 
|  | 845 | } | 
|  | 846 |  | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 847 |  | 
| Doug Hellmann | f04178f | 2012-07-05 17:10:03 -0400 | [diff] [blame] | 848 | # enable_service() adds the services passed as argument to the | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 849 | # ``ENABLED_SERVICES`` list, if they are not already present. | 
| Doug Hellmann | f04178f | 2012-07-05 17:10:03 -0400 | [diff] [blame] | 850 | # | 
|  | 851 | # For example: | 
| Joe Gordon | 6fd2811 | 2012-11-13 16:55:41 -0800 | [diff] [blame] | 852 | #   enable_service qpid | 
| Doug Hellmann | f04178f | 2012-07-05 17:10:03 -0400 | [diff] [blame] | 853 | # | 
|  | 854 | # This function does not know about the special cases | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 855 | # for nova, glance, and neutron built into is_service_enabled(). | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 856 | # Uses global ``ENABLED_SERVICES`` | 
|  | 857 | # enable_service service [service ...] | 
| Doug Hellmann | f04178f | 2012-07-05 17:10:03 -0400 | [diff] [blame] | 858 | function enable_service() { | 
|  | 859 | local tmpsvcs="${ENABLED_SERVICES}" | 
|  | 860 | for service in $@; do | 
|  | 861 | if ! is_service_enabled $service; then | 
|  | 862 | tmpsvcs+=",$service" | 
|  | 863 | fi | 
|  | 864 | done | 
|  | 865 | ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs") | 
|  | 866 | disable_negated_services | 
|  | 867 | } | 
|  | 868 |  | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 869 |  | 
| Doug Hellmann | f04178f | 2012-07-05 17:10:03 -0400 | [diff] [blame] | 870 | # disable_service() removes the services passed as argument to the | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 871 | # ``ENABLED_SERVICES`` list, if they are present. | 
| Doug Hellmann | f04178f | 2012-07-05 17:10:03 -0400 | [diff] [blame] | 872 | # | 
|  | 873 | # For example: | 
| Joe Gordon | 6fd2811 | 2012-11-13 16:55:41 -0800 | [diff] [blame] | 874 | #   disable_service rabbit | 
| Doug Hellmann | f04178f | 2012-07-05 17:10:03 -0400 | [diff] [blame] | 875 | # | 
|  | 876 | # This function does not know about the special cases | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 877 | # for nova, glance, and neutron built into is_service_enabled(). | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 878 | # Uses global ``ENABLED_SERVICES`` | 
|  | 879 | # disable_service service [service ...] | 
| Doug Hellmann | f04178f | 2012-07-05 17:10:03 -0400 | [diff] [blame] | 880 | function disable_service() { | 
|  | 881 | local tmpsvcs=",${ENABLED_SERVICES}," | 
|  | 882 | local service | 
|  | 883 | for service in $@; do | 
|  | 884 | if is_service_enabled $service; then | 
|  | 885 | tmpsvcs=${tmpsvcs//,$service,/,} | 
|  | 886 | fi | 
|  | 887 | done | 
|  | 888 | ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs") | 
|  | 889 | } | 
|  | 890 |  | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 891 |  | 
| Doug Hellmann | f04178f | 2012-07-05 17:10:03 -0400 | [diff] [blame] | 892 | # disable_all_services() removes all current services | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 893 | # from ``ENABLED_SERVICES`` to reset the configuration | 
| Doug Hellmann | f04178f | 2012-07-05 17:10:03 -0400 | [diff] [blame] | 894 | # before a minimal installation | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 895 | # Uses global ``ENABLED_SERVICES`` | 
|  | 896 | # disable_all_services | 
| Doug Hellmann | f04178f | 2012-07-05 17:10:03 -0400 | [diff] [blame] | 897 | function disable_all_services() { | 
|  | 898 | ENABLED_SERVICES="" | 
|  | 899 | } | 
|  | 900 |  | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 901 |  | 
|  | 902 | # Remove all services starting with '-'.  For example, to install all default | 
| Joe Gordon | 6fd2811 | 2012-11-13 16:55:41 -0800 | [diff] [blame] | 903 | # services except rabbit (rabbit) set in ``localrc``: | 
|  | 904 | # ENABLED_SERVICES+=",-rabbit" | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 905 | # Uses global ``ENABLED_SERVICES`` | 
|  | 906 | # disable_negated_services | 
| Doug Hellmann | f04178f | 2012-07-05 17:10:03 -0400 | [diff] [blame] | 907 | function disable_negated_services() { | 
|  | 908 | local tmpsvcs="${ENABLED_SERVICES}" | 
|  | 909 | local service | 
|  | 910 | for service in ${tmpsvcs//,/ }; do | 
|  | 911 | if [[ ${service} == -* ]]; then | 
|  | 912 | tmpsvcs=$(echo ${tmpsvcs}|sed -r "s/(,)?(-)?${service#-}(,)?/,/g") | 
|  | 913 | fi | 
|  | 914 | done | 
|  | 915 | ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs") | 
|  | 916 | } | 
| Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 917 |  | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 918 |  | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 919 | # Distro-agnostic package installer | 
|  | 920 | # install_package package [package ...] | 
|  | 921 | function install_package() { | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 922 | if is_ubuntu; then | 
| Vincent Untz | c0482e6 | 2012-06-12 11:30:43 +0200 | [diff] [blame] | 923 | [[ "$NO_UPDATE_REPOS" = "True" ]] || apt_get update | 
|  | 924 | NO_UPDATE_REPOS=True | 
|  | 925 |  | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 926 | apt_get install "$@" | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 927 | elif is_fedora; then | 
|  | 928 | yum_install "$@" | 
|  | 929 | elif is_suse; then | 
|  | 930 | zypper_install "$@" | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 931 | else | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 932 | exit_distro_not_supported "installing packages" | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 933 | fi | 
|  | 934 | } | 
|  | 935 |  | 
|  | 936 |  | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 937 | # Distro-agnostic package uninstaller | 
|  | 938 | # uninstall_package package [package ...] | 
|  | 939 | function uninstall_package() { | 
|  | 940 | if is_ubuntu; then | 
|  | 941 | apt_get purge "$@" | 
|  | 942 | elif is_fedora; then | 
| Ian Wienand | 2c678cc | 2013-03-20 13:00:44 +1100 | [diff] [blame] | 943 | sudo yum remove -y "$@" | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 944 | elif is_suse; then | 
| Adam Spiers | 6d8fce7 | 2013-10-01 15:59:05 +0100 | [diff] [blame] | 945 | sudo zypper rm "$@" | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 946 | else | 
|  | 947 | exit_distro_not_supported "uninstalling packages" | 
|  | 948 | fi | 
|  | 949 | } | 
|  | 950 |  | 
|  | 951 |  | 
| Vincent Untz | 71ebc6f | 2012-06-12 13:45:15 +0200 | [diff] [blame] | 952 | # Distro-agnostic function to tell if a package is installed | 
|  | 953 | # is_package_installed package [package ...] | 
|  | 954 | function is_package_installed() { | 
|  | 955 | if [[ -z "$@" ]]; then | 
|  | 956 | return 1 | 
|  | 957 | fi | 
|  | 958 |  | 
|  | 959 | if [[ -z "$os_PACKAGE" ]]; then | 
|  | 960 | GetOSVersion | 
|  | 961 | fi | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 962 |  | 
| Vincent Untz | 71ebc6f | 2012-06-12 13:45:15 +0200 | [diff] [blame] | 963 | if [[ "$os_PACKAGE" = "deb" ]]; then | 
| Dean Troyer | 04762cd | 2013-08-27 17:06:14 -0500 | [diff] [blame] | 964 | dpkg -s "$@" > /dev/null 2> /dev/null | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 965 | elif [[ "$os_PACKAGE" = "rpm" ]]; then | 
| Vincent Untz | 71ebc6f | 2012-06-12 13:45:15 +0200 | [diff] [blame] | 966 | rpm --quiet -q "$@" | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 967 | else | 
|  | 968 | exit_distro_not_supported "finding if a package is installed" | 
| Vincent Untz | 71ebc6f | 2012-06-12 13:45:15 +0200 | [diff] [blame] | 969 | fi | 
|  | 970 | } | 
|  | 971 |  | 
|  | 972 |  | 
| Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 973 | # Test if the named environment variable is set and not zero length | 
|  | 974 | # is_set env-var | 
|  | 975 | function is_set() { | 
|  | 976 | local var=\$"$1" | 
| Attila Fazekas | 251d3b5 | 2012-12-16 15:05:44 +0100 | [diff] [blame] | 977 | eval "[ -n \"$var\" ]" # For ex.: sh -c "[ -n \"$var\" ]" would be better, but several exercises depends on this | 
| Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 978 | } | 
|  | 979 |  | 
|  | 980 |  | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 981 | # Wrapper for ``pip install`` to set cache and proxy environment variables | 
| Maru Newby | 3a87edd | 2012-10-25 23:01:06 +0000 | [diff] [blame] | 982 | # Uses globals ``OFFLINE``, ``PIP_DOWNLOAD_CACHE``, ``PIP_USE_MIRRORS``, | 
|  | 983 | #   ``TRACK_DEPENDS``, ``*_proxy` | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 984 | # pip_install package [package ...] | 
|  | 985 | function pip_install { | 
| Dean Troyer | d0b21e2 | 2012-03-07 14:52:25 -0600 | [diff] [blame] | 986 | [[ "$OFFLINE" = "True" || -z "$@" ]] && return | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 987 | if [[ -z "$os_PACKAGE" ]]; then | 
|  | 988 | GetOSVersion | 
|  | 989 | fi | 
| Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 990 | if [[ $TRACK_DEPENDS = True ]]; then | 
| Monty Taylor | 47f0206 | 2012-07-26 11:09:24 -0500 | [diff] [blame] | 991 | source $DEST/.venv/bin/activate | 
|  | 992 | CMD_PIP=$DEST/.venv/bin/pip | 
|  | 993 | SUDO_PIP="env" | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 994 | else | 
| Monty Taylor | 47f0206 | 2012-07-26 11:09:24 -0500 | [diff] [blame] | 995 | SUDO_PIP="sudo" | 
| Vincent Untz | 8ec2722 | 2012-11-29 09:25:31 +0100 | [diff] [blame] | 996 | CMD_PIP=$(get_pip_command) | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 997 | fi | 
| Ian Wienand | d67dd87 | 2013-04-11 11:14:36 +1000 | [diff] [blame] | 998 |  | 
| Roman Gorodeckij | 99405a4 | 2013-08-07 09:20:36 -0400 | [diff] [blame] | 999 | # Mirror option not needed anymore because pypi has CDN available, | 
|  | 1000 | # but it's useful in certain circumstances | 
|  | 1001 | PIP_USE_MIRRORS=${PIP_USE_MIRRORS:-False} | 
| Maru Newby | 3a87edd | 2012-10-25 23:01:06 +0000 | [diff] [blame] | 1002 | if [[ "$PIP_USE_MIRRORS" != "False" ]]; then | 
|  | 1003 | PIP_MIRROR_OPT="--use-mirrors" | 
|  | 1004 | fi | 
| Ian Wienand | d67dd87 | 2013-04-11 11:14:36 +1000 | [diff] [blame] | 1005 |  | 
| Ian Wienand | 31dcd3e | 2013-07-16 13:36:34 +1000 | [diff] [blame] | 1006 | # pip < 1.4 has a bug where it will use an already existing build | 
|  | 1007 | # directory unconditionally.  Say an earlier component installs | 
|  | 1008 | # foo v1.1; pip will have built foo's source in | 
|  | 1009 | # /tmp/$USER-pip-build.  Even if a later component specifies foo < | 
|  | 1010 | # 1.1, the existing extracted build will be used and cause | 
|  | 1011 | # confusing errors.  By creating unique build directories we avoid | 
|  | 1012 | # this problem. See | 
|  | 1013 | #  https://github.com/pypa/pip/issues/709 | 
|  | 1014 | local pip_build_tmp=$(mktemp --tmpdir -d pip-build.XXXXX) | 
|  | 1015 |  | 
| Monty Taylor | 47f0206 | 2012-07-26 11:09:24 -0500 | [diff] [blame] | 1016 | $SUDO_PIP PIP_DOWNLOAD_CACHE=${PIP_DOWNLOAD_CACHE:-/var/cache/pip} \ | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 1017 | HTTP_PROXY=$http_proxy \ | 
|  | 1018 | HTTPS_PROXY=$https_proxy \ | 
| Osamu Habuka | 7abe4f2 | 2012-07-25 12:39:32 +0900 | [diff] [blame] | 1019 | NO_PROXY=$no_proxy \ | 
| Ian Wienand | 31dcd3e | 2013-07-16 13:36:34 +1000 | [diff] [blame] | 1020 | $CMD_PIP install --build=${pip_build_tmp} \ | 
|  | 1021 | $PIP_MIRROR_OPT $@ \ | 
|  | 1022 | && $SUDO_PIP rm -rf ${pip_build_tmp} | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 1023 | } | 
|  | 1024 |  | 
|  | 1025 |  | 
| Ian Wienand | 31dcd3e | 2013-07-16 13:36:34 +1000 | [diff] [blame] | 1026 | # Cleanup anything from /tmp on unstack | 
|  | 1027 | # clean_tmp | 
|  | 1028 | function cleanup_tmp { | 
|  | 1029 | local tmp_dir=${TMPDIR:-/tmp} | 
|  | 1030 |  | 
|  | 1031 | # see comments in pip_install | 
|  | 1032 | sudo rm -rf ${tmp_dir}/pip-build.* | 
|  | 1033 | } | 
|  | 1034 |  | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 1035 | # Service wrapper to restart services | 
|  | 1036 | # restart_service service-name | 
|  | 1037 | function restart_service() { | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 1038 | if is_ubuntu; then | 
| Dean Troyer | 5218d45 | 2012-02-04 02:13:23 -0600 | [diff] [blame] | 1039 | sudo /usr/sbin/service $1 restart | 
|  | 1040 | else | 
|  | 1041 | sudo /sbin/service $1 restart | 
|  | 1042 | fi | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 1043 | } | 
|  | 1044 |  | 
|  | 1045 |  | 
| Dean Troyer | 681f3fd | 2013-02-27 19:00:39 -0600 | [diff] [blame] | 1046 | # _run_process() is designed to be backgrounded by run_process() to simulate a | 
|  | 1047 | # fork.  It includes the dirty work of closing extra filehandles and preparing log | 
|  | 1048 | # files to produce the same logs as screen_it().  The log filename is derived | 
|  | 1049 | # from the service name and global-and-now-misnamed SCREEN_LOGDIR | 
|  | 1050 | # _run_process service "command-line" | 
|  | 1051 | function _run_process() { | 
|  | 1052 | local service=$1 | 
|  | 1053 | local command="$2" | 
|  | 1054 |  | 
|  | 1055 | # Undo logging redirections and close the extra descriptors | 
|  | 1056 | exec 1>&3 | 
|  | 1057 | exec 2>&3 | 
|  | 1058 | exec 3>&- | 
|  | 1059 | exec 6>&- | 
|  | 1060 |  | 
|  | 1061 | if [[ -n ${SCREEN_LOGDIR} ]]; then | 
|  | 1062 | exec 1>&${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log 2>&1 | 
|  | 1063 | ln -sf ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log ${SCREEN_LOGDIR}/screen-${1}.log | 
|  | 1064 |  | 
|  | 1065 | # TODO(dtroyer): Hack to get stdout from the Python interpreter for the logs. | 
|  | 1066 | export PYTHONUNBUFFERED=1 | 
|  | 1067 | fi | 
|  | 1068 |  | 
|  | 1069 | exec /bin/bash -c "$command" | 
|  | 1070 | die "$service exec failure: $command" | 
|  | 1071 | } | 
|  | 1072 |  | 
|  | 1073 |  | 
|  | 1074 | # run_process() launches a child process that closes all file descriptors and | 
|  | 1075 | # then exec's the passed in command.  This is meant to duplicate the semantics | 
|  | 1076 | # of screen_it() without screen.  PIDs are written to | 
|  | 1077 | # $SERVICE_DIR/$SCREEN_NAME/$service.pid | 
|  | 1078 | # run_process service "command-line" | 
|  | 1079 | function run_process() { | 
|  | 1080 | local service=$1 | 
|  | 1081 | local command="$2" | 
|  | 1082 |  | 
|  | 1083 | # Spawn the child process | 
|  | 1084 | _run_process "$service" "$command" & | 
|  | 1085 | echo $! | 
|  | 1086 | } | 
|  | 1087 |  | 
|  | 1088 |  | 
| Dean Troyer | 1573335 | 2012-09-06 11:51:30 -0500 | [diff] [blame] | 1089 | # Helper to launch a service in a named screen | 
|  | 1090 | # screen_it service "command-line" | 
|  | 1091 | function screen_it { | 
| Dean Troyer | 1573335 | 2012-09-06 11:51:30 -0500 | [diff] [blame] | 1092 | SCREEN_NAME=${SCREEN_NAME:-stack} | 
| jiajun xu | a941424 | 2012-12-06 16:30:57 +0800 | [diff] [blame] | 1093 | SERVICE_DIR=${SERVICE_DIR:-${DEST}/status} | 
| Dean Troyer | 681f3fd | 2013-02-27 19:00:39 -0600 | [diff] [blame] | 1094 | USE_SCREEN=$(trueorfalse True $USE_SCREEN) | 
| jiajun xu | a941424 | 2012-12-06 16:30:57 +0800 | [diff] [blame] | 1095 |  | 
| Dean Troyer | 1573335 | 2012-09-06 11:51:30 -0500 | [diff] [blame] | 1096 | if is_service_enabled $1; then | 
|  | 1097 | # Append the service to the screen rc file | 
|  | 1098 | screen_rc "$1" "$2" | 
|  | 1099 |  | 
| Dean Troyer | 681f3fd | 2013-02-27 19:00:39 -0600 | [diff] [blame] | 1100 | if [[ "$USE_SCREEN" = "True" ]]; then | 
|  | 1101 | screen -S $SCREEN_NAME -X screen -t $1 | 
| Jeremy Stanley | 25ebbcd | 2013-02-17 15:45:55 +0000 | [diff] [blame] | 1102 |  | 
| Dean Troyer | 681f3fd | 2013-02-27 19:00:39 -0600 | [diff] [blame] | 1103 | if [[ -n ${SCREEN_LOGDIR} ]]; then | 
|  | 1104 | screen -S $SCREEN_NAME -p $1 -X logfile ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log | 
|  | 1105 | screen -S $SCREEN_NAME -p $1 -X log on | 
|  | 1106 | ln -sf ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log ${SCREEN_LOGDIR}/screen-${1}.log | 
|  | 1107 | fi | 
| Jeremy Stanley | 25ebbcd | 2013-02-17 15:45:55 +0000 | [diff] [blame] | 1108 |  | 
| Vishvananda Ishaya | 58e2134 | 2013-02-11 16:48:12 -0800 | [diff] [blame] | 1109 | # sleep to allow bash to be ready to be send the command - we are | 
|  | 1110 | # creating a new window in screen and then sends characters, so if | 
|  | 1111 | # bash isn't running by the time we send the command, nothing happens | 
|  | 1112 | sleep 1.5 | 
| Dean Troyer | 1573335 | 2012-09-06 11:51:30 -0500 | [diff] [blame] | 1113 |  | 
| Vishvananda Ishaya | 58e2134 | 2013-02-11 16:48:12 -0800 | [diff] [blame] | 1114 | NL=`echo -ne '\015'` | 
| Clark Boylan | 41815cd | 2013-08-16 14:57:38 -0700 | [diff] [blame] | 1115 | screen -S $SCREEN_NAME -p $1 -X stuff "$2 || echo \"$1 failed to start\" | tee \"$SERVICE_DIR/$SCREEN_NAME/$1.failure\"$NL" | 
| Vishvananda Ishaya | 58e2134 | 2013-02-11 16:48:12 -0800 | [diff] [blame] | 1116 | else | 
| Dean Troyer | 681f3fd | 2013-02-27 19:00:39 -0600 | [diff] [blame] | 1117 | # Spawn directly without screen | 
|  | 1118 | run_process "$1" "$2" >$SERVICE_DIR/$SCREEN_NAME/$service.pid | 
| Dean Troyer | 1573335 | 2012-09-06 11:51:30 -0500 | [diff] [blame] | 1119 | fi | 
| Dean Troyer | 1573335 | 2012-09-06 11:51:30 -0500 | [diff] [blame] | 1120 | fi | 
|  | 1121 | } | 
|  | 1122 |  | 
|  | 1123 |  | 
|  | 1124 | # Screen rc file builder | 
|  | 1125 | # screen_rc service "command-line" | 
|  | 1126 | function screen_rc { | 
|  | 1127 | SCREEN_NAME=${SCREEN_NAME:-stack} | 
|  | 1128 | SCREENRC=$TOP_DIR/$SCREEN_NAME-screenrc | 
|  | 1129 | if [[ ! -e $SCREENRC ]]; then | 
|  | 1130 | # Name the screen session | 
|  | 1131 | echo "sessionname $SCREEN_NAME" > $SCREENRC | 
|  | 1132 | # Set a reasonable statusbar | 
|  | 1133 | echo "hardstatus alwayslastline '$SCREEN_HARDSTATUS'" >> $SCREENRC | 
| Steven Dake | 3039657 | 2013-06-30 16:11:54 -0700 | [diff] [blame] | 1134 | # Some distributions override PROMPT_COMMAND for the screen terminal type - turn that off | 
|  | 1135 | echo "setenv PROMPT_COMMAND /bin/true" >> $SCREENRC | 
| Dean Troyer | 1573335 | 2012-09-06 11:51:30 -0500 | [diff] [blame] | 1136 | echo "screen -t shell bash" >> $SCREENRC | 
|  | 1137 | fi | 
|  | 1138 | # If this service doesn't already exist in the screenrc file | 
|  | 1139 | if ! grep $1 $SCREENRC 2>&1 > /dev/null; then | 
|  | 1140 | NL=`echo -ne '\015'` | 
|  | 1141 | echo "screen -t $1 bash" >> $SCREENRC | 
|  | 1142 | echo "stuff \"$2$NL\"" >> $SCREENRC | 
|  | 1143 | fi | 
|  | 1144 | } | 
|  | 1145 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1146 |  | 
| jiajun xu | a941424 | 2012-12-06 16:30:57 +0800 | [diff] [blame] | 1147 | # Helper to remove the *.failure files under $SERVICE_DIR/$SCREEN_NAME | 
|  | 1148 | # This is used for service_check when all the screen_it are called finished | 
|  | 1149 | # init_service_check | 
|  | 1150 | function init_service_check() { | 
|  | 1151 | SCREEN_NAME=${SCREEN_NAME:-stack} | 
|  | 1152 | SERVICE_DIR=${SERVICE_DIR:-${DEST}/status} | 
|  | 1153 |  | 
|  | 1154 | if [[ ! -d "$SERVICE_DIR/$SCREEN_NAME" ]]; then | 
|  | 1155 | mkdir -p "$SERVICE_DIR/$SCREEN_NAME" | 
|  | 1156 | fi | 
|  | 1157 |  | 
|  | 1158 | rm -f "$SERVICE_DIR/$SCREEN_NAME"/*.failure | 
|  | 1159 | } | 
|  | 1160 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1161 |  | 
| jiajun xu | a941424 | 2012-12-06 16:30:57 +0800 | [diff] [blame] | 1162 | # Helper to get the status of each running service | 
|  | 1163 | # service_check | 
|  | 1164 | function service_check() { | 
|  | 1165 | local service | 
|  | 1166 | local failures | 
|  | 1167 | SCREEN_NAME=${SCREEN_NAME:-stack} | 
|  | 1168 | SERVICE_DIR=${SERVICE_DIR:-${DEST}/status} | 
|  | 1169 |  | 
|  | 1170 |  | 
|  | 1171 | if [[ ! -d "$SERVICE_DIR/$SCREEN_NAME" ]]; then | 
|  | 1172 | echo "No service status directory found" | 
|  | 1173 | return | 
|  | 1174 | fi | 
|  | 1175 |  | 
|  | 1176 | # Check if there is any falure flag file under $SERVICE_DIR/$SCREEN_NAME | 
|  | 1177 | failures=`ls "$SERVICE_DIR/$SCREEN_NAME"/*.failure 2>/dev/null` | 
|  | 1178 |  | 
|  | 1179 | for service in $failures; do | 
|  | 1180 | service=`basename $service` | 
| Bob Ball | 46287d8 | 2013-07-30 09:43:17 +0100 | [diff] [blame] | 1181 | service=${service%.failure} | 
| jiajun xu | a941424 | 2012-12-06 16:30:57 +0800 | [diff] [blame] | 1182 | echo "Error: Service $service is not running" | 
|  | 1183 | done | 
|  | 1184 |  | 
|  | 1185 | if [ -n "$failures" ]; then | 
|  | 1186 | echo "More details about the above errors can be found with screen, with ./rejoin-stack.sh" | 
|  | 1187 | fi | 
|  | 1188 | } | 
| Dean Troyer | 1573335 | 2012-09-06 11:51:30 -0500 | [diff] [blame] | 1189 |  | 
| Doug Hellmann | e700267 | 2013-09-05 08:10:07 -0400 | [diff] [blame] | 1190 | # Returns true if the directory is on a filesystem mounted via NFS. | 
|  | 1191 | function is_nfs_directory() { | 
|  | 1192 | local mount_type=`stat -f -L -c %T $1` | 
|  | 1193 | test "$mount_type" == "nfs" | 
|  | 1194 | } | 
|  | 1195 |  | 
|  | 1196 | # Only run the command if the target file (the last arg) is not on an | 
|  | 1197 | # NFS filesystem. | 
|  | 1198 | function _safe_permission_operation() { | 
|  | 1199 | local args=( $@ ) | 
|  | 1200 | local last | 
|  | 1201 | local sudo_cmd | 
|  | 1202 | local dir_to_check | 
|  | 1203 |  | 
|  | 1204 | let last="${#args[*]} - 1" | 
|  | 1205 |  | 
|  | 1206 | dir_to_check=${args[$last]} | 
|  | 1207 | if [ ! -d "$dir_to_check" ]; then | 
|  | 1208 | dir_to_check=`dirname "$dir_to_check"` | 
|  | 1209 | fi | 
|  | 1210 |  | 
|  | 1211 | if is_nfs_directory "$dir_to_check" ; then | 
|  | 1212 | return 0 | 
|  | 1213 | fi | 
|  | 1214 |  | 
|  | 1215 | if [[ $TRACK_DEPENDS = True ]]; then | 
|  | 1216 | sudo_cmd="env" | 
|  | 1217 | else | 
|  | 1218 | sudo_cmd="sudo" | 
|  | 1219 | fi | 
|  | 1220 |  | 
|  | 1221 | $sudo_cmd $@ | 
|  | 1222 | } | 
|  | 1223 |  | 
|  | 1224 | # Only change ownership of a file or directory if it is not on an NFS | 
|  | 1225 | # filesystem. | 
|  | 1226 | function safe_chown() { | 
|  | 1227 | _safe_permission_operation chown $@ | 
|  | 1228 | } | 
|  | 1229 |  | 
|  | 1230 | # Only change permissions of a file or directory if it is not on an | 
|  | 1231 | # NFS filesystem. | 
|  | 1232 | function safe_chmod() { | 
|  | 1233 | _safe_permission_operation chmod $@ | 
|  | 1234 | } | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1235 |  | 
| Monty Taylor | 408a4a7 | 2013-08-02 15:43:47 -0400 | [diff] [blame] | 1236 | # ``pip install -e`` the package, which processes the dependencies | 
|  | 1237 | # using pip before running `setup.py develop` | 
| Monty Taylor | b5bbaac | 2013-08-06 10:35:02 -0300 | [diff] [blame] | 1238 | # Uses globals ``STACK_USER``, ``TRACK_DEPENDS``, ``REQUIREMENTS_DIR`` | 
| Dean Troyer | bbafb1b | 2012-06-11 16:51:39 -0500 | [diff] [blame] | 1239 | # setup_develop directory | 
|  | 1240 | function setup_develop() { | 
| Sean Dague | 6c84463 | 2013-07-31 06:50:14 -0400 | [diff] [blame] | 1241 | local project_dir=$1 | 
| Sean Dague | 6c84463 | 2013-07-31 06:50:14 -0400 | [diff] [blame] | 1242 |  | 
|  | 1243 | echo "cd $REQUIREMENTS_DIR; $SUDO_CMD python update.py $project_dir" | 
|  | 1244 |  | 
| Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 1245 | # Don't update repo if local changes exist | 
| Doug Hellmann | c3431bf | 2013-09-06 15:30:22 -0400 | [diff] [blame] | 1246 | (cd $project_dir && git diff --quiet) | 
|  | 1247 | local update_requirements=$? | 
|  | 1248 |  | 
|  | 1249 | if [ $update_requirements -eq 0 ]; then | 
| Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 1250 | (cd $REQUIREMENTS_DIR; \ | 
|  | 1251 | $SUDO_CMD python update.py $project_dir) | 
|  | 1252 | fi | 
| Sean Dague | 6c84463 | 2013-07-31 06:50:14 -0400 | [diff] [blame] | 1253 |  | 
| Monty Taylor | b5bbaac | 2013-08-06 10:35:02 -0300 | [diff] [blame] | 1254 | pip_install -e $project_dir | 
|  | 1255 | # ensure that further actions can do things like setup.py sdist | 
| Doug Hellmann | e700267 | 2013-09-05 08:10:07 -0400 | [diff] [blame] | 1256 | safe_chown -R $STACK_USER $1/*.egg-info | 
| Doug Hellmann | c3431bf | 2013-09-06 15:30:22 -0400 | [diff] [blame] | 1257 |  | 
|  | 1258 | # Undo requirements changes, if we made them | 
|  | 1259 | if [ $update_requirements -eq 0 ]; then | 
|  | 1260 | (cd $project_dir && git checkout -- requirements.txt test-requirements.txt setup.py) | 
|  | 1261 | fi | 
| Dean Troyer | bbafb1b | 2012-06-11 16:51:39 -0500 | [diff] [blame] | 1262 | } | 
|  | 1263 |  | 
|  | 1264 |  | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 1265 | # Service wrapper to start services | 
|  | 1266 | # start_service service-name | 
|  | 1267 | function start_service() { | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 1268 | if is_ubuntu; then | 
| Dean Troyer | 5218d45 | 2012-02-04 02:13:23 -0600 | [diff] [blame] | 1269 | sudo /usr/sbin/service $1 start | 
|  | 1270 | else | 
|  | 1271 | sudo /sbin/service $1 start | 
|  | 1272 | fi | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 1273 | } | 
|  | 1274 |  | 
|  | 1275 |  | 
|  | 1276 | # Service wrapper to stop services | 
|  | 1277 | # stop_service service-name | 
|  | 1278 | function stop_service() { | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 1279 | if is_ubuntu; then | 
| Dean Troyer | 5218d45 | 2012-02-04 02:13:23 -0600 | [diff] [blame] | 1280 | sudo /usr/sbin/service $1 stop | 
|  | 1281 | else | 
|  | 1282 | sudo /sbin/service $1 stop | 
|  | 1283 | fi | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 1284 | } | 
|  | 1285 |  | 
|  | 1286 |  | 
|  | 1287 | # Normalize config values to True or False | 
| Sirushti Murugesan | a8d41e3 | 2013-09-25 11:30:31 +0530 | [diff] [blame] | 1288 | # Accepts as False: 0 no No NO false False FALSE | 
|  | 1289 | # Accepts as True: 1 yes Yes YES true True TRUE | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 1290 | # VAR=$(trueorfalse default-value test-value) | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 1291 | function trueorfalse() { | 
|  | 1292 | local default=$1 | 
|  | 1293 | local testval=$2 | 
|  | 1294 |  | 
|  | 1295 | [[ -z "$testval" ]] && { echo "$default"; return; } | 
| Sirushti Murugesan | a8d41e3 | 2013-09-25 11:30:31 +0530 | [diff] [blame] | 1296 | [[ "0 no No NO false False FALSE" =~ "$testval" ]] && { echo "False"; return; } | 
|  | 1297 | [[ "1 yes Yes YES true True TRUE" =~ "$testval" ]] && { echo "True"; return; } | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 1298 | echo "$default" | 
|  | 1299 | } | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 1300 |  | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 1301 |  | 
| Dean Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 1302 | # Retrieve an image from a URL and upload into Glance | 
|  | 1303 | # Uses the following variables: | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 1304 | #   ``FILES`` must be set to the cache dir | 
|  | 1305 | #   ``GLANCE_HOSTPORT`` | 
| Dean Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 1306 | # upload_image image-url glance-token | 
|  | 1307 | function upload_image() { | 
|  | 1308 | local image_url=$1 | 
|  | 1309 | local token=$2 | 
|  | 1310 |  | 
|  | 1311 | # Create a directory for the downloaded image tarballs. | 
|  | 1312 | mkdir -p $FILES/images | 
|  | 1313 |  | 
|  | 1314 | # Downloads the image (uec ami+aki style), then extracts it. | 
|  | 1315 | IMAGE_FNAME=`basename "$image_url"` | 
|  | 1316 | if [[ ! -f $FILES/$IMAGE_FNAME || "$(stat -c "%s" $FILES/$IMAGE_FNAME)" = "0" ]]; then | 
|  | 1317 | wget -c $image_url -O $FILES/$IMAGE_FNAME | 
|  | 1318 | if [[ $? -ne 0 ]]; then | 
|  | 1319 | echo "Not found: $image_url" | 
|  | 1320 | return | 
|  | 1321 | fi | 
|  | 1322 | fi | 
|  | 1323 |  | 
|  | 1324 | # OpenVZ-format images are provided as .tar.gz, but not decompressed prior to loading | 
|  | 1325 | if [[ "$image_url" =~ 'openvz' ]]; then | 
|  | 1326 | IMAGE="$FILES/${IMAGE_FNAME}" | 
|  | 1327 | IMAGE_NAME="${IMAGE_FNAME%.tar.gz}" | 
|  | 1328 | 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}" | 
|  | 1329 | return | 
|  | 1330 | fi | 
|  | 1331 |  | 
| Sreeram Yerrapragada | cbaff86 | 2013-07-24 19:49:23 -0700 | [diff] [blame] | 1332 | # vmdk format images | 
|  | 1333 | if [[ "$image_url" =~ '.vmdk' ]]; then | 
|  | 1334 | IMAGE="$FILES/${IMAGE_FNAME}" | 
|  | 1335 | IMAGE_NAME="${IMAGE_FNAME%.vmdk}" | 
| Ryan Hsu | a6273b9 | 2013-09-04 23:51:29 -0700 | [diff] [blame] | 1336 |  | 
|  | 1337 | # Before we can upload vmdk type images to glance, we need to know it's | 
|  | 1338 | # disk type, storage adapter, and networking adapter. These values are | 
|  | 1339 | # passed to glance as custom properties. We take these values from the | 
|  | 1340 | # vmdk filename, which is expected in the following format: | 
|  | 1341 | # | 
|  | 1342 | #     <name>-<disk type>:<storage adapter>:<network adapter> | 
|  | 1343 | # | 
|  | 1344 | # If the filename does not follow the above format then the vsphere | 
|  | 1345 | # driver will supply default values. | 
|  | 1346 | property_string=`echo "$IMAGE_NAME" | grep -oP '(?<=-)(?!.*-).+:.+:.+$'` | 
|  | 1347 | if [[ ! -z "$property_string" ]]; then | 
|  | 1348 | IFS=':' read -a props <<< "$property_string" | 
|  | 1349 | vmdk_disktype="${props[0]}" | 
|  | 1350 | vmdk_adapter_type="${props[1]}" | 
|  | 1351 | vmdk_net_adapter="${props[2]}" | 
|  | 1352 | fi | 
|  | 1353 |  | 
| Ryan Hsu | 49f4486 | 2013-10-03 22:27:03 -0700 | [diff] [blame] | 1354 | 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 Yerrapragada | cbaff86 | 2013-07-24 19:49:23 -0700 | [diff] [blame] | 1355 | return | 
|  | 1356 | fi | 
|  | 1357 |  | 
| Mate Lakat | bc2ef92 | 2013-08-15 18:06:59 +0100 | [diff] [blame] | 1358 | # XenServer-vhd-ovf-format images are provided as .vhd.tgz | 
| Davanum Srinivas | 316ed6c | 2013-02-06 15:29:49 -0500 | [diff] [blame] | 1359 | # and should not be decompressed prior to loading | 
|  | 1360 | if [[ "$image_url" =~ '.vhd.tgz' ]]; then | 
|  | 1361 | IMAGE="$FILES/${IMAGE_FNAME}" | 
|  | 1362 | IMAGE_NAME="${IMAGE_FNAME%.vhd.tgz}" | 
|  | 1363 | 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}" | 
|  | 1364 | return | 
|  | 1365 | fi | 
|  | 1366 |  | 
| Mate Lakat | bc2ef92 | 2013-08-15 18:06:59 +0100 | [diff] [blame] | 1367 | # .xen-raw.tgz suggests a Xen capable raw image inside a tgz. | 
|  | 1368 | # and should not be decompressed prior to loading. | 
|  | 1369 | # Setting metadata, so PV mode is used. | 
|  | 1370 | if [[ "$image_url" =~ '.xen-raw.tgz' ]]; then | 
|  | 1371 | IMAGE="$FILES/${IMAGE_FNAME}" | 
|  | 1372 | IMAGE_NAME="${IMAGE_FNAME%.xen-raw.tgz}" | 
|  | 1373 | glance \ | 
|  | 1374 | --os-auth-token $token \ | 
|  | 1375 | --os-image-url http://$GLANCE_HOSTPORT \ | 
|  | 1376 | image-create \ | 
|  | 1377 | --name "$IMAGE_NAME" --is-public=True \ | 
|  | 1378 | --container-format=tgz --disk-format=raw \ | 
|  | 1379 | --property vm_mode=xen < "${IMAGE}" | 
|  | 1380 | return | 
|  | 1381 | fi | 
|  | 1382 |  | 
| Dean Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 1383 | KERNEL="" | 
|  | 1384 | RAMDISK="" | 
|  | 1385 | DISK_FORMAT="" | 
|  | 1386 | CONTAINER_FORMAT="" | 
|  | 1387 | UNPACK="" | 
|  | 1388 | case "$IMAGE_FNAME" in | 
|  | 1389 | *.tar.gz|*.tgz) | 
|  | 1390 | # Extract ami and aki files | 
|  | 1391 | [ "${IMAGE_FNAME%.tar.gz}" != "$IMAGE_FNAME" ] && | 
|  | 1392 | IMAGE_NAME="${IMAGE_FNAME%.tar.gz}" || | 
|  | 1393 | IMAGE_NAME="${IMAGE_FNAME%.tgz}" | 
|  | 1394 | xdir="$FILES/images/$IMAGE_NAME" | 
|  | 1395 | rm -Rf "$xdir"; | 
|  | 1396 | mkdir "$xdir" | 
|  | 1397 | tar -zxf $FILES/$IMAGE_FNAME -C "$xdir" | 
|  | 1398 | KERNEL=$(for f in "$xdir/"*-vmlinuz* "$xdir/"aki-*/image; do | 
|  | 1399 | [ -f "$f" ] && echo "$f" && break; done; true) | 
|  | 1400 | RAMDISK=$(for f in "$xdir/"*-initrd* "$xdir/"ari-*/image; do | 
|  | 1401 | [ -f "$f" ] && echo "$f" && break; done; true) | 
|  | 1402 | IMAGE=$(for f in "$xdir/"*.img "$xdir/"ami-*/image; do | 
|  | 1403 | [ -f "$f" ] && echo "$f" && break; done; true) | 
|  | 1404 | if [[ -z "$IMAGE_NAME" ]]; then | 
|  | 1405 | IMAGE_NAME=$(basename "$IMAGE" ".img") | 
|  | 1406 | fi | 
|  | 1407 | ;; | 
|  | 1408 | *.img) | 
|  | 1409 | IMAGE="$FILES/$IMAGE_FNAME"; | 
|  | 1410 | IMAGE_NAME=$(basename "$IMAGE" ".img") | 
| Dean Troyer | 636a3ff | 2012-09-14 11:36:07 -0500 | [diff] [blame] | 1411 | format=$(qemu-img info ${IMAGE} | awk '/^file format/ { print $3; exit }') | 
|  | 1412 | if [[ ",qcow2,raw,vdi,vmdk,vpc," =~ ",$format," ]]; then | 
|  | 1413 | DISK_FORMAT=$format | 
|  | 1414 | else | 
|  | 1415 | DISK_FORMAT=raw | 
|  | 1416 | fi | 
| Dean Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 1417 | CONTAINER_FORMAT=bare | 
|  | 1418 | ;; | 
|  | 1419 | *.img.gz) | 
|  | 1420 | IMAGE="$FILES/${IMAGE_FNAME}" | 
|  | 1421 | IMAGE_NAME=$(basename "$IMAGE" ".img.gz") | 
|  | 1422 | DISK_FORMAT=raw | 
|  | 1423 | CONTAINER_FORMAT=bare | 
|  | 1424 | UNPACK=zcat | 
|  | 1425 | ;; | 
|  | 1426 | *.qcow2) | 
|  | 1427 | IMAGE="$FILES/${IMAGE_FNAME}" | 
|  | 1428 | IMAGE_NAME=$(basename "$IMAGE" ".qcow2") | 
|  | 1429 | DISK_FORMAT=qcow2 | 
|  | 1430 | CONTAINER_FORMAT=bare | 
|  | 1431 | ;; | 
| Jonathan Michalon | 0680204 | 2013-03-21 14:29:58 +0100 | [diff] [blame] | 1432 | *.iso) | 
|  | 1433 | IMAGE="$FILES/${IMAGE_FNAME}" | 
|  | 1434 | IMAGE_NAME=$(basename "$IMAGE" ".iso") | 
|  | 1435 | DISK_FORMAT=iso | 
|  | 1436 | CONTAINER_FORMAT=bare | 
|  | 1437 | ;; | 
| Dean Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 1438 | *) echo "Do not know what to do with $IMAGE_FNAME"; false;; | 
|  | 1439 | esac | 
|  | 1440 |  | 
|  | 1441 | if [ "$CONTAINER_FORMAT" = "bare" ]; then | 
|  | 1442 | if [ "$UNPACK" = "zcat" ]; then | 
| Christian Berendt | a7a219a | 2013-07-30 18:22:32 +0200 | [diff] [blame] | 1443 | 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 Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 1444 | else | 
| Christian Berendt | a7a219a | 2013-07-30 18:22:32 +0200 | [diff] [blame] | 1445 | 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 Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 1446 | fi | 
|  | 1447 | else | 
|  | 1448 | # Use glance client to add the kernel the root filesystem. | 
|  | 1449 | # We parse the results of the first upload to get the glance ID of the | 
|  | 1450 | # kernel for use when uploading the root filesystem. | 
|  | 1451 | KERNEL_ID=""; RAMDISK_ID=""; | 
|  | 1452 | if [ -n "$KERNEL" ]; then | 
| Christian Berendt | a7a219a | 2013-07-30 18:22:32 +0200 | [diff] [blame] | 1453 | 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 Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 1454 | fi | 
|  | 1455 | if [ -n "$RAMDISK" ]; then | 
| Christian Berendt | a7a219a | 2013-07-30 18:22:32 +0200 | [diff] [blame] | 1456 | 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 Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 1457 | fi | 
| Christian Berendt | a7a219a | 2013-07-30 18:22:32 +0200 | [diff] [blame] | 1458 | 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 Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 1459 | fi | 
|  | 1460 | } | 
|  | 1461 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1462 |  | 
| Dean Troyer | c1b486a | 2012-11-05 14:26:09 -0600 | [diff] [blame] | 1463 | # Set the database backend to use | 
|  | 1464 | # When called from stackrc/localrc DATABASE_BACKENDS has not been | 
|  | 1465 | # initialized yet, just save the configuration selection and call back later | 
|  | 1466 | # to validate it. | 
|  | 1467 | #  $1 The name of the database backend to use (mysql, postgresql, ...) | 
|  | 1468 | function use_database { | 
|  | 1469 | if [[ -z "$DATABASE_BACKENDS" ]]; then | 
| Dean Troyer | afc29fe | 2013-02-07 15:56:24 -0600 | [diff] [blame] | 1470 | # No backends registered means this is likely called from ``localrc`` | 
|  | 1471 | # This is now deprecated usage | 
| Dean Troyer | c1b486a | 2012-11-05 14:26:09 -0600 | [diff] [blame] | 1472 | DATABASE_TYPE=$1 | 
| Bob Ball | 3aa8887 | 2013-02-28 17:39:41 +0000 | [diff] [blame] | 1473 | DEPRECATED_TEXT="$DEPRECATED_TEXT\nThe database backend needs to be properly set in ENABLED_SERVICES; use_database is deprecated localrc\n" | 
| Attila Fazekas | 251d3b5 | 2012-12-16 15:05:44 +0100 | [diff] [blame] | 1474 | else | 
| Dean Troyer | afc29fe | 2013-02-07 15:56:24 -0600 | [diff] [blame] | 1475 | # This should no longer get called...here for posterity | 
| Attila Fazekas | 251d3b5 | 2012-12-16 15:05:44 +0100 | [diff] [blame] | 1476 | use_exclusive_service DATABASE_BACKENDS DATABASE_TYPE $1 | 
| Dean Troyer | c1b486a | 2012-11-05 14:26:09 -0600 | [diff] [blame] | 1477 | fi | 
| Dean Troyer | c1b486a | 2012-11-05 14:26:09 -0600 | [diff] [blame] | 1478 | } | 
|  | 1479 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1480 |  | 
| Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 1481 | # Toggle enable/disable_service for services that must run exclusive of each other | 
|  | 1482 | #  $1 The name of a variable containing a space-separated list of services | 
|  | 1483 | #  $2 The name of a variable in which to store the enabled service's name | 
|  | 1484 | #  $3 The name of the service to enable | 
|  | 1485 | function use_exclusive_service { | 
|  | 1486 | local options=${!1} | 
|  | 1487 | local selection=$3 | 
|  | 1488 | out=$2 | 
|  | 1489 | [ -z $selection ] || [[ ! "$options" =~ "$selection" ]] && return 1 | 
|  | 1490 | for opt in $options;do | 
|  | 1491 | [[ "$opt" = "$selection" ]] && enable_service $opt || disable_service $opt | 
|  | 1492 | done | 
|  | 1493 | eval "$out=$selection" | 
|  | 1494 | return 0 | 
|  | 1495 | } | 
| Dean Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 1496 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1497 |  | 
| Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 1498 | # Wait for an HTTP server to start answering requests | 
|  | 1499 | # wait_for_service timeout url | 
|  | 1500 | function wait_for_service() { | 
|  | 1501 | local timeout=$1 | 
|  | 1502 | local url=$2 | 
| JUN JIE NAN | 0aa8534 | 2013-09-13 15:47:09 +0800 | [diff] [blame] | 1503 | timeout $timeout sh -c "while ! curl --noproxy '*' -s $url >/dev/null; do sleep 1; done" | 
| Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 1504 | } | 
|  | 1505 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1506 |  | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 1507 | # Wrapper for ``yum`` to set proxy environment variables | 
|  | 1508 | # Uses globals ``OFFLINE``, ``*_proxy` | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 1509 | # yum_install package [package ...] | 
|  | 1510 | function yum_install() { | 
|  | 1511 | [[ "$OFFLINE" = "True" ]] && return | 
|  | 1512 | local sudo="sudo" | 
|  | 1513 | [[ "$(id -u)" = "0" ]] && sudo="env" | 
|  | 1514 | $sudo http_proxy=$http_proxy https_proxy=$https_proxy \ | 
| Osamu Habuka | 7abe4f2 | 2012-07-25 12:39:32 +0900 | [diff] [blame] | 1515 | no_proxy=$no_proxy \ | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 1516 | yum install -y "$@" | 
|  | 1517 | } | 
|  | 1518 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1519 |  | 
|  | 1520 | # zypper wrapper to set arguments correctly | 
|  | 1521 | # zypper_install package [package ...] | 
|  | 1522 | function zypper_install() { | 
|  | 1523 | [[ "$OFFLINE" = "True" ]] && return | 
|  | 1524 | local sudo="sudo" | 
|  | 1525 | [[ "$(id -u)" = "0" ]] && sudo="env" | 
|  | 1526 | $sudo http_proxy=$http_proxy https_proxy=$https_proxy \ | 
|  | 1527 | zypper --non-interactive install --auto-agree-with-licenses "$@" | 
|  | 1528 | } | 
|  | 1529 |  | 
|  | 1530 |  | 
| Nachi Ueno | fda946e | 2012-10-24 17:26:02 -0700 | [diff] [blame] | 1531 | # ping check | 
|  | 1532 | # Uses globals ``ENABLED_SERVICES`` | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1533 | # ping_check from-net ip boot-timeout expected | 
| Nachi Ueno | fda946e | 2012-10-24 17:26:02 -0700 | [diff] [blame] | 1534 | function ping_check() { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1535 | if is_service_enabled neutron; then | 
|  | 1536 | _ping_check_neutron  "$1" $2 $3 $4 | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 1537 | return | 
|  | 1538 | fi | 
|  | 1539 | _ping_check_novanet "$1" $2 $3 $4 | 
| Nachi Ueno | fda946e | 2012-10-24 17:26:02 -0700 | [diff] [blame] | 1540 | } | 
|  | 1541 |  | 
|  | 1542 | # ping check for nova | 
|  | 1543 | # Uses globals ``MULTI_HOST``, ``PRIVATE_NETWORK`` | 
|  | 1544 | function _ping_check_novanet() { | 
|  | 1545 | local from_net=$1 | 
|  | 1546 | local ip=$2 | 
|  | 1547 | local boot_timeout=$3 | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 1548 | local expected=${4:-"True"} | 
|  | 1549 | local check_command="" | 
| Nachi Ueno | fda946e | 2012-10-24 17:26:02 -0700 | [diff] [blame] | 1550 | MULTI_HOST=`trueorfalse False $MULTI_HOST` | 
|  | 1551 | if [[ "$MULTI_HOST" = "True" && "$from_net" = "$PRIVATE_NETWORK_NAME" ]]; then | 
| Nachi Ueno | fda946e | 2012-10-24 17:26:02 -0700 | [diff] [blame] | 1552 | return | 
|  | 1553 | fi | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 1554 | if [[ "$expected" = "True" ]]; then | 
|  | 1555 | check_command="while ! ping -c1 -w1 $ip; do sleep 1; done" | 
|  | 1556 | else | 
|  | 1557 | check_command="while ping -c1 -w1 $ip; do sleep 1; done" | 
|  | 1558 | fi | 
|  | 1559 | if ! timeout $boot_timeout sh -c "$check_command"; then | 
|  | 1560 | if [[ "$expected" = "True" ]]; then | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 1561 | die $LINENO "[Fail] Couldn't ping server" | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 1562 | else | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 1563 | die $LINENO "[Fail] Could ping server" | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 1564 | fi | 
| Nachi Ueno | fda946e | 2012-10-24 17:26:02 -0700 | [diff] [blame] | 1565 | exit 1 | 
|  | 1566 | fi | 
|  | 1567 | } | 
|  | 1568 |  | 
| Nachi Ueno | 6769b16 | 2013-08-12 18:18:56 -0700 | [diff] [blame] | 1569 | # Get ip of instance | 
|  | 1570 | function get_instance_ip(){ | 
|  | 1571 | local vm_id=$1 | 
|  | 1572 | local network_name=$2 | 
|  | 1573 | local nova_result="$(nova show $vm_id)" | 
|  | 1574 | local ip=$(echo "$nova_result" | grep "$network_name" | get_field 2) | 
|  | 1575 | if [[ $ip = "" ]];then | 
|  | 1576 | echo "$nova_result" | 
|  | 1577 | die $LINENO "[Fail] Coudn't get ipaddress of VM" | 
|  | 1578 | exit 1 | 
|  | 1579 | fi | 
|  | 1580 | echo $ip | 
|  | 1581 | } | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1582 |  | 
| Nachi Ueno | fda946e | 2012-10-24 17:26:02 -0700 | [diff] [blame] | 1583 | # ssh check | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 1584 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1585 | # ssh_check net-name key-file floating-ip default-user active-timeout | 
| Nachi Ueno | fda946e | 2012-10-24 17:26:02 -0700 | [diff] [blame] | 1586 | function ssh_check() { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1587 | if is_service_enabled neutron; then | 
|  | 1588 | _ssh_check_neutron  "$1" $2 $3 $4 $5 | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 1589 | return | 
|  | 1590 | fi | 
|  | 1591 | _ssh_check_novanet "$1" $2 $3 $4 $5 | 
|  | 1592 | } | 
|  | 1593 |  | 
|  | 1594 | function _ssh_check_novanet() { | 
| Nachi Ueno | fda946e | 2012-10-24 17:26:02 -0700 | [diff] [blame] | 1595 | local NET_NAME=$1 | 
|  | 1596 | local KEY_FILE=$2 | 
|  | 1597 | local FLOATING_IP=$3 | 
|  | 1598 | local DEFAULT_INSTANCE_USER=$4 | 
|  | 1599 | local ACTIVE_TIMEOUT=$5 | 
| Dean Troyer | 6931c13 | 2012-11-07 16:51:21 -0600 | [diff] [blame] | 1600 | local probe_cmd="" | 
| Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 1601 | 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 Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 1602 | die $LINENO "server didn't become ssh-able!" | 
| Nachi Ueno | fda946e | 2012-10-24 17:26:02 -0700 | [diff] [blame] | 1603 | fi | 
|  | 1604 | } | 
| Dean Troyer | 13dc5cc | 2012-03-27 14:50:45 -0500 | [diff] [blame] | 1605 |  | 
| Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 1606 |  | 
| Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 1607 | # Add a user to a group. | 
|  | 1608 | # add_user_to_group user group | 
|  | 1609 | function add_user_to_group() { | 
|  | 1610 | local user=$1 | 
|  | 1611 | local group=$2 | 
|  | 1612 |  | 
|  | 1613 | if [[ -z "$os_VENDOR" ]]; then | 
|  | 1614 | GetOSVersion | 
|  | 1615 | fi | 
|  | 1616 |  | 
|  | 1617 | # SLE11 and openSUSE 12.2 don't have the usual usermod | 
|  | 1618 | if ! is_suse || [[ "$os_VENDOR" = "openSUSE" && "$os_RELEASE" != "12.2" ]]; then | 
|  | 1619 | sudo usermod -a -G "$group" "$user" | 
|  | 1620 | else | 
|  | 1621 | sudo usermod -A "$group" "$user" | 
|  | 1622 | fi | 
|  | 1623 | } | 
|  | 1624 |  | 
|  | 1625 |  | 
| Jakub Ruzicka | 4196d55 | 2013-01-30 15:35:54 +0100 | [diff] [blame] | 1626 | # Get the path to the direcotry where python executables are installed. | 
|  | 1627 | # get_python_exec_prefix | 
|  | 1628 | function get_python_exec_prefix() { | 
| Martin Vidner | 4f9b33d | 2013-06-27 13:11:22 +0000 | [diff] [blame] | 1629 | if is_fedora || is_suse; then | 
| Jakub Ruzicka | 4196d55 | 2013-01-30 15:35:54 +0100 | [diff] [blame] | 1630 | echo "/usr/bin" | 
|  | 1631 | else | 
|  | 1632 | echo "/usr/local/bin" | 
|  | 1633 | fi | 
|  | 1634 | } | 
|  | 1635 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1636 |  | 
| Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 1637 | # Get the location of the $module-rootwrap executables, where module is cinder | 
|  | 1638 | # or nova. | 
|  | 1639 | # get_rootwrap_location module | 
|  | 1640 | function get_rootwrap_location() { | 
|  | 1641 | local module=$1 | 
|  | 1642 |  | 
| Jakub Ruzicka | 4196d55 | 2013-01-30 15:35:54 +0100 | [diff] [blame] | 1643 | echo "$(get_python_exec_prefix)/$module-rootwrap" | 
| Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 1644 | } | 
|  | 1645 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1646 |  | 
| Vincent Untz | 8ec2722 | 2012-11-29 09:25:31 +0100 | [diff] [blame] | 1647 | # Get the path to the pip command. | 
|  | 1648 | # get_pip_command | 
|  | 1649 | function get_pip_command() { | 
| Dean Troyer | d2cfcaa | 2013-08-01 14:17:27 -0500 | [diff] [blame] | 1650 | which pip || which pip-python | 
| Ian Wienand | 535a814 | 2013-05-15 09:25:27 +1000 | [diff] [blame] | 1651 |  | 
|  | 1652 | if [ $? -ne 0 ]; then | 
|  | 1653 | die $LINENO "Unable to find pip; cannot continue" | 
|  | 1654 | fi | 
| Vincent Untz | 8ec2722 | 2012-11-29 09:25:31 +0100 | [diff] [blame] | 1655 | } | 
| Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 1656 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1657 |  | 
| Ian Wienand | 0488edd | 2013-04-11 12:04:36 +1000 | [diff] [blame] | 1658 | # Path permissions sanity check | 
|  | 1659 | # check_path_perm_sanity path | 
|  | 1660 | function check_path_perm_sanity() { | 
|  | 1661 | # Ensure no element of the path has 0700 permissions, which is very | 
|  | 1662 | # likely to cause issues for daemons.  Inspired by default 0700 | 
|  | 1663 | # homedir permissions on RHEL and common practice of making DEST in | 
|  | 1664 | # the stack user's homedir. | 
|  | 1665 |  | 
|  | 1666 | local real_path=$(readlink -f $1) | 
|  | 1667 | local rebuilt_path="" | 
|  | 1668 | for i in $(echo ${real_path} | tr "/" " "); do | 
|  | 1669 | rebuilt_path=$rebuilt_path"/"$i | 
|  | 1670 |  | 
|  | 1671 | if [[ $(stat -c '%a' ${rebuilt_path}) = 700 ]]; then | 
|  | 1672 | echo "*** DEST path element" | 
|  | 1673 | echo "***    ${rebuilt_path}" | 
|  | 1674 | echo "*** appears to have 0700 permissions." | 
|  | 1675 | echo "*** This is very likely to cause fatal issues for devstack daemons." | 
|  | 1676 |  | 
|  | 1677 | if [[ -n "$SKIP_PATH_SANITY" ]]; then | 
|  | 1678 | return | 
|  | 1679 | else | 
|  | 1680 | echo "*** Set SKIP_PATH_SANITY to skip this check" | 
|  | 1681 | die $LINENO "Invalid path permissions" | 
|  | 1682 | fi | 
|  | 1683 | fi | 
|  | 1684 | done | 
|  | 1685 | } | 
|  | 1686 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 1687 |  | 
| Kyle Mestery | 51a3f1f | 2013-06-13 11:47:56 +0000 | [diff] [blame] | 1688 | # This function recursively compares versions, and is not meant to be | 
|  | 1689 | # called by anything other than vercmp_numbers below. This function does | 
|  | 1690 | # not work with alphabetic versions. | 
|  | 1691 | # | 
|  | 1692 | # _vercmp_r sep ver1 ver2 | 
|  | 1693 | function _vercmp_r { | 
|  | 1694 | typeset sep | 
|  | 1695 | typeset -a ver1=() ver2=() | 
|  | 1696 | sep=$1; shift | 
|  | 1697 | ver1=("${@:1:sep}") | 
|  | 1698 | ver2=("${@:sep+1}") | 
|  | 1699 |  | 
|  | 1700 | if ((ver1 > ver2)); then | 
|  | 1701 | echo 1; return 0 | 
|  | 1702 | elif ((ver2 > ver1)); then | 
|  | 1703 | echo -1; return 0 | 
|  | 1704 | fi | 
|  | 1705 |  | 
|  | 1706 | if ((sep <= 1)); then | 
|  | 1707 | echo 0; return 0 | 
|  | 1708 | fi | 
|  | 1709 |  | 
|  | 1710 | _vercmp_r $((sep-1)) "${ver1[@]:1}" "${ver2[@]:1}" | 
|  | 1711 | } | 
|  | 1712 |  | 
|  | 1713 |  | 
|  | 1714 | # This function compares two versions and is meant to be called by | 
|  | 1715 | # external callers. Please note the function assumes non-alphabetic | 
|  | 1716 | # versions. For example, this will work: | 
|  | 1717 | # | 
|  | 1718 | #   vercmp_numbers 1.10 1.4 | 
|  | 1719 | # | 
|  | 1720 | # The above will return "1", as 1.10 is greater than 1.4. | 
|  | 1721 | # | 
|  | 1722 | #   vercmp_numbers 5.2 6.4 | 
|  | 1723 | # | 
|  | 1724 | # The above will return "-1", as 5.2 is less than 6.4. | 
|  | 1725 | # | 
|  | 1726 | #   vercmp_numbers 4.0 4.0 | 
|  | 1727 | # | 
|  | 1728 | # The above will return "0", as the versions are equal. | 
|  | 1729 | # | 
|  | 1730 | # vercmp_numbers ver1 ver2 | 
|  | 1731 | vercmp_numbers() { | 
|  | 1732 | typeset v1=$1 v2=$2 sep | 
|  | 1733 | typeset -a ver1 ver2 | 
|  | 1734 |  | 
|  | 1735 | IFS=. read -ra ver1 <<< "$v1" | 
|  | 1736 | IFS=. read -ra ver2 <<< "$v2" | 
|  | 1737 |  | 
|  | 1738 | _vercmp_r "${#ver1[@]}" "${ver1[@]}" "${ver2[@]}" | 
|  | 1739 | } | 
|  | 1740 |  | 
|  | 1741 |  | 
| Dean Troyer | 533e14d | 2013-08-30 15:11:22 -0500 | [diff] [blame] | 1742 | # ``policy_add policy_file policy_name policy_permissions`` | 
|  | 1743 | # | 
|  | 1744 | # Add a policy to a policy.json file | 
|  | 1745 | # Do nothing if the policy already exists | 
|  | 1746 |  | 
|  | 1747 | function policy_add() { | 
|  | 1748 | local policy_file=$1 | 
|  | 1749 | local policy_name=$2 | 
|  | 1750 | local policy_perm=$3 | 
|  | 1751 |  | 
|  | 1752 | if grep -q ${policy_name} ${policy_file}; then | 
|  | 1753 | echo "Policy ${policy_name} already exists in ${policy_file}" | 
|  | 1754 | return | 
|  | 1755 | fi | 
|  | 1756 |  | 
|  | 1757 | # Add a terminating comma to policy lines without one | 
|  | 1758 | # Remove the closing '}' and all lines following to the end-of-file | 
|  | 1759 | local tmpfile=$(mktemp) | 
|  | 1760 | uniq ${policy_file} | sed -e ' | 
|  | 1761 | s/]$/],/ | 
|  | 1762 | /^[}]/,$d | 
|  | 1763 | ' > ${tmpfile} | 
|  | 1764 |  | 
|  | 1765 | # Append policy and closing brace | 
|  | 1766 | echo "    \"${policy_name}\": ${policy_perm}" >>${tmpfile} | 
|  | 1767 | echo "}" >>${tmpfile} | 
|  | 1768 |  | 
|  | 1769 | mv ${tmpfile} ${policy_file} | 
|  | 1770 | } | 
|  | 1771 |  | 
|  | 1772 |  | 
| Salvatore Orlando | 05ae833 | 2013-08-20 14:51:08 -0700 | [diff] [blame] | 1773 | # This function sets log formatting options for colorizing log | 
|  | 1774 | # output to stdout. It is meant to be called by lib modules. | 
|  | 1775 | # The last two parameters are optional and can be used to specify | 
|  | 1776 | # non-default value for project and user format variables. | 
|  | 1777 | # Defaults are respectively 'project_name' and 'user_name' | 
|  | 1778 | # | 
|  | 1779 | # setup_colorized_logging something.conf SOMESECTION | 
|  | 1780 | function setup_colorized_logging() { | 
|  | 1781 | local conf_file=$1 | 
|  | 1782 | local conf_section=$2 | 
|  | 1783 | local project_var=${3:-"project_name"} | 
|  | 1784 | local user_var=${4:-"user_name"} | 
|  | 1785 | # Add color to logging output | 
|  | 1786 | iniset $conf_file $conf_section logging_context_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [[01;36m%(request_id)s [00;36m%("$user_var")s %("$project_var")s%(color)s] [01;35m%(instance)s%(color)s%(message)s[00m" | 
|  | 1787 | iniset $conf_file $conf_section logging_default_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [[00;36m-%(color)s] [01;35m%(instance)s%(color)s%(message)s[00m" | 
|  | 1788 | iniset $conf_file $conf_section logging_debug_format_suffix "[00;33mfrom (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d[00m" | 
|  | 1789 | iniset $conf_file $conf_section logging_exception_prefix "%(color)s%(asctime)s.%(msecs)03d TRACE %(name)s [01;35m%(instance)s[00m" | 
|  | 1790 | } | 
|  | 1791 |  | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 1792 | # Restore xtrace | 
| Chmouel Boudjnah | 408b009 | 2012-03-15 23:21:55 +0000 | [diff] [blame] | 1793 | $XTRACE | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 1794 |  | 
|  | 1795 |  | 
|  | 1796 | # Local variables: | 
| Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 1797 | # mode: shell-script | 
| Andrew Laski | f900bd7 | 2012-09-05 17:23:14 -0400 | [diff] [blame] | 1798 | # End: |