Browse code

Add OFFLINE support to allow stack.sh to run cleanly without Internet access after having initialized /opt/stack with access. Good for those long flights on a Friday night.

Change-Id: If97c22eef91bbd88aed644f05c56bf815036e78f

Dean Troyer authored on 2011/12/17 13:40:46
Showing 1 changed files
... ...
@@ -82,6 +82,7 @@ DEST=${DEST:-/opt/stack}
82 82
 
83 83
 # apt-get wrapper to just get arguments set correctly
84 84
 function apt_get() {
85
+    [[ "$OFFLINE" = "True" ]] && return
85 86
     local sudo="sudo"
86 87
     [ "$(id -u)" = "0" ] && sudo="env"
87 88
     $sudo DEBIAN_FRONTEND=noninteractive apt-get \
... ...
@@ -147,6 +148,23 @@ else
147 147
     sudo mv $TEMPFILE /etc/sudoers.d/stack_sh_nova
148 148
 fi
149 149
 
150
+# Normalize config values to True or False
151
+# VAR=`trueorfalse default-value test-value`
152
+function trueorfalse() {
153
+    local default=$1
154
+    local testval=$2
155
+
156
+    [[ -z "$testval" ]] && { echo "$default"; return; }
157
+    [[ "0 no false False FALSE" =~ "$testval" ]] && { echo "False"; return; }
158
+    [[ "1 yes true True TRUE" =~ "$testval" ]] && { echo "True"; return; }
159
+    echo "$default"
160
+}
161
+
162
+# Set True to configure stack.sh to run cleanly without Internet access.
163
+# stack.sh must have been previously run with Internet access to install
164
+# prerequisites and initialize $DEST.
165
+OFFLINE=`trueorfalse False $OFFLINE`
166
+
150 167
 # Set the destination directories for openstack projects
151 168
 NOVA_DIR=$DEST/nova
152 169
 HORIZON_DIR=$DEST/horizon
... ...
@@ -196,18 +214,6 @@ if [ ! -n "$HOST_IP" ]; then
196 196
     fi
197 197
 fi
198 198
 
199
-# Normalize config values to True or False
200
-# VAR=`trueorfalse default-value test-value`
201
-function trueorfalse() {
202
-    local default=$1
203
-    local testval=$2
204
-
205
-    [[ -z "$testval" ]] && { echo "$default"; return; }
206
-    [[ "0 no false False FALSE" =~ "$testval" ]] && { echo "False"; return; }
207
-    [[ "1 yes true True TRUE" =~ "$testval" ]] && { echo "True"; return; }
208
-    echo "$default"
209
-}
210
-
211 199
 # Configure services to syslog instead of writing to individual log files
212 200
 SYSLOG=`trueorfalse False $SYSLOG`
213 201
 SYSLOG_HOST=${SYSLOG_HOST:-$HOST_IP}
... ...
@@ -460,17 +466,23 @@ function get_packages() {
460 460
     done
461 461
 }
462 462
 
463
+function pip_install {
464
+    [[ "$OFFLINE" = "True" ]] && return
465
+    sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install --use-mirrors $@
466
+}
467
+
463 468
 # install apt requirements
464 469
 apt_get update
465 470
 apt_get install $(get_packages)
466 471
 
467 472
 # install python requirements
468
-sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install --use-mirrors `cat $FILES/pips/*`
473
+pip_install `cat $FILES/pips/* | uniq`
469 474
 
470 475
 # git clone only if directory doesn't exist already.  Since ``DEST`` might not
471 476
 # be owned by the installation user, we create the directory and change the
472 477
 # ownership to the proper user.
473 478
 function git_clone {
479
+    [[ "$OFFLINE" = "True" ]] && return
474 480
 
475 481
     GIT_REMOTE=$1
476 482
     GIT_DEST=$2