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