blob: ae3d48d90dcd1662c10daea3b97c2defaa9a771a [file] [log] [blame]
Pamela Dragosh0e16acf2017-02-14 19:45:48 -05001#! /bin/bash
2
Jorge Hernandez508ad582017-05-31 13:58:27 -05003###
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
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050023lib=${POLICY_HOME}/lib
24opt=${lib}/opt
25
26# change to the options directory
27cd ${opt}
28
29# default field lengths
30nameLength=20
31versionLength=15
32
33# update field lengths, if needed
34for jar in $(ls) ; do
35 # get file name without 'jar' suffix
36 tmp="${jar%\.jar}"
37
38 # get feature name by removing the version portion
39 name="${tmp%%-[0-9]*}"
40
41 # extract version portion of name
42 version="${tmp#${name}-}"
43
44 # grow the size of the name/version field, if needed
45 if (( "${#name}" > nameLength )) ; then
46 nameLength="${#name}"
47 fi
48 if (( "${#version}" > versionLength )) ; then
49 versionLength="${#version}"
50 fi
51done
52
53# dump out status information
54function status
55{
56 local tmp name version status
57 local format="%-${nameLength}s %-${versionLength}s %s\n"
58
59 printf "${format}" "name" "version" "status"
60 printf "${format}" "----" "-------" "------"
61 for jar in $(ls) ; do
62 # get file name without 'jar' suffix
63 tmp="${jar%\.jar}"
64
65 # get feature name by removing the version portion
66 name="${tmp%%-[0-9]*}"
67
68 # extract version portion of name
69 version="${tmp#${name}-}"
70
71 # determine status
72 status=disabled
73 if [[ -e "${lib}/${jar}" ]] ; then
74 status=enabled
75 fi
76 printf "${format}" "${name}" "${version}" "${status}"
77 done
78}
79
80case "$1" in
81 status)
82 {
83 # dump out status information
84 status
85 };;
86
87 enable)
88 {
89 # enable the specified options
90 shift
91 match=
92 for name in "$@" ; do
93 # look for matches - 'file' has the full path name
94 file=$(ls ${opt}/"${name}"-[0-9]* 2>/dev/null)
95 if [[ "$?" != 0 ]] ; then
96 # no matching file
97 echo "${name}: no such option"
98 else
99 # found a match (handle multiple matches, just in case)
100 match=true
101 ln -s -f ${file} "${lib}/"
102 fi
103 done
104 if [[ "${match}" ]] ; then
105 echo
106 status
107 fi
108 };;
109
110 disable)
111 {
112 # disable the specified options
113 shift
114 match=
115 for name in "$@" ; do
116 # look for matches -- 'file' has the last segment of the path name
117 file=$(ls "${name}"-[0-9]* 2>/dev/null)
118 if [[ "$?" != 0 ]] ; then
119 echo "${name}: no such option"
120 else
121 # found a match (handle multiple matches, just in case)
122 match=true
123 (cd ${lib} ; rm -f ${file})
124 fi
125 done
126 if [[ "${match}" ]] ; then
127 echo
128 status
129 fi
130 };;
131
132 *)
133 {
134 # print out usage information
135 cat >&2 <<-'EOF'
136 Usage: options status
137 Get enabled/disabled status on all options
138 options enable <option> ...
139 Enable the specified options
140 options disable <option> ...
141 Disable the specified options
142 EOF
143 };;
144esac
145exit