Contents of /trunk/sgml-common/sgml-common-0.6.3-install-catalog.in
Parent Directory
|
Revision Log
Revision 153 -
(show annotations)
(download)
Tue May 8 20:52:56 2007 UTC (17 years ago) by niro
File size: 4919 byte(s)
Tue May 8 20:52:56 2007 UTC (17 years ago) by niro
File size: 4919 byte(s)
-import
1 | #!/bin/bash |
2 | # Script to install a catalog in the centralized SGML catalog |
3 | # Send any comments to Eric Bischoff <eric@caldera.de> |
4 | # This program is under GPL license. See LICENSE file for details. |
5 | |
6 | # Modified by Gentoo developers to better integrate it to portage. |
7 | # <text-markup@gentoo.org> |
8 | |
9 | # Set help message |
10 | SGML_HELP_MESSAGE="Usage: `basename $0` [<option>] <action>\n\ |
11 | where <option> is:\n\ |
12 | \040 -d|--delegate: \t\t\t Use DELEGATE instead of CATALOG\n\ |
13 | and where <action> is:\n\ |
14 | \040 -a|--add <centralized> <ordinary>: \t Declare ordinary catalog in the centralized catalog\n\ |
15 | \040 -r|--remove <centralized> <ordinary>:\t Remove ordinary catalog from the centralized catalog\n\ |
16 | \040 -h, --help: \t\t\t\t Print this help message and exit\n\ |
17 | \040 -v, --version: \t\t\t Print the version number and exit\n" |
18 | |
19 | # Set version message |
20 | SGML_VERSION_MESSAGE="sgml-common version @VERSION@ (install-catalog version 1.0)" |
21 | |
22 | # Set type of pointer |
23 | SGML_POINTER="CATALOG" |
24 | |
25 | # Set action to be performed |
26 | SGML_ACTION="" |
27 | |
28 | # Set catalogs |
29 | SGML_CENTRALIZED="" |
30 | SGML_ORDINARY="" |
31 | |
32 | # Default ROOT value (usually defined by portage) |
33 | [ -z "$ROOT" ] && ROOT="/" |
34 | [[ $ROOT == */ ]] || ROOT="${ROOT}/" |
35 | |
36 | |
37 | # Process options |
38 | case $1 in |
39 | -d|--delegate) SGML_POINTER="DELEGATE" |
40 | shift 1 |
41 | ;; |
42 | esac |
43 | |
44 | # Process actions |
45 | case $1 in |
46 | -a|--add) SGML_ACTION="addition" |
47 | SGML_CENTRALIZED=$2 |
48 | SGML_ORDINARY=$3 |
49 | ;; |
50 | -r|--remove) if [ -z "$3" -o "$3" = "--version" ] |
51 | then |
52 | echo "install-catalog: Old syntax; doing nothing" |
53 | exit 0 |
54 | fi |
55 | SGML_ACTION="removal" |
56 | SGML_CENTRALIZED=$2 |
57 | SGML_ORDINARY=$3 |
58 | ;; |
59 | -h|--help) echo -e $SGML_HELP_MESSAGE |
60 | exit 0 |
61 | ;; |
62 | -v|--version) echo -e $SGML_VERSION_MESSAGE |
63 | exit 0 |
64 | ;; |
65 | --install) echo "install-catalog: Old syntax; doing nothing" |
66 | exit 0 |
67 | ;; |
68 | *) echo -e $SGML_HELP_MESSAGE >&2 |
69 | exit 1 |
70 | ;; |
71 | esac |
72 | |
73 | |
74 | # The arguments to this program should always be relative to $ROOT. Here we |
75 | # declare some extra variables to distingish between the absolute and |
76 | # relative paths. |
77 | SGML_ROOT_CENTRALIZED="${ROOT%/}${SGML_CENTRALIZED}" |
78 | SGML_ROOT_ORDINARY="${ROOT%/}${SGML_ORDINARY}" |
79 | |
80 | |
81 | # Check that the super catalog can be created and changed and deleted |
82 | if [ ! -w ${ROOT}etc/sgml ] |
83 | then |
84 | echo "`basename $0`: unable to write in ${ROOT}etc/sgml." >&2 |
85 | exit 2 |
86 | fi |
87 | case $SGML_ACTION in |
88 | addition) |
89 | if [ -e ${ROOT}etc/sgml/catalog -a ! -w ${ROOT}etc/sgml/catalog ] |
90 | then |
91 | echo "`basename $0`: can not modify \"${ROOT}etc/sgml/catalog\"." >&2 |
92 | exit 2 |
93 | fi |
94 | ;; |
95 | removal) |
96 | if [ ! -w ${ROOT}etc/sgml/catalog ] |
97 | then |
98 | echo "`basename $0`: can not modify \"${ROOT}etc/sgml/catalog\"." >&2 |
99 | exit 2 |
100 | fi |
101 | ;; |
102 | esac |
103 | |
104 | # Check that the centralized catalog can be created, changed and deleted |
105 | if [ -z "$SGML_ROOT_CENTRALIZED" ] |
106 | then |
107 | echo -e $SGML_HELP_MESSAGE >&2 |
108 | exit 1 |
109 | fi |
110 | case $SGML_ACTION in |
111 | addition) |
112 | if [ -e "$SGML_ROOT_CENTRALIZED" -a ! -w "$SGML_ROOT_CENTRALIZED" ] |
113 | then |
114 | echo "`basename $0`: can not modify \"$SGML_ROOT_CENTRALIZED\"." >&2 |
115 | exit 2 |
116 | fi |
117 | ;; |
118 | removal) |
119 | if [ ! -w "$SGML_ROOT_CENTRALIZED" ] |
120 | then |
121 | echo "`basename $0`: can not modify \"$SGML_ROOT_CENTRALIZED\"." >&2 |
122 | exit 2 |
123 | fi |
124 | ;; |
125 | esac |
126 | |
127 | # Check that we have at least one ordinary package to process |
128 | if [ -z "$SGML_ROOT_ORDINARY" ] |
129 | then |
130 | echo -e $SGML_HELP_MESSAGE >&2 |
131 | exit 1 |
132 | fi |
133 | case $SGML_ACTION in |
134 | addition) |
135 | if [ ! -s $SGML_ROOT_ORDINARY ] |
136 | then |
137 | echo "`basename $0`: \"$SGML_ROOT_ORDINARY\" does not exist or is empty." >&2 |
138 | exit 2 |
139 | fi |
140 | ;; |
141 | esac |
142 | |
143 | # Installation or removal of pointers |
144 | case $SGML_ACTION in |
145 | addition) |
146 | echo "`basename $0`: addition of $SGML_ORDINARY in $SGML_CENTRALIZED" |
147 | if grep -q $SGML_ORDINARY $SGML_ROOT_CENTRALIZED 2>/dev/null |
148 | then |
149 | echo "Warning: $SGML_ORDINARY is already installed in the centralized catalog $SGML_CENTRALIZED" >&2 |
150 | else |
151 | echo "$SGML_POINTER \"$SGML_ORDINARY\"" >> $SGML_ROOT_CENTRALIZED |
152 | fi |
153 | grep -q $SGML_CENTRALIZED ${ROOT}etc/sgml/catalog 2>/dev/null |
154 | if [ $? -ne 0 ] |
155 | then |
156 | echo "`basename $0`: addition of $SGML_CENTRALIZED in ${ROOT}etc/sgml/catalog" |
157 | echo "$SGML_POINTER \"$SGML_CENTRALIZED\"" >> ${ROOT}etc/sgml/catalog |
158 | fi |
159 | ;; |
160 | removal) |
161 | echo "`basename $0`: removal of $SGML_ORDINARY from $SGML_CENTRALIZED" |
162 | if grep -q $SGML_ORDINARY $SGML_ROOT_CENTRALIZED 2>/dev/null |
163 | then |
164 | sed -e "\:$SGML_POINTER \"$SGML_ORDINARY\":d" < \ |
165 | $SGML_ROOT_CENTRALIZED > ${SGML_ROOT_CENTRALIZED}.new |
166 | mv ${SGML_ROOT_CENTRALIZED}.new $SGML_ROOT_CENTRALIZED |
167 | else |
168 | echo "Warning: $SGML_ORDINARY was not found in the centralized catalog $SGML_CENTRALIZED" >&2 |
169 | fi |
170 | if [ ! -s "$SGML_ROOT_CENTRALIZED" ] |
171 | then |
172 | rm $SGML_ROOT_CENTRALIZED |
173 | echo "`basename $0`: removal of $SGML_CENTRALIZED from ${ROOT}etc/sgml/catalog" |
174 | sed -e "\:$SGML_POINTER \"$SGML_CENTRALIZED\":d" < ${ROOT}etc/sgml/catalog > ${ROOT}etc/sgml/catalog.new |
175 | mv ${ROOT}etc/sgml/catalog.new ${ROOT}etc/sgml/catalog |
176 | fi |
177 | ;; |
178 | esac |
179 | |
180 | exit 0 |