diff options
author | Taka Cho <takamune.cho@att.com> | 2020-11-12 17:48:30 -0500 |
---|---|---|
committer | Taka Cho <takamune.cho@att.com> | 2020-11-30 10:20:55 -0500 |
commit | 8583b5150f8ccf3a1d1b0e4849346024763aa838 (patch) | |
tree | f36885b89485b2144c0ab287fe9f06fbdfcb5cd8 /policy-management/src/main/server-gen/bin/features | |
parent | dc6c4a21d46909dad59f4bd16cb6d4fc29fcce77 (diff) |
move all bash to ash shell scripts
this gerrit would be the first step
to not to use any GPL-3.0 and plus license
Issue-ID: POLICY-2847
Change-Id: I09a571f14ef8c6983f9051068c2bad5acc173787
Signed-off-by: Taka Cho <takamune.cho@att.com>
Diffstat (limited to 'policy-management/src/main/server-gen/bin/features')
-rw-r--r-- | policy-management/src/main/server-gen/bin/features | 1783 |
1 files changed, 883 insertions, 900 deletions
diff --git a/policy-management/src/main/server-gen/bin/features b/policy-management/src/main/server-gen/bin/features index 2646c04d..fc1f239f 100644 --- a/policy-management/src/main/server-gen/bin/features +++ b/policy-management/src/main/server-gen/bin/features @@ -1,17 +1,17 @@ -#!/usr/bin/env bash +#!/usr/bin/env ash ### # ============LICENSE_START======================================================= # ONAP POLICY # ================================================================================ -# Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. +# Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -115,10 +115,10 @@ # in the pdp-d migration directory ($POLICY_HOME/etc/db/migration). # 6. cd to the feature 'install' directory an executes (if exists) the 'disable' script to allow for specific # customizations for this feature. -# +# # Notes for DB enabled features: -# A. Upgrade/Downgrade SQL File Name Format: -# <VERSION>-<pdp|feature-name>[-description](.upgrade|.downgrade).sql +# A. Upgrade/Downgrade SQL File Name Format: +# <VERSION>-<pdp|feature-name>[-description](.upgrade|.downgrade).sql # B. See related tooling: db-migrator, deploy-artifact, and policy # # Example: @@ -145,11 +145,11 @@ # L─ feature-healthcheck-1.1.0-SNAPSHOT.jar # ############################################################# -if [[ ${DEBUG} == y ]]; then - echo "-- MAIN --" - set -x +if [ "${DEBUG}" = "y" ]; then + echo "-- MAIN --" + set -x fi - + # The directories at play LIB=${POLICY_HOME}/lib @@ -158,21 +158,21 @@ BIN=${POLICY_HOME}/bin DB=${POLICY_HOME}/etc/db/migration FEATURES=${POLICY_HOME}/features -if [[ ! ( -d "${LIB}" && -x "${LIB}" ) ]]; then - echo "error: no ${LIB} directory" - exit 1 +if [ ! -d "${LIB}" ]; then + echo "error: no ${LIB} directory" + exit 1 fi -if [[ ! ( -d "${CONFIG}" && -x "${CONFIG}" ) ]]; then - echo "error: no ${CONFIG} directory" - exit 2 +if [ ! -d "${CONFIG}" ]; then + echo "error: no ${CONFIG} directory" + exit 2 fi # ensure that the directory exists mkdir -p "${FEATURES}" 2> /dev/null -if [[ ! -d "${DB}" ]]; then - mkdir -p "${DB}" +if [ ! -d "${DB}" ]; then + mkdir -p "${DB}" fi # relative per Feature Directory Paths @@ -197,25 +197,25 @@ versionLength=15 # update field lengths, if needed for jar in ${featureJars} ; do - # get file name without 'jar' suffix - tmp="${jar%\.jar}" - - # remove feature prefix - tmp="${tmp#feature-}" - - # get feature name by removing the version portion - name="${tmp%%-[0-9]*}" - - # extract version portion of name - version="${tmp#${name}-}" - - # grow the size of the name/version field, if needed - if (( "${#name}" > nameLength )) ; then - nameLength="${#name}" - fi - if (( "${#version}" > versionLength )) ; then - versionLength="${#version}" - fi + # get file name without 'jar' suffix + tmp="${jar%\.jar}" + + # remove feature prefix + tmp="${tmp#feature-}" + + # get feature name by removing the version portion + name="${tmp%%-[0-9]*}" + + # extract version portion of name + version="${tmp#${name}-}" + + # grow the size of the name/version field, if needed + if [ ${#name} -gt $nameLength ] ; then + nameLength=${#name} + fi + if [ ${#version} -gt $versionLength ] ; then + versionLength=${#version} + fi done # ########################################################## @@ -238,121 +238,121 @@ function usage EOF } + # ########################################################## # status: dump out status information # ########################################################## function status { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi - - local tmp name version status - local format="%-${nameLength}s %-${versionLength}s %s\n" - - printf "${format}" "name" "version" "status" - printf "${format}" "----" "-------" "------" - - for jar in ${featureJars} ; do - # get file name without 'jar' suffix - tmp="${jar%\.jar}" - - # remove feature prefix - tmp="${tmp#feature-}" - - # get feature name by removing the version portion - name="${tmp%%-[0-9]*}" - - # extract version portion of name - version="${tmp#${name}-}" - - # determine status - status=disabled - if [[ -e "${LIB}/${jar}" ]] ; then - status=enabled - fi - printf "${format}" "${name}" "${version}" "${status}" - done - echo + if [ "${DEBUG}" = "y" ]; then + echo "-- status --" + set -x + fi + + local tmp name version status + local format="%-${nameLength}s %-${versionLength}s %s\n" + + printf "${format}" "name" "version" "status" + printf "${format}" "----" "-------" "------" + + for jar in ${featureJars} ; do + # get file name without 'jar' suffix + tmp="${jar%\.jar}" + + # remove feature prefix + tmp="${tmp#feature-}" + + # get feature name by removing the version portion + name="${tmp%%-[0-9]*}" + + # extract version portion of name + version="${tmp#${name}-}" + + # determine status + status=disabled + if [ -e "${LIB}/${jar}" ] ; then + status=enabled + fi + printf "${format}" "${name}" "${version}" "${status}" + done + echo } # ########################################################## -# enableDepAnalysis (featureName): +# enableDepAnalysis (featureName): # reports on potential dependency conflicts # featureName: name of the feature # ########################################################## function enableDepAnalysis () { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureDepJars featureDepJarPath depJarName multiVersionJars - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureDepJars=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) - for featureDepJarPath in ${featureDepJars}; do - depJarName=$(basename "${featureDepJarPath}") - - # it could be a base jar - - if [[ -f "${LIB}"/"${depJarName}" ]]; then - echo "warning: dependency ${depJarName} already in use" - continue - fi - - # it could be a link from another feature - - if [[ -L "${LIB}"/"${depJarName}" ]]; then - continue - fi - - # unadvisable if multiple versions exist but the base or - # installed one wins. - - multiVersionJars=$(ls "${LIB}"/"${depJarName%%-[0-9]*.jar}"-*.jar 2> /dev/null) - if [[ -n "${multiVersionJars}" ]]; then - echo "warning: other version of library ${depJarName} present: ${multiVersionJars}" - continue - fi - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableDepAnalysis $* --" + set -x + fi + + local featureName="$1" + local featureDepJars featureDepJarPath depJarName multiVersionJars + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + fi + + featureDepJars=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) + for featureDepJarPath in ${featureDepJars}; do + depJarName=$(basename "${featureDepJarPath}") + + # it could be a base jar + + if [ -f "${LIB}"/"${depJarName}" ]; then + echo "warning: dependency ${depJarName} already in use" + continue + fi + + # it could be a link from another feature + + if [ -L "${LIB}"/"${depJarName}" ]; then + continue + fi + + # unadvisable if multiple versions exist but the base or + # installed one wins. + + multiVersionJars=$(ls "${LIB}"/"${depJarName%%-[0-9]*.jar}"-*.jar 2> /dev/null) + if [ -n "${multiVersionJars}" ]; then + echo "warning: other version of library ${depJarName} present: ${multiVersionJars}" + continue + fi + done } # ########################################################## -# enableConfigAnalysis (featureName): +# enableConfigAnalysis (featureName): # reports on potential dependency conflicts # featureName: name of the feature # ########################################################## function enableConfigAnalysis () { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureConfigs configPath configFileName - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureConfigs=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ 2> /dev/null) - for configPath in ${featureConfigs}; do - configFileName=$(basename "${configPath}") - if [[ -e "${CONFIG}"/"${configFileName}" ]]; then - echo "error: a config file of the same name is already in the base installation: ${configFileName}" - return 2 - fi - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableConfigAnalysis $* --" + set -x + fi + + local featureName="$1" + local featureConfigs configPath configFileName + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureConfigs=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ 2> /dev/null) + for configPath in ${featureConfigs}; do + configFileName=$(basename "${configPath}") + if [ -e "${CONFIG}"/"${configFileName}" ]; then + echo "error: a config file of the same name is already in the base installation: ${configFileName}" + return 2 + fi + done } # ########################################################## @@ -362,232 +362,230 @@ function enableConfigAnalysis () # ########################################################## function enableBinAnalysis () { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureBins binPath binFileName - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureBins=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ 2> /dev/null) - for binPath in ${featureBins}; do - binFileName=$(basename "${binPath}") - if [[ -e "${CONFIG}"/"${binFileName}" ]]; then - echo "error: a bin file of the same name is already in the base installation: ${binFileName}" - return 2 - fi - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableBinAnalysis $* --" + set -x + fi + + local featureName="$1" + local featureBins binPath binFileName + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureBins=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ 2> /dev/null) + for binPath in ${featureBins}; do + binFileName=$(basename "${binPath}") + if [ -e "${CONFIG}"/"${binFileName}" ]; then + echo "error: a bin file of the same name is already in the base installation: ${binFileName}" + return 2 + fi + done } # ########################################################## -# enableDbAnalysis (featureName): +# enableDbAnalysis (featureName): # reports on potential db access problems # featureName: name of the feature # ########################################################## function enableDbAnalysis() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureSqls - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureSqls=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/${FEATURE_SQL}/*${UPGRADE_SQL_SUFFIX} 2> /dev/null) - if [[ -z ${featureSqls} ]]; then - return 0 - fi - - source "${POLICY_HOME}"/etc/profile.d/env.sh - if [[ -z ${SQL_HOST} ]] || [[ -z ${SQL_USER} ]] || [[ -z ${SQL_PASSWORD} ]]; then - echo "warning: DB server is not configured" - fi - - return 0 + if [ "${DEBUG}" = "y" ]; then + echo "-- enableDbAnalysis $* --" + set -x + fi + + local featureName="$1" + local featureSqls + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureSqls=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/${FEATURE_SQL}/*${UPGRADE_SQL_SUFFIX} 2> /dev/null) + if [ -z "${featureSqls}" ]; then + return 0 + fi + + source "${POLICY_HOME}"/etc/profile.d/env.sh + if [ -z "${SQL_HOST}" ] || [ -z "${SQL_USER}" ] || [ -z "${SQL_PASSWORD}" ]; then + echo "warning: DB server is not configured" + fi + + return 0 } # ########################################################## -# enableFeatureDeps(featureName): +# enableFeatureDeps(featureName): # enables feature dependencies # featureName: name of the feature # ########################################################## function enableFeatureDeps() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureDeps featureDepPath depJarName - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureDeps=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) - for featureDepPath in ${featureDeps}; do - depJarName=$(basename "${featureDepPath}") - if [[ ! -f "${LIB}"/"${depJarName}" ]]; then - ln -s -f "${featureDepPath}" "${LIB}/" - fi - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableFeatureDeps $* --" + set -x + fi + + local featureName="$1" + local featureDeps featureDepPath depJarName + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureDeps=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) + for featureDepPath in ${featureDeps}; do + depJarName=$(basename "${featureDepPath}") + if [ ! -f "${LIB}"/"${depJarName}" ]; then + ln -s -f "${featureDepPath}" "${LIB}/" + fi + done } # ########################################################## -# enableFeatureConfig(featureName): +# enableFeatureConfig(featureName): # enables feature configuration # featureName: name of the feature # ########################################################## function enableFeatureConfig() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureConfigs featureConfigPath - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureConfigs=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ -type f -maxdepth 1 2> /dev/null) - for featureConfigPath in ${featureConfigs}; do - ln -s -f "${featureConfigPath}" "${CONFIG}/" - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableFeatureConfig $* --" + set -x + fi + + local featureName="$1" + local featureConfigs featureConfigPath + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureConfigs=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ -type f -maxdepth 1 2> /dev/null) + for featureConfigPath in ${featureConfigs}; do + ln -s -f "${featureConfigPath}" "${CONFIG}/" + done } # ########################################################## -# enableFeatureBin(featureName): -# enables feature binaries +# enableFeatureBin(featureName): enables feature binaries # featureName: name of the feature # ########################################################## function enableFeatureBin() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureBins featureBinPath - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureBins=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ -type f -maxdepth 1 2> /dev/null) - for featureBinPath in ${featureBins}; do - chmod u+x "${featureBinPath}" - ln -s -f "${featureBinPath}" "${BIN}/" - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableFeatureBin $* --" + set -x + fi + + local featureName="$1" + local featureBins featureBinPath + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureBins=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ -type f -maxdepth 1 2> /dev/null) + for featureBinPath in ${featureBins}; do + chmod u+x "${featureBinPath}" + ln -s -f "${featureBinPath}" "${BIN}/" + done } # ########################################################## -# enableFeatureDbSchema(featureName): +# enableFeatureDbSchema(featureName): # enables feature DB Schema configuration # featureName: name of the feature # ########################################################## function enableFeatureDbSchema() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureDbPath="$2" - local schemaName="$3" - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - if [[ -z ${featureDbPath} ]]; then - echo "warning: ${featureName} contains no DB path" - return 2 - fi - - if [[ -z ${schemaName} ]]; then - echo "warning: feature ${featureName} contains no schema name" - return 3 - fi - - rc=0 - sqlUpgradeScripts=$(ls "${featureDbPath%/}"/${FEATURE_SQL}/*${UPGRADE_SQL_SUFFIX} 2> /dev/null) - for sqlUpgradeScript in ${sqlUpgradeScripts}; do - if [[ ! -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]]; then - mkdir -p "${DB}"/"${schemaName}"/${FEATURE_SQL} 2> /dev/null - fi - ln -s -f "${sqlUpgradeScript}" "${DB}"/"${schemaName}"/${FEATURE_SQL}/ - done - - sqlDowngradeScripts=$(ls "${featureDbPath%/}"/${FEATURE_SQL}/*${DOWNGRADE_SQL_SUFFIX} 2> /dev/null) - for sqlDowngradeScript in ${sqlDowngradeScripts}; do - if [[ -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]]; then - sqlName=$(basename "${sqlDowngradeScript}") - rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null - else - echo "warning: feature ${featureName} only contains downgrade scripts" - rc=4 - break - fi - done - - if [[ -n ${sqlUpgradeScripts} || -n ${sqlDowngradeScripts} ]]; then - DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok - fi - - return ${rc} + if [ "${DEBUG}" = "y" ]; then + echo "-- enableFeatureDbSchema $* --" + set -x + fi + + local featureName="$1" + local featureDbPath="$2" + local schemaName="$3" + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + if [ -z "${featureDbPath}" ]; then + echo "warning: ${featureName} contains no DB path" + return 2 + fi + + if [ -z "${schemaName}" ]; then + echo "warning: feature ${featureName} contains no schema name" + return 3 + fi + + rc=0 + sqlUpgradeScripts=$(ls "${featureDbPath%/}"/${FEATURE_SQL}/*${UPGRADE_SQL_SUFFIX} 2> /dev/null) + for sqlUpgradeScript in ${sqlUpgradeScripts}; do + if [ ! -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]; then + mkdir -p "${DB}"/"${schemaName}"/${FEATURE_SQL} 2> /dev/null + fi + ln -s -f "${sqlUpgradeScript}" "${DB}"/"${schemaName}"/${FEATURE_SQL}/ + done + + sqlDowngradeScripts=$(ls "${featureDbPath%/}"/${FEATURE_SQL}/*${DOWNGRADE_SQL_SUFFIX} 2> /dev/null) + for sqlDowngradeScript in ${sqlDowngradeScripts}; do + if [ -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]; then + sqlName=$(basename "${sqlDowngradeScript}") + rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null + else + echo "warning: feature ${featureName} only contains downgrade scripts" + rc=4 + break + fi + done + + if [ -n "${sqlUpgradeScripts}" ] || [ -n "${sqlDowngradeScripts}" ]; then + DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok + fi + + return ${rc} } # ########################################################## -# enableFeatureDb(featureName): +# enableFeatureDb(featureName): # enables DB feature configuration # featureName: name of the feature # ########################################################## function enableFeatureDb() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureDbs featureDbPath schemaName sqls - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureDbs=$(ls -d "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/ 2> /dev/null) - for featureDbPath in ${featureDbs}; do - sqls=$(ls "${featureDbPath%/}"/"${FEATURE_SQL}"/*.sql 2> /dev/null) - if [[ -z ${sqls} ]]; then - continue - fi - schemaName=$(basename "${featureDbPath%/}") - enableFeatureDbSchema "${featureName}" "${featureDbPath%/}" "${schemaName}" - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableFeatureDb $* --" + set -x + fi + + local featureName="$1" + local featureDbs featureDbPath schemaName sqls + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureDbs=$(ls -d "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/ 2> /dev/null) + for featureDbPath in ${featureDbs}; do + sqls=$(ls "${featureDbPath%/}"/"${FEATURE_SQL}"/*.sql 2> /dev/null) + if [ -z "${sqls}" ]; then + continue + fi + schemaName=$(basename "${featureDbPath%/}") + enableFeatureDbSchema "${featureName}" "${featureDbPath%/}" "${schemaName}" + done } # ########################################################## @@ -597,61 +595,59 @@ function enableFeatureDb() # ########################################################## function enableFeatureArtifacts() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local artifacts - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - artifacts=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_ARTIFACTS}"/* 2> /dev/null) - for artifactPath in ${artifacts}; do - deploy-artifact -l -a "${artifactPath}" - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableFeatureArtifacts $* --" + set -x + fi + + local featureName="$1" + local artifacts + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + artifacts=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_ARTIFACTS}"/* 2> /dev/null) + for artifactPath in ${artifacts}; do + deploy-artifact -l -a "${artifactPath}" + done } # ########################################################## -# customize(featureName): -# executes customized script for an operation. +# customize(featureName): +# executes customized script for an operation. # # featureName - feature name -# operation - operation, ie. +# operation - operation, ie. # 'enable', 'disable', 'install', or 'uninstall' # ########################################################## function customOpScript() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local operation="$2" - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - if [[ -z ${operation} ]]; then - echo "warning: ${featureName} : a custom operation script must be provided" - return 1 - fi - - local customScript="${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}"/"${operation}" - if [[ -f ${customScript} ]]; then - ( - cd "${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}" - chmod u+x "${customScript}" - ./"$(basename "${customScript}")" - ) - fi + if [ "${DEBUG}" = "y" ]; then + echo "-- customOpScript $* --" + set -x + fi + + local featureName="$1" + local operation="$2" + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + if [ -z "${operation}" ]; then + echo "warning: ${featureName} : a custom operation script must be provided" + return 1 + fi + + local customScript="${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}"/"${operation}" + if [ -f "${customScript}" ]; then + cd "${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}" + chmod u+x "${customScript}" + ./"$(basename "${customScript}")" + fi } # ########################################################## @@ -661,157 +657,158 @@ function customOpScript() # ########################################################## function enableFeature() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureJar="$2" - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - if [[ -z ${featureJar} ]]; then - echo "warning: no feature jar" - return 2 - fi - - if ! enableDepAnalysis "${featureName}"; then - return "$?" - fi - - if ! enableConfigAnalysis "${featureName}"; then - return "$?" - fi - - if ! enableBinAnalysis "${featureName}"; then - return "$?" - fi - - if ! enableDbAnalysis "${featureName}"; then - return "$?" - fi - - # enable feature itself - - ln -s -f "${featureJar}" "${LIB}/" - - # enable dependent libraries if any - - enableFeatureDeps "${featureName}" - - # enable configuration - - enableFeatureConfig "${featureName}" - - # enable binaries - - enableFeatureBin "${featureName}" - - # enable db - - enableFeatureDb "${featureName}" - - # enable feature artifacts - - enableFeatureArtifacts "${featureName}" - - # run custom enable if any - - customOpScript "${featureName}" "enable" + if [ "$DEBUG" = "y" ]; then + echo "-- enableFeature $* --" + set -x + fi + + local featureName="$1" + local featureJar="$2" + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + if [ -z "${featureJar}" ]; then + echo "warning: no feature jar" + return 2 + fi + + if ! enableDepAnalysis "${featureName}"; then + return "$?" + fi + + if ! enableConfigAnalysis "${featureName}"; then + return "$?" + fi + + if ! enableBinAnalysis "${featureName}"; then + return "$?" + fi + + if ! enableDbAnalysis "${featureName}"; then + return "$?" + fi + + # enable feature itself + + ln -s -f "${featureJar}" "${LIB}/" + + # enable dependent libraries if any + + enableFeatureDeps "${featureName}" + + # enable configuration + + enableFeatureConfig "${featureName}" + + # enable binaries + + enableFeatureBin "${featureName}" + + # enable db + + enableFeatureDb "${featureName}" + + # enable feature artifacts + + enableFeatureArtifacts "${featureName}" + + # run custom enable if any + + customOpScript "${featureName}" "enable" } # ########################################################## -# disableFeatureDeps(featureName): -# disables feature dependencies +# disableFeatureDeps(featureName): +# disables feature dependencies # ########################################################## function disableFeatureDeps() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local xDepsEnabledMap featureBaseDirs aFeatureDir aFeatureName - local featureDeps aFeatureDep - local depJarPath depJarName depJarRealPath - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - declare -A xDepsEnabledMap - - featureBaseDirs=$(ls -d "${FEATURES}"/*/ 2> /dev/null) - for aFeatureDir in ${featureBaseDirs}; do - aFeatureName=$(basename "${aFeatureDir}") - if [[ "${aFeatureName}" == "${featureName}" ]]; then - continue - fi - - depJarPaths=$(ls "${aFeatureDir}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) - for depJarPath in ${depJarPaths}; do - if [[ "$?" == 0 ]] ; then - depJarName=$(basename "${depJarPath}") - xDepsEnabledMap[${depJarName}]="${depJarPath}" - fi - done - done - - if [[ ${DEBUG} == y ]]; then - echo "${!xDepsEnabledMap[@]}" - echo "${xDepsEnabledMap[@]}" - fi - - featureDeps=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) - for aFeatureDep in ${featureDeps}; do - depJarName=$(basename "${aFeatureDep}") - if [[ -L "${LIB}"/"${depJarName}" ]]; then - depJarRealPath=$(readlink -f "${LIB}"/"${depJarName}") - if [[ "${depJarRealPath}" == "${aFeatureDep}" ]]; then - rm -f "${LIB}"/"${depJarName}" - - # case there were multiple features using this library - # re-enable link fron an enabled feature - - if [[ -n ${xDepsEnabledMap[${depJarName}]} ]]; then - ln -s -f "${xDepsEnabledMap[${depJarName}]}" "${LIB}/" - fi - fi - fi - done + if [ "${DEBUG}" = "y" ]; then + echo "-- disableFeatureDeps $* --" + set -x + fi + + local featureName="$1" + local aDepsEnabledMap xDepsEnabledMap featureBaseDirs aFeatureDir aFeatureName + local featureDeps aFeatureDep + local depJarPath depJarName depJarRealPath + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureBaseDirs=$(ls -d "${FEATURES}"/*/ 2> /dev/null) + for aFeatureDir in ${featureBaseDirs}; do + aFeatureName=$(basename "${aFeatureDir}") + if [ "${aFeatureName}" = "${featureName}" ]; then + continue + fi + + depJarPaths=$(ls "${aFeatureDir}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) + for depJarPath in ${depJarPaths}; do + if [ "$?" = "0" ] ; then + depJarName=$(basename "${depJarPath}") + xDepsEnabledMap="${xDepsEnabledMap} ${depJarPath}" + fi + done + done + + if [ "${DEBUG}" = "y" ]; then + echo "${xDepsEnabledMap}" + fi + + featureDeps=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) + for aFeatureDep in ${featureDeps}; do + depJarName=$(basename "${aFeatureDep}") + # + # check if defJarName is a sym-link + # + if [ -L "${LIB}"/"${depJarName}" ]; then + depJarRealPath=$(readlink -f "${LIB}"/"${depJarName}") + if [ "${depJarRealPath}" = "${aFeatureDep}" ]; then + rm -f "${LIB}"/"${depJarName}" + + # case there were multiple features using this library + # re-enable link fron an enabled feature + for aDepsEnabledMap in ${xDepsEnabledMap}; do + if [ $(basename "${aDepsEnabledMap}") = ${depJarName} ]; then + ln -s -f "${aDepsEnabledMap}" "${LIB}/" + fi + done + fi + fi + done } # ########################################################## -# disableFeatureConfig(featureName): +# disableFeatureConfig(featureName): # disables feature configuration # featureName: name of the feature # ########################################################## function disableFeatureConfig() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureConfigs featureConfigPath - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureConfigs=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ -type f -maxdepth 1 2> /dev/null) - for featureConfigPath in ${featureConfigs}; do - configFileName=$(basename "${featureConfigPath}") - rm -f "${CONFIG}"/"${configFileName}" 2> /dev/null - done + if [ "${DEBUG}" = "y" ]; then + echo "-- disableFeatureConfig $* --" + set -x + fi + + local featureName="$1" + local featureConfigs featureConfigPath + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureConfigs=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ -type f -maxdepth 1 2> /dev/null) + for featureConfigPath in ${featureConfigs}; do + configFileName=$(basename "${featureConfigPath}") + rm -f "${CONFIG}"/"${configFileName}" 2> /dev/null + done } # ########################################################## @@ -821,116 +818,115 @@ function disableFeatureConfig() # ########################################################## function disableFeatureBin() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureBins featureBinPath - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureBins=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ -type f -maxdepth 1 2> /dev/null) - for featureBinPath in ${featureBins}; do - binFileName=$(basename "${featureBinPath}") - rm -f "${BIN}"/"${binFileName}" 2> /dev/null - done + if [ "${DEBUG}" = "y" ]; then + echo "-- disableFeatureBin $* --" + set -x + fi + + local featureName="$1" + local featureBins featureBinPath + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureBins=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ -type f -maxdepth 1 2> /dev/null) + for featureBinPath in ${featureBins}; do + binFileName=$(basename "${featureBinPath}") + rm -f "${BIN}"/"${binFileName}" 2> /dev/null + done } # ########################################################## -# disableFeatureDbSchema(featureName, featureDbPath, schemaName): -# disables feature db configuration for a schema +# disableFeatureDbSchema(featureName, featureDbPath, schemaName): +# disables feature db configuration for a schema # featureName: name of the feature # ########################################################## function disableFeatureDbSchema() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" featureDbPath="$2" schemaName="$3" - local upgradeFeatureSqls downgradeFeatureSqls featureSql sqlDir sqlName schemaDir schemaName - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - if [[ -z ${featureDbPath} ]]; then - echo "warning: ${featureName} contains no DB path" - return 2 - fi - - if [[ -z ${schemaName} ]]; then - echo "warning: feature ${featureName} contains no schema name" - return 3 - fi - - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - upgradeFeatureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/"${schemaName}"/"${FEATURE_SQL}"/*"${UPGRADE_SQL_SUFFIX}" -type f -maxdepth 1 2> /dev/null) - for featureSql in ${upgradeFeatureSqls}; do - sqlName=$(basename "${featureSql}") - sqlDir=$(dirname "${featureSql}") - schemaDir=$(dirname "${sqlDir}") - schemaName=$(basename "${schemaDir}") - rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null - done - - downgradeFeatureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/"${schemaName}"/"${FEATURE_SQL}"/*"${DOWNGRADE_SQL_SUFFIX}" -type f -maxdepth 1 2> /dev/null) - for featureSql in ${downgradeFeatureSqls}; do - sqlName=$(basename "${featureSql}") - sqlDir=$(dirname "${featureSql}") - schemaDir=$(dirname "${sqlDir}") - schemaName=$(basename "${schemaDir}") - if [[ ! -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]]; then - mkdir -p "${DB}"/"${schemaName}"/${FEATURE_SQL} 2> /dev/null - fi - ln -s -f "${featureSql}" "${DB}"/"${schemaName}"/${FEATURE_SQL}/ - done - - if [[ -n ${sqlUpgradeScripts} || -n ${sqlDowngradeScripts} ]]; then - DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok - fi + if [ "${DEBUG}" = "y" ]; then + echo "-- disableFeatureDbSchema $* --" + set -x + fi + + local featureName="$1" featureDbPath="$2" schemaName="$3" + local upgradeFeatureSqls downgradeFeatureSqls featureSql sqlDir sqlName schemaDir schemaName + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + if [ -z "${featureDbPath}" ]; then + echo "warning: ${featureName} contains no DB path" + return 2 + fi + + if [ -z "${schemaName}" ]; then + echo "warning: feature ${featureName} contains no schema name" + return 3 + fi + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + upgradeFeatureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/"${schemaName}"/"${FEATURE_SQL}"/*"${UPGRADE_SQL_SUFFIX}" -type f -maxdepth 1 2> /dev/null) + for featureSql in ${upgradeFeatureSqls}; do + sqlName=$(basename "${featureSql}") + sqlDir=$(dirname "${featureSql}") + schemaDir=$(dirname "${sqlDir}") + schemaName=$(basename "${schemaDir}") + rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null + done + + downgradeFeatureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/"${schemaName}"/"${FEATURE_SQL}"/*"${DOWNGRADE_SQL_SUFFIX}" -type f -maxdepth 1 2> /dev/null) + for featureSql in ${downgradeFeatureSqls}; do + sqlName=$(basename "${featureSql}") + sqlDir=$(dirname "${featureSql}") + schemaDir=$(dirname "${sqlDir}") + schemaName=$(basename "${schemaDir}") + if [ ! -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]; then + mkdir -p "${DB}"/"${schemaName}"/${FEATURE_SQL} 2> /dev/null + fi + ln -s -f "${featureSql}" "${DB}"/"${schemaName}"/${FEATURE_SQL}/ + done + + if [ -n "${sqlUpgradeScripts}" ] || [ -n "${sqlDowngradeScripts}" ]; then + DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok + fi } # ########################################################## -# disableFeatureDb(featureName): -# disables feature db configuration +# disableFeatureDb(featureName): +# disables feature db configuration # featureName: name of the feature # ########################################################## function disableFeatureDb() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureDbPath featureDbs schemaName - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureDbs=$(ls -d "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/ 2> /dev/null) - for featureDbPath in ${featureDbs}; do - if [[ -z "$(ls "${featureDbPath%/}"/"${FEATURE_SQL}"/*${UPGRADE_SQL_SUFFIX} 2> /dev/null)" ]]; then - continue - fi - schemaName=$(basename "${featureDbPath%/}") - disableFeatureDbSchema "${featureName}" "${featureDbPath%/}" "${schemaName}" - done + if [ "${DEBUG}" = "y" ]; then + echo "-- disableFeatureDb $* --" + set -x + fi + + local featureName="$1" + local featureDbPath featureDbs schemaName + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureDbs=$(ls -d "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/ 2> /dev/null) + for featureDbPath in ${featureDbs}; do + if [ -z "$(ls "${featureDbPath%/}"/"${FEATURE_SQL}"/*${UPGRADE_SQL_SUFFIX} 2> /dev/null)" ]; then + continue + fi + schemaName=$(basename "${featureDbPath%/}") + disableFeatureDbSchema "${featureName}" "${featureDbPath%/}" "${schemaName}" + done } # ########################################################## @@ -939,44 +935,44 @@ function disableFeatureDb() # ########################################################## function disableFeature() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return - fi - - # disable feature itself - - ( - cd "${LIB}" - rm -f feature-"${featureName}"-[0-9]*.jar 2> /dev/null - ) - - # disable dependencies if any - - disableFeatureDeps "${featureName}" - - # disable configuration if any - - disableFeatureConfig "${featureName}" - - # disable binaries if any - - disableFeatureBin "${featureName}" - - # disable DB SQL scripts if any - - disableFeatureDb "${featureName}" - - # run custom disable if any - - customOpScript "${featureName}" "disable" + if [ "${DEBUG}" = "y" ]; then + echo "-- disableFeature $* --" + set -x + fi + + local featureName="$1" + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return + fi + + # disable feature itself + + ( + cd "${LIB}" + rm -f feature-"${featureName}"-[0-9]*.jar 2> /dev/null + ) + + # disable dependencies if any + + disableFeatureDeps "${featureName}" + + # disable configuration if any + + disableFeatureConfig "${featureName}" + + # disable binaries if any + + disableFeatureBin "${featureName}" + + # disable DB SQL scripts if any + + disableFeatureDb "${featureName}" + + # run custom disable if any + + customOpScript "${featureName}" "disable" } ############################################################ @@ -985,40 +981,40 @@ function disableFeature() # This was copied from 'policy-drools/docker-install.sh' # in the 'docker' repository, and modified where needed. ############################################################ -function configureFeature() +function configureFeature() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local envConfig=$1 featureRoot=$2 - local sedLine="sed -i" - local sedFiles="" nonBinaryFiles sedFile name value - - while read line || [ -n "${line}" ]; do - if [[ -n ${line} ]] && [[ ${line:0:1} != \# ]]; then - name="${line%%=*}" - value="${line#*=}" - value=$(echo "${value}" | sed -e 's/[\/&]/\\&/g') - if [[ -z ${name} ]] || [[ -z ${value} ]]; then - echo "warning: ${line} missing name or value" - fi - sedLine+=" -e 's/\${{${name}}}/${value}/g' " - fi - done < "${envConfig}" - - nonBinaryFiles=$(find "${featureRoot}" -type f -exec grep -Iq . {} \; -print 2> /dev/null) - for sedFile in ${nonBinaryFiles}; do - if fgrep -l '${{' ${sedFile} > /dev/null 2>&1; then - sedFiles+="${sedFile} " - fi - done - - if [[ -n ${sedFiles} ]]; then - sedLine+=${sedFiles} - eval "${sedLine}" - fi + if [ "$DEBUG" = "y" ]; then + echo "-- configureFeature $* --" + set -x + fi + + local envConfig=$1 featureRoot=$2 + local sedLine="sed -i" + local sedFiles="" nonBinaryFiles sedFile name value + + while read line || [ -n "${line}" ]; do + if [ -n "${line}" ] && [ "${line:0:1}" != \# ]; then + name="${line%%=*}" + value="${line#*=}" + value=$(echo "${value}" | sed -e 's/[\/&]/\\&/g') + if [ -z "${name}" ] || [ -z "${value}" ]; then + echo "warning: ${line} missing name or value" + fi + sedLine+=" -e 's/\${{${name}}}/${value}/g' " + fi + done < "${envConfig}" + + nonBinaryFiles=$(find "${featureRoot}" -type f -exec grep -Iq . {} \; -print 2> /dev/null) + for sedFile in ${nonBinaryFiles}; do + if fgrep -l '${{' ${sedFile} > /dev/null 2>&1; then + sedFiles+="${sedFile} " + fi + done + + if [ -n "${sedFiles}" ]; then + sedLine+=${sedFiles} + eval "${sedLine}" + fi } ############################################################ @@ -1029,121 +1025,100 @@ function configureFeature() ############################################################ function installFeatures { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local name featureConf feature dir conf - - if [[ -d "${FEATURES}" && -x "${FEATURES}" ]]; then - SOURCE_DIR=$PWD - for feature in "$@" ; do - dir= - if [[ "${feature}" == feature-*.zip || - "${feature}" == */feature-*.zip ]] ; then - # the ZIP file is specified -- find the name - name="${feature##*/}" - name="${name#feature-}" - name="${name%%-[0-9]*\.zip}" - - # if the ZIP file has a directory name component, - # set 'dir' accordingly - if [[ "${feature}" =~ / ]] ; then - dir="${feature%/*}" - fi - else - # Doesn't match the ZIP file name convention -- interpret - # this as a feature name, and try to locate a matching ZIP - # file. If there is more than one, choose the one with the - # highest version number. - name="${feature}" - feature=$(ls -v feature-"${name}"-[0-9]*.zip 2>/dev/null|tail -1) - fi - if [[ ! -f "${feature}" ]] ; then - # include the file name in the error message, unless we don't - # have one -- in this case, use the feature name - echo "error: feature file ${feature:-for ${name}} not found" - continue - fi - if [[ -d "${FEATURES}/${name}" ]] ; then - echo "error: feature ${name} has already been installed" - continue - fi - - # extract contents of ZIP file in to feature directory - mkdir -p "${FEATURES}/${name}" > /dev/null 2>&1 - (cd "${FEATURES}/${name}"; jar xf "${SOURCE_DIR}"/"${feature}") - - # if there is a configuration file available, - # use it to configure the feature - featureConf="${dir:+$dir/}feature-${name}.conf" - if [[ -r "${featureConf}" ]]; then - configureFeature "${featureConf}" "${FEATURES}"/"${name}" - cp "${featureConf}" "${POLICY_HOME}"/etc/profile.d - echo "feature ${name} has been installed (configuration present)" - else - echo "feature ${name} has been installed (no configuration present)" - fi - - customOpScript "${name}" "install" - done - - # check the current directory and the 'config' directory for a - # 'base.conf' file -- use the first one that is found - for conf in base.conf ${POLICY_HOME}/config/base.conf ${POLICY_HOME}/etc/profile.d/base.conf; do - if [[ -f "${conf}" ]] ; then - echo "applying base configuration '${conf}' to features" - configureFeature "${conf}" "${FEATURES}" - break - fi - done - else - echo "error: aborting -- ${FEATURES} is not accessible" - exit 1 - fi + if [ "$DEBUG" = "y" ]; then + echo "-- installFeatures $* --" + set -x + fi + + local name featureConf feature conf + if [ -d "${FEATURES}" ]; then + SOURCE_DIR=$PWD + for feature in "$@" ; do + name="${feature}" + feature=$(ls -v feature-"${name}"-[0-9]*.zip 2>/dev/null|tail -1) + if [ ! -f "${feature}" ] ; then + # include the file name in the error message, unless we don't + # have one -- in this case, use the feature name + echo "error: feature file ${feature:-for ${name}} not found" + continue + fi + if [ -d "${FEATURES}/${name}" ] ; then + echo "error: feature ${name} has already been installed" + continue + fi + + # extract contents of ZIP file in to feature directory + mkdir -p "${FEATURES}/${name}" > /dev/null 2>&1 + (cd "${FEATURES}/${name}"; jar xf "${SOURCE_DIR}"/"${feature}") + + # if there is a configuration file available, + # use it to configure the feature + featureConf="${dir:+$dir/}feature-${name}.conf" + if [ -r "${featureConf}" ]; then + configureFeature "${featureConf}" "${FEATURES}"/"${name}" + cp "${featureConf}" "${POLICY_HOME}"/etc/profile.d + echo "feature ${name} has been installed (configuration present)" + else + echo "feature ${name} has been installed (no configuration present)" + fi + + customOpScript "${name}" "install" + done + + # check the current directory and the 'config' directory for a + # 'base.conf' file -- use the first one that is found + for conf in base.conf ${POLICY_HOME}/config/base.conf ${POLICY_HOME}/etc/profile.d/base.conf; do + if [ -f "${conf}" ] ; then + echo "applying base configuration '${conf}' to features" + configureFeature "${conf}" "${FEATURES}" + break + fi + done + else + echo "error: aborting -- ${FEATURES} is not accessible" + exit 1 + fi } # ########################################################## -# uninstallFeatureDb(featureName): -# uninstalls the feature db configuration +# uninstallFeatureDb(featureName): +# uninstalls the feature db configuration # featureName: name of the feature # ########################################################## function uninstallFeatureDb() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureSqls sqlDir sqlName schemaDir schemaName schemaNames leftSqls - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/${FEATURE_SQL}/*.sql -type f -maxdepth 1 2> /dev/null) - for featureSql in ${featureSqls}; do - sqlName=$(basename "${featureSql}") - sqlDir=$(dirname "${featureSql}") - schemaDir=$(dirname "${sqlDir}") - schemaName=$(basename "${schemaDir}") - schemaNames+=${schemaName} - rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null - done - - for schemaName in ${schemaNames}; - do - leftSqls=$(ls "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/*.sql 2> /dev/null) - if [[ -z ${leftSqls} ]]; then - if ! DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok; then - echo -n "warning: ${featureName}: ${schemaName}: database data is leftover. " - echo -n "Consider cleaning left over data with 'db-migrator'." - fi - fi - done + if [ "${DEBUG}" = "y" ]; then + echo "-- uninstallFeatureDb $* --" + set -x + fi + + local featureName="$1" + local featureSqls sqlDir sqlName schemaDir schemaName schemaNames leftSqls + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/${FEATURE_SQL}/*.sql -type f -maxdepth 1 2> /dev/null) + for featureSql in ${featureSqls}; do + sqlName=$(basename "${featureSql}") + sqlDir=$(dirname "${featureSql}") + schemaDir=$(dirname "${sqlDir}") + schemaName=$(basename "${schemaDir}") + schemaNames="${schemaNames} ${schemaName}" + rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null + done + for schemaName in ${schemaNames}; + do + leftSqls=$(ls "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/*.sql 2> /dev/null) + if [ -n "${leftSqls}" ]; then + if ! DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok; then + echo -n "warning: ${featureName}: ${schemaName}: database data is leftover. " + echo -n "Consider cleaning left over data with 'db-migrator'." + fi + fi + done } ############################################################ @@ -1151,25 +1126,24 @@ function uninstallFeatureDb() ############################################################ function uninstallFeature { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return - fi - - disableFeature "${featureName}" - uninstallFeatureDb "${featureName}" - customOpScript "${featureName}" "uninstall" - - if [[ -n ${FEATURES} && -n ${featureName} ]]; then - rm -rf "${FEATURES:-???}/${featureName}" - fi + if [ "$DEBUG" = "y" ]; then + echo "-- uninstallFeature $* --" + set -x + fi + + local featureName="$1" + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return + fi + disableFeature "${featureName}" + uninstallFeatureDb "${featureName}" + customOpScript "${featureName}" "uninstall" + + if [ -n "${FEATURES}" ] && [ -n "${featureName}" ]; then + rm -rf "${FEATURES:-???}/${featureName}" + fi } ############################################################ @@ -1177,120 +1151,129 @@ function uninstallFeature ############################################################ function uninstallFeatures { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi - - local name - local allFeatures=$'\n'$(cd ${FEATURES};ls)$'\n' - for name in "$@" ; do - # the following check takes care of potentially troublesome names - # like '.', '..', and names containing '/' - if [[ "${allFeatures}" =~ $'\n'${name}$'\n' ]] ; then - uninstallFeature "${name}" - else - echo "feature ${name} not found" - fi - done + if [ "${DEBUG}" = "y" ]; then + echo "-- uninstallFeatures --" + set -x + fi + + local name + local allFeatures=$(cd ${FEATURES};ls) + local aFeature + local flag + for name in "$@" ; do + flag=false + # the following check takes care of potentially troublesome names + # like '.', '..', and names containing '/' + for aFeature in ${allFeatures}; + do + if [ "${aFeature}" = "${name}" ] ; then + uninstallFeature "${name}" + echo "feature ${name} uninstalled" + flag=true + fi + done + if ! $flag; then + echo "error: feature ${name} not found" + fi + done } case "$1" in - status) - { - # dump out status information - status - };; - - enable) - { - if [[ -f "${POLICY_HOME}"/PID ]]; then - echo "error: enable: not allowed when policy is running .." - echo - status - exit 10 - fi - - # enable the specified options - shift - match= - for name in "$@" ; do - # look for matches - 'file' has the full path name - file=$(ls "${FEATURES}"/"${name}"/"${FEATURE_LIB}"/feature-"${name}"-[0-9]*.jar 2> /dev/null) - if [[ "$?" != 0 ]] ; then - # no matching file - echo "${name}: no such option" - else - # make sure there is only one feature jar - countFeatureJars=$(echo "${file}" | wc -w) - if [[ ${countFeatureJars} != 1 ]]; then - echo "warning: skipping ${name}, ${countFeatureJars} feature libraries found" - continue - fi - - # found a match (handle multiple matches, just in case) - match=true - - enableFeature "${name}" "${file}" - fi - done - if [[ "${match}" ]] ; then - echo - status - fi - };; - - disable) - { - if [[ -f "${POLICY_HOME}"/PID ]]; then - echo "error: disable: not allowed when policy is running .." - echo - status - exit 11 - fi - - # disable the specified options - shift - match= - for name in "$@" ; do - # look for matches -- 'file' has the last segment of the path name - file=$(ls "${FEATURES}"/"${name}"/"${FEATURE_LIB}"/feature-"${name}"-[0-9]*.jar 2> /dev/null) - if [[ "$?" != 0 ]] ; then - echo "${name}: no such option" - else - # found a match (handle multiple matches, just in case) - match=true - - disableFeature "${name}" - fi - done - if [[ "${match}" ]] ; then - echo - status - fi - };; - - install) - { - shift - installFeatures "$@" - };; - - uninstall) - { - if [[ -f "${POLICY_HOME}"/PID ]]; then - echo "error: uninstall: not allowed when policy is running .." - echo - status - exit 12 - fi - shift - uninstallFeatures "$@" - };; - - *) - { - usage - };; + status) + { + # dump out status information + status + };; + + enable) + { + if [ -f "${POLICY_HOME}"/PID ]; then + echo "error: enable: not allowed when policy is running .." + echo + status + exit 10 + fi + + # enable the specified options + shift + match= + for name in "$@" ; do + # look for matches - 'file' has the full path name + file=$(ls "${FEATURES}"/"${name}"/"${FEATURE_LIB}"/feature-"${name}"-[0-9]*.jar 2> /dev/null) + if [ "$?" != "0" ] ; then + # no matching file + echo "enable feature: ${name} failed" + else + # make sure there is only one feature jar + countFeatureJars=$(echo "${file}" | wc -w) + if [ ${countFeatureJars} -ne 1 ]; then + echo "warning: skipping ${name}, ${countFeatureJars} feature libraries found" + continue + fi + + # found a match (handle multiple matches, just in case) + match=true + + enableFeature "${name}" "${file}" + fi + done + if [ "${match}" ] ; then + echo + status + fi + };; + + disable) + { + if [ -f "${POLICY_HOME}"/PID ]; then + echo "error: disable: not allowed when policy is running .." + echo + status + exit 11 + fi + + # disable the specified options + shift + match= + for name in "$@" ; do + # look for matches -- 'file' has the last segment of the path name + file=$(ls "${FEATURES}"/"${name}"/"${FEATURE_LIB}"/feature-"${name}"-[0-9]*.jar 2> /dev/null) + if [ "$?" != "0" ] ; then + echo "${name}: no such option" + else + # found a match (handle multiple matches, just in case) + match=true + + disableFeature "${name}" + fi + done + if [ "${match}" ] ; then + echo + status + fi + };; + + install) + { + shift + installFeatures "$@" + };; + + uninstall) + { + if [ -f "${POLICY_HOME}"/PID ]; then + echo "error: uninstall: not allowed when policy is running .." + echo + status + exit 12 + fi + shift + uninstallFeatures "$@" + };; + + *) + { + usage + };; esac exit |