blob: 5918bf398677638517ab84229be4370b4128a2c7 [file] [log] [blame]
Jorge Hernandezae4a9352017-07-18 01:06:39 -05001#! /bin/bash
2
3###
4# ============LICENSE_START=======================================================
5# ONAP POLICY
6# ================================================================================
7# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
8# ================================================================================
9# Licensed under the Apache License, Version 2.0 (the "License");
10# you may not use this file except in compliance with the License.
11# You may obtain a copy of the License at
12#
13# http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS,
17# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18# See the License for the specific language governing permissions and
19# limitations under the License.
20# ============LICENSE_END=========================================================
21##
22
23# #############################################################
24# Features Directory Layout:
25#
26# POLICY_HOME/
27# └── features/
28# └── <feature-name>*/
29#     └── [config]/
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -050030#     │   └── <config-file>+
Jorge Hernandezae4a9352017-07-18 01:06:39 -050031#     └── lib/
32#     │  └── [dependencies]/
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -050033#     │  │ └── <dependent-jar>+
Jorge Hernandezae4a9352017-07-18 01:06:39 -050034#     │  └── feature/
35#     │  └── <feature-jar>
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -050036#     └── [db]/
37#     │   └── <db-name>/+
38#     │  └── sql/
39#     │ └── <sql-scripts>*
Jorge Hernandezae4a9352017-07-18 01:06:39 -050040#     └── [install]
41#      └── [enable]
42#      └── [disable]
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -050043#      └── [other-directories-or-files]
Jorge Hernandezae4a9352017-07-18 01:06:39 -050044#
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -050045# notes: [] = optional , * = 0 or more , + = 1 or more
46# <feature-name> directory without "feature-" prefix.
47# [config] feature configuration directory that contains all configuration
48# needed for this features
49# [config]/<config-file> preferable named with "feature-<feature-name>" prefix to
50# precisely match it against the exact features, source code, and
51# associated wiki page for configuration details.
52# lib jar libraries needed by this features
53# lib/[dependencies] 3rd party jar dependencies not provided by base installation
54# of pdp-d that are necessary for <feature-name> to operate
55# correctly.
56# lib/feature the single feature jar that implements the feature.
57# [db] database directory, if the feature contains sql.
58# [db]/<db-name> database to which underlying sql scripts should be applied against.
59# ideally, <db-name> = <feature-name> so it is easily to associate
60# the db data with a feature itself. Ideally, since a feature is
61# a somewhat independent isolated unit of functionality,the <db-name>
62# database ideally isolates all its data.
63# [db]/<db-name>/sql directory with all the sql scripts.
64# [db]/<db-name>/sql/<sql-scripts> for this featuresql scripts
65# upgrade scripts should be suffixed with ".upgrade.sql"
66# downgrade scripts should be suffixed with ".downgrade.sql"
67# [install] custom installation directory where custom enable or disable scripts
68# and other free form data is included to be used for the enable and
69# and disable scripts.
70# [install]/[enable] enable script executed when the enable operation is invoked in
71# the feature.
72# [install]/[disable] disable script executed when the disable operation is invoked in
73# the feature.
74# [install]/[other-directories-or-files] other executables, or data that can be used
75# by the feature for any of its operations. The content is determined
76# by the feature designer.
77#
78# Operations:
79# enable : enables 1) dependencies, 2) configuration, 3) database, and 4) feature
80# disable: disables 1) dependencies, 2) configuration, and 3) feature
81# * note: no operation on the DB.
82# status : status of a feature
Jorge Hernandezae4a9352017-07-18 01:06:39 -050083#
84# Example:
85#
86# POLICY_HOME/
87# └── features/
88# ├── eelf/
89# │   ├── config/
90# │   │   ├── logback-eelf.xml
91# │   └── lib/
92# │   │ └── dependencies/
Guo Ruijing6abeb292017-07-28 08:23:01 +000093# │   │ │ └── ONAP-Logging-1.1.0-SNAPSHOT.jar
Jorge Hernandezae4a9352017-07-18 01:06:39 -050094# │   │ │ └── eelf-core-1.0.0.jar
95# │   │ └── feature/
96# │   │ └── feature-eelf-1.1.0-SNAPSHOT.jar
97# │   └── install/
98# │   └── enable
99# │   └── disable
100# └── healthcheck/
101# ├── config/
102# │   └── feature-healthcheck.properties
103# └── lib/
104# └── feature/
105# └── feature-healthcheck-1.1.0-SNAPSHOT.jar
106# #############################################################
107
108if [[ ${DEBUG} == y ]]; then
109 echo "-- MAIN --"
110 set -x
111fi
112
113# The directories at play
114
115LIB=${POLICY_HOME}/lib
116CONFIG=${POLICY_HOME}/config
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500117DB=${POLICY_HOME}/etc/db
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500118FEATURES=${POLICY_HOME}/features
119
120if [[ ! ( -d "${LIB}" && -x "${LIB}" ) ]]; then
121 echo "ERROR: no ${LIB} directory"
122 exit 1
123fi
124
125if [[ ! ( -d "${CONFIG}" && -x "${CONFIG}" ) ]]; then
126 echo "ERROR: no ${CONFIG} directory"
127 exit 2
128fi
129
130if [[ ! ( -d "${FEATURES}" && -x "${FEATURES}" ) ]]; then
131 echo "ERROR: no ${FEATURES} directory"
132 exit 3
133fi
134
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500135if [[ ! -d "${DB}" ]]; then
136 mkdir -p "${DB}"
137fi
138
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500139# relative per Feature Directory Paths
140
141FEATURE_DEPS="lib/dependencies"
142FEATURE_LIB="lib/feature"
143FEATURE_CONFIG="config"
144FEATURE_INSTALL="install"
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500145FEATURE_DB="db"
146FEATURE_SQL="sql"
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500147
148featureJars=$(find "${FEATURES}" -name "feature-*.jar" -type f -exec basename {} \; 2> /dev/null)
149if [[ -z ${featureJars} ]]; then
150 echo "no features"
151 usage
152 exit 0
153fi
154
155# default field lengths
156nameLength=20
157versionLength=15
158
159# update field lengths, if needed
160for jar in ${featureJars} ; do
161 # get file name without 'jar' suffix
162 tmp="${jar%\.jar}"
163
164 # remove feature prefix
165 tmp="${tmp#feature-}"
166
167 # get feature name by removing the version portion
168 name="${tmp%%-[0-9]*}"
169
170 # extract version portion of name
171 version="${tmp#${name}-}"
172
173 # grow the size of the name/version field, if needed
174 if (( "${#name}" > nameLength )) ; then
175 nameLength="${#name}"
176 fi
177 if (( "${#version}" > versionLength )) ; then
178 versionLength="${#version}"
179 fi
180done
181
182# ##########################################################
183# usage: usage information
184# ##########################################################
185function usage
186{
187 # print out usage information
188 cat >&2 <<-'EOF'
189 Usage: features status
190 Get enabled/disabled status on all features
191 features enable <feature> ...
192 Enable the specified feature
193 features disable <feature> ...
194 Disable the specified feature
195 EOF
196}
197
198# ##########################################################
199# status: dump out status information
200# ##########################################################
201function status
202{
203 if [[ ${DEBUG} == y ]]; then
204 echo "-- ${FUNCNAME[0]} $@ --"
205 set -x
206 fi
207
208 local tmp name version status
209 local format="%-${nameLength}s %-${versionLength}s %s\n"
210
211 printf "${format}" "name" "version" "status"
212 printf "${format}" "----" "-------" "------"
213
214 for jar in ${featureJars} ; do
215 # get file name without 'jar' suffix
216 tmp="${jar%\.jar}"
217
218 # remove feature prefix
219 tmp="${tmp#feature-}"
220
221 # get feature name by removing the version portion
222 name="${tmp%%-[0-9]*}"
223
224 # extract version portion of name
225 version="${tmp#${name}-}"
226
227 # determine status
228 status=disabled
229 if [[ -e "${LIB}/${jar}" ]] ; then
230 status=enabled
231 fi
232 printf "${format}" "${name}" "${version}" "${status}"
233 done
234}
235
236# ##########################################################
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500237# enableDepAnalysis (featureName):
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500238# reports on potential dependency conflicts
239# featureName: name of the feature
240# ##########################################################
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500241function enableDepAnalysis ()
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500242{
243 if [[ ${DEBUG} == y ]]; then
244 echo "-- ${FUNCNAME[0]} $@ --"
245 set -x
246 fi
247
248 local featureName="$1"
249 local featureDepJars featureDepJarPath depJarName multiVersionJars
250
251 if [[ -z ${featureName} ]]; then
252 echo "WARN: no feature name"
253 return 1
254 fi
255
256 featureDepJars=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null)
257 for featureDepJarPath in ${featureDepJars}; do
258 depJarName=$(basename "${featureDepJarPath}")
259
260 # it could be a base jar
261
262 if [[ -f "${LIB}"/"${depJarName}" ]]; then
263 echo "WARN: dependency ${depJarName} already in use"
264 continue
265 fi
266
267 # it could be a link from another feature
268
269 if [[ -L "${LIB}"/"${depJarName}" ]]; then
270 continue
271 fi
272
273 # unadvisable if multiple versions exist
274
275 multiVersionJars=$(ls "${LIB}"/"${depJarName%%-[0-9]*.jar}"-*.jar 2> /dev/null)
276 if [[ -n "${multiVersionJars}" ]]; then
277 echo "WARN: other version of library ${depJarName} present: ${multiVersionJars}"
278 return 2
279 fi
280 done
281}
282
283# ##########################################################
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500284# enableConfigAnalysis (featureName):
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500285# reports on potential dependency conflicts
286# featureName: name of the feature
287# ##########################################################
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500288function enableConfigAnalysis ()
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500289{
290 if [[ ${DEBUG} == y ]]; then
291 echo "-- ${FUNCNAME[0]} $@ --"
292 set -x
293 fi
294
295 local featureName="$1"
296 local featureConfigs configPath configFileName
297
298 if [[ -z ${featureName} ]]; then
299 echo "WARN: no feature name"
300 return 1
301 fi
302
303 featureConfigs=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ 2> /dev/null)
304 for configPath in ${featureConfigs}; do
305 configFileName=$(basename "${configPath}")
306 if [[ -e "${LIB}"/"${configFileName}" ]]; then
307 echo "ERROR: a config file of the same name is already in the base: ${configFileName}"
308 return 2
309 fi
310 done
311}
312
313# ##########################################################
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500314# enableDbAnalysis (featureName):
315# reports on potential db access problems
316# featureName: name of the feature
317# ##########################################################
318function enableDbAnalysis()
319{
320 if [[ ${DEBUG} == y ]]; then
321 echo "-- ${FUNCNAME[0]} $@ --"
322 set -x
323 fi
324
325 local featureName="$1"
326 local featureSqls
327
328 if [[ -z ${featureName} ]]; then
329 echo "WARN: no feature name"
330 return 1
331 fi
332
333 featureSqls=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/sql/*.upgrade.sql 2> /dev/null)
334 if [[ -z ${featureSqls} ]]; then
335 return 0
336 fi
337
338 source "${POLICY_HOME}"/etc/profile.d/base.conf
339 if [[ -z ${SQL_HOST} ]] || [[ -z ${SQL_USER} ]] || [[ -z ${SQL_PASSWORD} ]]; then
340 echo "ERROR: not existing configuration to contact the database"
341 return 2
342 fi
343
344 # check reachability
345
346 if which mysqlshow; then
347 if ! mysqlshow -u"${SQL_USER}" -p"${SQL_PASSWORD}" -h"${SQL_HOST}" > /dev/null 2>&1; then
348 echo "ERROR: No DB connectivity to ${SQL_HOST} for ${SQL_USER}"
349 return 3
350 else
351 echo "OK: DB connect to ${SQL_HOST} connectivity for ${SQL_USER}"
352 fi
353 else
354 if ! ping -c2 -W2 "${SQL_HOST}"; then
355 echo "ERROR: database ${SQL_HOST} not reachable"
356 return 4
357 else
358 echo "OK: ping ${SQL_HOST} connectivity"
359 fi
360 fi
361
362 return 0
363}
364
365# ##########################################################
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500366# enableFeatureDeps(featureName):
367# enables feature dependencies
368# featureName: name of the feature
369# ##########################################################
370function enableFeatureDeps()
371{
372 if [[ ${DEBUG} == y ]]; then
373 echo "-- ${FUNCNAME[0]} $@ --"
374 set -x
375 fi
376
377 local featureName="$1"
378 local featureDeps featureDepPath depJarName
379
380 if [[ -z ${featureName} ]]; then
381 echo "WARN: no feature name"
382 return 1
383 fi
384
385 featureDeps=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null)
386 for featureDepPath in ${featureDeps}; do
387 depJarName=$(basename "${featureDepPath}")
388 if [[ ! -f "${LIB}"/"${depJarName}" ]]; then
389 ln -s -f "${featureDepPath}" "${LIB}/"
390 fi
391 done
392}
393
394# ##########################################################
395# enableFeatureConfig(featureName):
396# enables feature configuration
397# featureName: name of the feature
398# ##########################################################
399function enableFeatureConfig()
400{
401 if [[ ${DEBUG} == y ]]; then
402 echo "-- ${FUNCNAME[0]} $@ --"
403 set -x
404 fi
405
406 local featureName="$1"
407 local featureConfigs featureConfigPath
408
409 if [[ -z ${featureName} ]]; then
410 echo "WARN: no feature name"
411 return 1
412 fi
413
414 featureConfigs=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ -type f -maxdepth 1 2> /dev/null)
415 for featureConfigPath in ${featureConfigs}; do
416 ln -s -f "${featureConfigPath}" "${CONFIG}/"
417 done
418}
419
420# ##########################################################
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500421# enableFeatureDbSchema(featureName):
422# enables feature DB Schema configuration
423# featureName: name of the feature
424# ##########################################################
425function enableFeatureDbSchema()
426{
427 if [[ ${DEBUG} == y ]]; then
428 echo "-- ${FUNCNAME[0]} $@ --"
429 set -x
430 fi
431
432 local featureName="$1"
433 local featureDbPath="$2"
434 local schemaName="$3"
435
436 if [[ -z ${featureName} ]]; then
437 echo "WARN: no feature name"
438 return 1
439 fi
440
441 if [[ -z ${featureDbPath} ]]; then
442 echo "WARN: no feature DB path"
443 return 2
444 fi
445
446 if [[ -z ${schemaName} ]]; then
447 echo "WARN: no feature schema name"
448 return 3
449 fi
450
451 sqlUpgradeScripts=$(ls "${featureDbPath%/}"/sql/*.upgrade.sql 2> /dev/null)
452 if [[ -z "${sqlUpgradeScripts}" ]]; then
453 return 0
454 fi
455
456 for sqlUpgradeScript in ${sqlUpgradeScripts}; do
457 if [[ ! -d "${DB}"/"${schemaName}"/sql ]]; then
458 mkdir -p "${DB}"/"${schemaName}"/sql 2> /dev/null
459 fi
460 ln -s -f "${sqlUpgradeScript}" "${DB}"/"${schemaName}"/sql/
461 done
462}
463
464# ##########################################################
465# enableFeatureDb(featureName):
466# enables DB feature configuration
467# featureName: name of the feature
468# ##########################################################
469function enableFeatureDb()
470{
471 if [[ ${DEBUG} == y ]]; then
472 echo "-- ${FUNCNAME[0]} $@ --"
473 set -x
474 fi
475
476 local featureName="$1"
477 local featureDbs featureDbPath schemaName
478
479 if [[ -z ${featureName} ]]; then
480 echo "WARN: no feature name"
481 return 1
482 fi
483
484 featureDbs=$(ls -d "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/ 2> /dev/null)
485 for featureDbPath in ${featureDbs}; do
486 if [[ -z "$(ls "${featureDbPath%/}"/"${FEATURE_SQL}"/*.upgrade.sql 2> /dev/null)" ]]; then
487 continue
488 fi
489 schemaName=$(basename "${featureDbPath%/}")
490 enableFeatureDbSchema "${featureName}" "${featureDbPath%/}" "${schemaName}"
491 done
492}
493
494
495# ##########################################################
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500496# enableFeatureOp(featureName): 'enable' feature operation
497# featureName: name of the feature
498# ##########################################################
499function enableFeatureOp()
500{
501 if [[ ${DEBUG} == y ]]; then
502 echo "-- ${FUNCNAME[0]} $@ --"
503 set -x
504 fi
505
506 local featureName="$1"
507
508 if [[ -z ${featureName} ]]; then
509 echo "WARN: no feature name"
510 return 1
511 fi
512
513 enableScript="${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}"/enable
514 if [[ -f ${enableScript} ]]; then
515 (
516 cd "${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}"
517 chmod u+x enable
518 ./enable
519 )
520 fi
521}
522
523# ##########################################################
524# enableFeature(featureName, featureJar): enables a feature
525# featureName: name of the feature
526# featureJar: path to feature jar implementation
527# ##########################################################
528function enableFeature()
529{
530 if [[ $DEBUG == y ]]; then
531 echo "-- ${FUNCNAME[0]} $@ --"
532 set -x
533 fi
534
535 local featureName="$1"
536 local featureJar="$2"
537
538 if [[ -z ${featureName} ]]; then
539 echo "WARN: no feature name"
540 return 1
541 fi
542
543 if [[ -z ${featureJar} ]]; then
544 echo "WARN: no feature jar"
545 return 2
546 fi
547
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500548 if ! enableDepAnalysis "${featureName}"; then
549 return "$?"
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500550 fi
551
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500552 if ! enableConfigAnalysis "${featureName}"; then
553 return "$?"
554 fi
555
556 if ! enableDbAnalysis "${featureName}"; then
557 return "$?"
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500558 fi
559
560 # enable feature itself
561
562 ln -s -f "${featureJar}" "${LIB}/"
563
564 # enable dependent libraries if any
565
566 enableFeatureDeps "${featureName}"
567
568 # enable configuration
569
570 enableFeatureConfig "${featureName}"
571
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500572 # enable db
573
574 enableFeatureDb "${featureName}"
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500575
576 # run custom enable if any
577
578 enableFeatureOp "${featureName}"
579}
580
581# ##########################################################
582# disableFeatureDeps(featureName):
583# disables feature dependencies
584# ##########################################################
585function disableFeatureDeps()
586{
587 if [[ ${DEBUG} == y ]]; then
588 echo "-- ${FUNCNAME[0]} $@ --"
589 set -x
590 fi
591
592 local featureName="$1"
593 local xDepsEnabledMap featureBaseDirs aFeatureDir aFeatureName
594 local featureDeps aFeatureDep
595 local depJarPath depJarName depJarRealPath
596
597 if [[ -z ${featureName} ]]; then
598 echo "WARN: no feature name"
599 return 1
600 fi
601
602 declare -A xDepsEnabledMap
603
604 featureBaseDirs=$(ls -d "${FEATURES}"/*/ 2> /dev/null)
605 for aFeatureDir in ${featureBaseDirs}; do
606 aFeatureName=$(basename "${aFeatureDir}")
607 if [[ "${aFeatureName}" == "${featureName}" ]]; then
608 continue
609 fi
610
611 depJarPaths=$(ls "${aFeatureDir}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null)
612 for depJarPath in ${depJarPaths}; do
613 if [[ "$?" == 0 ]] ; then
614 depJarName=$(basename "${depJarPath}")
615 xDepsEnabledMap[${depJarName}]="${depJarPath}"
616 fi
617 done
618 done
619
620 if [[ ${DEBUG} == y ]]; then
621 echo "${!xDepsEnabledMap[@]}"
622 echo "${xDepsEnabledMap[@]}"
623 fi
624
625 featureDeps=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null)
626 for aFeatureDep in ${featureDeps}; do
627 depJarName=$(basename "${aFeatureDep}")
628 if [[ -L "${LIB}"/"${depJarName}" ]]; then
629 depJarRealPath=$(readlink -f "${LIB}"/"${depJarName}")
630 if [[ "${depJarRealPath}" == "${aFeatureDep}" ]]; then
631 rm -f "${LIB}"/"${depJarName}"
632
633 # case there were multiple features using this library
634 # re-enable link fron an enabled feature
635
636 if [[ -n ${xDepsEnabledMap[${depJarName}]} ]]; then
637 ln -s -f "${xDepsEnabledMap[${depJarName}]}" "${LIB}/"
638 fi
639 fi
640 fi
641 done
642}
643
644# ##########################################################
645# disableFeatureConfig(featureName):
646# disables feature configuration
647# featureName: name of the feature
648# ##########################################################
649function disableFeatureConfig()
650{
651 if [[ ${DEBUG} == y ]]; then
652 echo "-- ${FUNCNAME[0]} $@ --"
653 set -x
654 fi
655
656 local featureName="$1"
657 local featureConfigs featureConfigPath
658
659 if [[ -z ${featureName} ]]; then
660 echo "WARN: no feature name"
661 return 1
662 fi
663
664 featureConfigs=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ -type f -maxdepth 1 2> /dev/null)
665 for featureConfigPath in ${featureConfigs}; do
666 configFileName=$(basename "${featureConfigPath}")
667 rm -f "${CONFIG}"/"${configFileName}" 2> /dev/null
668 done
669}
670
671# ##########################################################
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500672# disableFeatureDb(featureName):
673# disables feature db configuration
674# featureName: name of the feature
675# ##########################################################
676function disableFeatureDb()
677{
678 if [[ ${DEBUG} == y ]]; then
679 echo "-- ${FUNCNAME[0]} $@ --"
680 set -x
681 fi
682
683 local featureName="$1"
684 local featureSqls sqlDir schemaDir schemaName
685
686 if [[ -z ${featureName} ]]; then
687 echo "WARN: no feature name"
688 return 1
689 fi
690
691 featureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/sql/*.upgrade.sql -type f -maxdepth 1 2> /dev/null)
692 for featureSql in ${featureSqls}; do
693 sqlName=$(basename "${featureSql}")
694 sqlDir=$(dirname "${featureSql}")
695 schemaDir=$(dirname "${sqlDir}")
696 schemaName=$(basename "${schemaDir}")
697 rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null
698 done
699}
700
701# ##########################################################
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500702# disableFeatureOp(featureName): 'enable' feature operation
703# featureName: name of the feature
704# ##########################################################
705function disableFeatureOp()
706{
707 if [[ ${DEBUG} == y ]]; then
708 echo "-- ${FUNCNAME[0]} $@ --"
709 set -x
710 fi
711
712 local featureName="$1"
713
714 if [[ -z ${featureName} ]]; then
715 echo "WARN: no feature name"
716 return 1
717 fi
718
719 disableScript="${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}"/disable
720 if [[ -f ${disableScript} ]]; then
721 (
722 cd "${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}"
723 chmod u+x disable
724 ./disable
725 )
726 fi
727}
728
729# ##########################################################
730# disableFeature(featureName, featureJar): enables a feature
731# featureName: name of the feature
732# ##########################################################
733function disableFeature()
734{
735 if [[ ${DEBUG} == y ]]; then
736 echo "-- ${FUNCNAME[0]} $@ --"
737 set -x
738 fi
739
740 local featureName="$1"
741
742 if [[ -z ${featureName} ]]; then
743 echo "WARN: no feature name"
744 return
745 fi
746
747 # disable feature itself
748
749 (
750 cd "${LIB}"
751 rm -f feature-"${featureName}"-[0-9]*.jar 2> /dev/null
752 )
753
754 # disable dependencies if any
755
756 disableFeatureDeps "${featureName}"
757
758 # disable configuration if any
759
760 disableFeatureConfig "${featureName}"
761
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500762 # disable DB SQL scripts if any
763
764 disableFeatureDb "${featureName}"
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500765
766 # run custom disable if any
Jorge Hernandezc8b6a3f2017-08-08 07:44:21 -0500767
Jorge Hernandezae4a9352017-07-18 01:06:39 -0500768 disableFeatureOp "${featureName}"
769}
770
771case "$1" in
772 status)
773 {
774 # dump out status information
775 status
776 };;
777
778 enable)
779 {
780 if [[ -f "${POLICY_HOME}"/PID ]]; then
781 echo "ERROR: enable: not allowed when policy is running .."
782 echo
783 status
784 exit 10
785 fi
786
787 # enable the specified options
788 shift
789 match=
790 for name in "$@" ; do
791 # look for matches - 'file' has the full path name
792 file=$(ls "${FEATURES}"/"${name}"/"${FEATURE_LIB}"/feature-"${name}"-[0-9]*.jar 2> /dev/null)
793 if [[ "$?" != 0 ]] ; then
794 # no matching file
795 echo "${name}: no such option"
796 else
797 # make sure there is only one feature jar
798 countFeatureJars=$(echo "${file}" | wc -w)
799 if [[ ${countFeatureJars} != 1 ]]; then
800 echo "WARNING: skipping ${name}, ${countFeatureJars} feature libraries found"
801 continue
802 fi
803
804 # found a match (handle multiple matches, just in case)
805 match=true
806
807 enableFeature "${name}" "${file}"
808 fi
809 done
810 if [[ "${match}" ]] ; then
811 echo
812 status
813 fi
814 };;
815
816 disable)
817 {
818 if [[ -f "${POLICY_HOME}"/PID ]]; then
819 echo "ERROR: disable: not allowed when policy is running .."
820 echo
821 status
822 exit 11
823 fi
824
825 # disable the specified options
826 shift
827 match=
828 for name in "$@" ; do
829 # look for matches -- 'file' has the last segment of the path name
830 file=$(ls "${FEATURES}"/"${name}"/"${FEATURE_LIB}"/feature-"${name}"-[0-9]*.jar 2> /dev/null)
831 if [[ "$?" != 0 ]] ; then
832 echo "${name}: no such option"
833 else
834 # found a match (handle multiple matches, just in case)
835 match=true
836
837 disableFeature "${name}"
838 fi
839 done
840 if [[ "${match}" ]] ; then
841 echo
842 status
843 fi
844 };;
845
846 *)
847 {
848 usage
849 };;
850esac
851exit