Refactor get_package logic.
With this refactoring, code like
"if is_ubuntu; then install_package xxx elif is_fedora..."
can be simplified later.
Change-Id: I489bfd4cc12cc6b0b8201837f2bfb78c6881c82c
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
| ... | ... |
@@ -117,20 +117,32 @@ function get_field() {
|
| 117 | 117 |
} |
| 118 | 118 |
|
| 119 | 119 |
|
| 120 |
+function _get_package_dir() {
|
|
| 121 |
+ local pkg_dir |
|
| 122 |
+ if is_ubuntu; then |
|
| 123 |
+ pkg_dir=$FILES/apts |
|
| 124 |
+ elif is_fedora; then |
|
| 125 |
+ pkg_dir=$FILES/rpms |
|
| 126 |
+ elif is_suse; then |
|
| 127 |
+ pkg_dir=$FILES/rpms-suse |
|
| 128 |
+ else |
|
| 129 |
+ exit_distro_not_supported "list of packages" |
|
| 130 |
+ fi |
|
| 131 |
+ echo "$pkg_dir" |
|
| 132 |
+} |
|
| 133 |
+ |
|
| 120 | 134 |
# get_packages() collects a list of package names of any type from the |
| 121 | 135 |
# prerequisite files in ``files/{apts|rpms}``. The list is intended
|
| 122 | 136 |
# to be passed to a package installer such as apt or yum. |
| 123 | 137 |
# |
| 124 |
-# Only packages required for the services in ``ENABLED_SERVICES`` will be |
|
| 138 |
+# Only packages required for the services in 1st argument will be |
|
| 125 | 139 |
# included. Two bits of metadata are recognized in the prerequisite files: |
| 126 | 140 |
# - ``# NOPRIME`` defers installation to be performed later in stack.sh |
| 127 | 141 |
# - ``# dist:DISTRO`` or ``dist:DISTRO1,DISTRO2`` limits the selection |
| 128 | 142 |
# of the package to the distros listed. The distro names are case insensitive. |
| 129 |
-# |
|
| 130 |
-# Uses globals ``ENABLED_SERVICES`` |
|
| 131 |
-# get_packages dir |
|
| 132 | 143 |
function get_packages() {
|
| 133 |
- local package_dir=$1 |
|
| 144 |
+ local services=$1 |
|
| 145 |
+ local package_dir=$(_get_package_dir) |
|
| 134 | 146 |
local file_to_parse |
| 135 | 147 |
local service |
| 136 | 148 |
|
| ... | ... |
@@ -141,7 +153,7 @@ function get_packages() {
|
| 141 | 141 |
if [[ -z "$DISTRO" ]]; then |
| 142 | 142 |
GetDistro |
| 143 | 143 |
fi |
| 144 |
- for service in general ${ENABLED_SERVICES//,/ }; do
|
|
| 144 |
+ for service in general ${services//,/ }; do
|
|
| 145 | 145 |
# Allow individual services to specify dependencies |
| 146 | 146 |
if [[ -e ${package_dir}/${service} ]]; then
|
| 147 | 147 |
file_to_parse="${file_to_parse} $service"
|
| ... | ... |
@@ -88,17 +88,7 @@ done |
| 88 | 88 |
# - We are going to check packages only for the services needed. |
| 89 | 89 |
# - We are parsing the packages files and detecting metadatas. |
| 90 | 90 |
|
| 91 |
-if is_ubuntu; then |
|
| 92 |
- PKG_DIR=$FILES/apts |
|
| 93 |
-elif is_fedora; then |
|
| 94 |
- PKG_DIR=$FILES/rpms |
|
| 95 |
-elif is_suse; then |
|
| 96 |
- PKG_DIR=$FILES/rpms-suse |
|
| 97 |
-else |
|
| 98 |
- exit_distro_not_supported "list of packages" |
|
| 99 |
-fi |
|
| 100 |
- |
|
| 101 |
-for p in $(get_packages $PKG_DIR); do |
|
| 91 |
+for p in $(get_packages $ENABLED_SERVICES); do |
|
| 102 | 92 |
if [[ "$os_PACKAGE" = "deb" ]]; then |
| 103 | 93 |
ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2) |
| 104 | 94 |
elif [[ "$os_PACKAGE" = "rpm" ]]; then |
| ... | ... |
@@ -54,15 +54,7 @@ export_proxy_variables |
| 54 | 54 |
# ================ |
| 55 | 55 |
|
| 56 | 56 |
# Install package requirements |
| 57 |
-if is_ubuntu; then |
|
| 58 |
- install_package $(get_packages $FILES/apts) |
|
| 59 |
-elif is_fedora; then |
|
| 60 |
- install_package $(get_packages $FILES/rpms) |
|
| 61 |
-elif is_suse; then |
|
| 62 |
- install_package $(get_packages $FILES/rpms-suse) |
|
| 63 |
-else |
|
| 64 |
- exit_distro_not_supported "list of packages" |
|
| 65 |
-fi |
|
| 57 |
+install_package $(get_packages $ENABLED_SERVICES) |
|
| 66 | 58 |
|
| 67 | 59 |
if [[ -n "$SYSLOG" && "$SYSLOG" != "False" ]]; then |
| 68 | 60 |
if is_ubuntu || is_fedora; then |