package: consolidate get_packages logic

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>
diff --git a/functions b/functions
index b94c611..11f7d50 100644
--- a/functions
+++ b/functions
@@ -117,20 +117,32 @@
 }
 
 
+function _get_package_dir() {
+    local pkg_dir
+    if is_ubuntu; then
+        pkg_dir=$FILES/apts
+    elif is_fedora; then
+        pkg_dir=$FILES/rpms
+    elif is_suse; then
+        pkg_dir=$FILES/rpms-suse
+    else
+        exit_distro_not_supported "list of packages"
+    fi
+    echo "$pkg_dir"
+}
+
 # get_packages() collects a list of package names of any type from the
 # prerequisite files in ``files/{apts|rpms}``.  The list is intended
 # to be passed to a package installer such as apt or yum.
 #
-# Only packages required for the services in ``ENABLED_SERVICES`` will be
+# Only packages required for the services in 1st argument will be
 # included.  Two bits of metadata are recognized in the prerequisite files:
 # - ``# NOPRIME`` defers installation to be performed later in stack.sh
 # - ``# dist:DISTRO`` or ``dist:DISTRO1,DISTRO2`` limits the selection
 #   of the package to the distros listed.  The distro names are case insensitive.
-#
-# Uses globals ``ENABLED_SERVICES``
-# get_packages dir
 function get_packages() {
-    local package_dir=$1
+    local services=$1
+    local package_dir=$(_get_package_dir)
     local file_to_parse
     local service
 
@@ -141,7 +153,7 @@
     if [[ -z "$DISTRO" ]]; then
         GetDistro
     fi
-    for service in general ${ENABLED_SERVICES//,/ }; do
+    for service in general ${services//,/ }; do
         # Allow individual services to specify dependencies
         if [[ -e ${package_dir}/${service} ]]; then
             file_to_parse="${file_to_parse} $service"