@@ -73,6 +73,91 @@ function get_field() {
7373}
7474
7575
76+ # get_packages() collects a list of package names of any type from the
77+ # prerequisite files in ``files/{apts|pips}``. The list is intended
78+ # to be passed to a package installer such as apt or pip.
79+ #
80+ # Only packages required for the services in ENABLED_SERVICES will be
81+ # included. Two bits of metadata are recognized in the prerequisite files:
82+ # - ``# NOPRIME`` defers installation to be performed later in stack.sh
83+ # - ``# dist:DISTRO`` or ``dist:DISTRO1,DISTRO2`` limits the selection
84+ # of the package to the distros listed. The distro names are case insensitive.
85+ #
86+ # get_packages dir
87+ function get_packages() {
88+ local package_dir=$1
89+ local file_to_parse
90+ local service
91+
92+ if [[ -z "$package_dir" ]]; then
93+ echo "No package directory supplied"
94+ return 1
95+ fi
96+ if [[ -z "$DISTRO" ]]; then
97+ echo "No distro set in DISTRO"
98+ return 1
99+ fi
100+ for service in general ${ENABLED_SERVICES//,/ }; do
101+ # Allow individual services to specify dependencies
102+ if [[ -e ${package_dir}/${service} ]]; then
103+ file_to_parse="${file_to_parse} $service"
104+ fi
105+ # NOTE(sdague) n-api needs glance for now because that's where
106+ # glance client is
107+ if [[ $service == n-api ]]; then
108+ if [[ ! $file_to_parse =~ nova ]]; then
109+ file_to_parse="${file_to_parse} nova"
110+ fi
111+ if [[ ! $file_to_parse =~ glance ]]; then
112+ file_to_parse="${file_to_parse} glance"
113+ fi
114+ elif [[ $service == c-* ]]; then
115+ if [[ ! $file_to_parse =~ cinder ]]; then
116+ file_to_parse="${file_to_parse} cinder"
117+ fi
118+ elif [[ $service == n-* ]]; then
119+ if [[ ! $file_to_parse =~ nova ]]; then
120+ file_to_parse="${file_to_parse} nova"
121+ fi
122+ elif [[ $service == g-* ]]; then
123+ if [[ ! $file_to_parse =~ glance ]]; then
124+ file_to_parse="${file_to_parse} glance"
125+ fi
126+ elif [[ $service == key* ]]; then
127+ if [[ ! $file_to_parse =~ keystone ]]; then
128+ file_to_parse="${file_to_parse} keystone"
129+ fi
130+ fi
131+ done
132+
133+ for file in ${file_to_parse}; do
134+ local fname=${package_dir}/${file}
135+ local OIFS line package distros distro
136+ [[ -e $fname ]] || continue
137+
138+ OIFS=$IFS
139+ IFS=$'\n'
140+ for line in $(<${fname}); do
141+ if [[ $line =~ "NOPRIME" ]]; then
142+ continue
143+ fi
144+
145+ if [[ $line =~ (.*)#.*dist:([^ ]*) ]]; then
146+ # We are using BASH regexp matching feature.
147+ package=${BASH_REMATCH[1]}
148+ distros=${BASH_REMATCH[2]}
149+ # In bash ${VAR,,} will lowecase VAR
150+ [[ ${distros,,} =~ ${DISTRO,,} ]] && echo $package
151+ continue
152+ fi
153+
154+ echo ${line%#*}
155+ done
156+ IFS=$OIFS
157+ done
158+ }
159+
160+
76161# Determine OS Vendor, Release and Update
77162# Tested with OS/X, Ubuntu, RedHat, CentOS, Fedora
78163# Returns results in global variables:
0 commit comments