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>
This commit is contained in:
parent
555ecd07b0
commit
8c43809ef6
24
functions
24
functions
@ -117,20 +117,32 @@ function get_field() {
|
||||
}
|
||||
|
||||
|
||||
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 @@ function get_packages() {
|
||||
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"
|
||||
|
@ -88,17 +88,7 @@ done
|
||||
# - We are going to check packages only for the services needed.
|
||||
# - We are parsing the packages files and detecting metadatas.
|
||||
|
||||
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
|
||||
|
||||
for p in $(get_packages $PKG_DIR); do
|
||||
for p in $(get_packages $ENABLED_SERVICES); do
|
||||
if [[ "$os_PACKAGE" = "deb" ]]; then
|
||||
ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2)
|
||||
elif [[ "$os_PACKAGE" = "rpm" ]]; then
|
||||
|
@ -54,15 +54,7 @@ export_proxy_variables
|
||||
# ================
|
||||
|
||||
# Install package requirements
|
||||
if is_ubuntu; then
|
||||
install_package $(get_packages $FILES/apts)
|
||||
elif is_fedora; then
|
||||
install_package $(get_packages $FILES/rpms)
|
||||
elif is_suse; then
|
||||
install_package $(get_packages $FILES/rpms-suse)
|
||||
else
|
||||
exit_distro_not_supported "list of packages"
|
||||
fi
|
||||
install_package $(get_packages $ENABLED_SERVICES)
|
||||
|
||||
if [[ -n "$SYSLOG" && "$SYSLOG" != "False" ]]; then
|
||||
if is_ubuntu || is_fedora; then
|
||||
|
Loading…
Reference in New Issue
Block a user