Browse code

Create tools/install_prereqs.sh

* Factor system package prereq installs out to tools/install_prereqs.sh
* Set minimum time between runs with PREREQ_RERUN_HOURS
default = 2 hours
* Create re_export_proxy_variables

Change-Id: I4a182b1da685f403d6abdd8540d2114796c01682

Dean Troyer authored on 2012/12/13 03:50:38
Showing 3 changed files
... ...
@@ -710,6 +710,27 @@ function restart_service() {
710 710
 }
711 711
 
712 712
 
713
+# HTTP and HTTPS proxy servers are supported via the usual environment variables [1]
714
+# ``http_proxy``, ``https_proxy`` and ``no_proxy``. They can be set in
715
+# ``localrc`` or on the command line if necessary::
716
+#
717
+# [1] http://www.w3.org/Daemon/User/Proxies/ProxyClients.html
718
+#
719
+#     http_proxy=http://proxy.example.com:3128/ no_proxy=repo.example.net ./stack.sh
720
+
721
+function re_export_proxy_variables() {
722
+    if [[ -n "$http_proxy" ]]; then
723
+        export http_proxy=$http_proxy
724
+    fi
725
+    if [[ -n "$https_proxy" ]]; then
726
+        export https_proxy=$https_proxy
727
+    fi
728
+    if [[ -n "$no_proxy" ]]; then
729
+        export no_proxy=$no_proxy
730
+    fi
731
+}
732
+
733
+
713 734
 # Helper to launch a service in a named screen
714 735
 # screen_it service "command-line"
715 736
 function screen_it {
... ...
@@ -644,25 +644,7 @@ set -o xtrace
644 644
 
645 645
 # Install package requirements
646 646
 echo_summary "Installing package prerequisites"
647
-if is_ubuntu; then
648
-    install_package $(get_packages $FILES/apts)
649
-elif is_fedora; then
650
-    install_package $(get_packages $FILES/rpms)
651
-elif is_suse; then
652
-    install_package $(get_packages $FILES/rpms-suse)
653
-else
654
-    exit_distro_not_supported "list of packages"
655
-fi
656
-
657
-if [[ $SYSLOG != "False" ]]; then
658
-    if is_ubuntu || is_fedora; then
659
-        install_package rsyslog-relp
660
-    elif is_suse; then
661
-        install_package rsyslog-module-relp
662
-    else
663
-        exit_distro_not_supported "rsyslog-relp installation"
664
-    fi
665
-fi
647
+$TOP_DIR/tools/install_prereqs.sh
666 648
 
667 649
 if is_service_enabled rabbit; then
668 650
     # Install rabbitmq-server
669 651
new file mode 100755
... ...
@@ -0,0 +1,78 @@
0
+#!/usr/bin/env bash
1
+
2
+# **install_prereqs.sh**
3
+
4
+# Install system package prerequisites
5
+#
6
+# install_prereqs.sh [-f]
7
+#
8
+# -f        Force an install run now
9
+
10
+
11
+if [[ -n "$1" &&  "$1" = "-f" ]]; then
12
+    FORCE=1
13
+fi
14
+
15
+# Keep track of the devstack directory
16
+TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
17
+
18
+# Import common functions
19
+source $TOP_DIR/functions
20
+
21
+# Determine what system we are running on.  This provides ``os_VENDOR``,
22
+# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
23
+# and ``DISTRO``
24
+GetDistro
25
+
26
+# Needed to get ``ENABLED_SERVICES``
27
+source $TOP_DIR/stackrc
28
+
29
+# Prereq dirs are here
30
+FILES=$TOP_DIR/files
31
+
32
+# Minimum wait time
33
+PREREQ_RERUN_MARKER=${PREREQ_RERUN_MARKER:-$TOP_DIR/.prereqs}
34
+PREREQ_RERUN_HOURS=${PREREQ_RERUN_HOURS:-2}
35
+PREREQ_RERUN_SECONDS=$((60*60*$PREREQ_RERUN_HOURS))
36
+
37
+NOW=$(date "+%s")
38
+LAST_RUN=$(head -1 $PREREQ_RERUN_MARKER 2>/dev/null || echo "0")
39
+DELTA=$(($NOW - $LAST_RUN))
40
+if [[ $DELTA -lt $PREREQ_RERUN_SECONDS && -z "$FORCE" ]]; then
41
+    echo "Re-run time has not expired ($(($PREREQ_RERUN_SECONDS - $DELTA)) seconds remaining); exiting..."
42
+    exit 0
43
+fi
44
+
45
+# Make sure the proxy config is visible to sub-processes
46
+re_export_proxy_variables
47
+
48
+# Install Packages
49
+# ================
50
+
51
+# Install package requirements
52
+if is_ubuntu; then
53
+    install_package $(get_packages $FILES/apts)
54
+elif is_fedora; then
55
+    install_package $(get_packages $FILES/rpms)
56
+elif is_suse; then
57
+    install_package $(get_packages $FILES/rpms-suse)
58
+else
59
+    exit_distro_not_supported "list of packages"
60
+fi
61
+
62
+if [[ -n "$SYSLOG" && "$SYSLOG" != "False" ]]; then
63
+    if is_ubuntu || is_fedora; then
64
+        install_package rsyslog-relp
65
+    elif is_suse; then
66
+        install_package rsyslog-module-relp
67
+    else
68
+        exit_distro_not_supported "rsyslog-relp installation"
69
+    fi
70
+fi
71
+
72
+
73
+# Mark end of run
74
+# ---------------
75
+
76
+date "+%s" >$PREREQ_RERUN_MARKER
77
+date >>$PREREQ_RERUN_MARKER