summaryrefslogtreecommitdiffstats
path: root/encap/bcfg2-0.8.2.ep
blob: e2dbfc135ca79eb05d6887e0590bba66c6c5015b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<?xml version="1.0"?>

<!-- $Id$ -->

<encap_profile
	profile_ver="1.0"
	pkgspec="bcfg2-0.8.2"
>

<environment
        variable="CC"
        value="gcc"
        type="set"
/>

<environment
        variable="PATH"
PLATFORM_IF_MATCH(solaris)
        value="/usr/local/lib/bcfg2/bin:/usr/local/bin:/usr/sfw/bin:/usr/ccs/bin:"
PLATFORM_ELSE
        value="/usr/local/lib/bcfg2/bin:/usr/local/bin:"
PLATFORM_ENDIF
        type="prepend"
/>

PLATFORM_IF_MATCH(linux)
PLATFORM_ELSE
<environment
        variable="MAKE"
        value="gmake"
        type="set"
/>
PLATFORM_ENDIF

<environment
        variable="LDFLAGS"
PLATFORM_IF_MATCH(linux)
        value="-L/usr/local/lib/bcfg2/lib -Wl,-rpath,/usr/local/lib/bcfg2/lib"
PLATFORM_ELSE_IF_MATCH(aix)
	value="-L/usr/local/lib/bcfg2/lib -Wl,-blibpath:/usr/local/lib/bcfg2/lib:/usr/lib"
PLATFORM_ELSE_IF_MATCH(solaris)
        value="-L/usr/local/lib/bcfg2/lib -R/usr/local/lib/bcfg2/lib:/usr/lib -YP,/usr/local/lib/bcfg2/lib:/usr/lib"
PLATFORM_ELSE
PLATFORM_ENDIF
        type="set"
/>

<environment
        variable="CPPFLAGS"
        value="-I/usr/local/lib/bcfg2/include"
        type="set"
/>

<source
url="http://www.pobox.com/users/dclark/mirror/bcfg/bcfg2-0.8.2.tar.gz
     ftp://ftp.mcs.anl.gov/pub/bcfg/bcfg2-0.8.2.tar.gz"
>

<configure>
:
</configure>

<build>
/usr/local/lib/bcfg2/bin/python setup.py build \
--build-base=${builddir}/build
</build>

<install>
/usr/local/lib/bcfg2/bin/python setup.py install \
--prefix=${ENCAP_SOURCE}/${ENCAP_PKGNAME}/lib/bcfg2
</install>

<clean>
/usr/local/lib/bcfg2/bin/python setup.py clean
</clean>

</source>

<prepackage type="set"><![CDATA[
# Make binaries available from /usr/local/bin
mkdir bin 2>/dev/null || exit 1
for FILE in `ls lib/bcfg2/bin`; do \
    ln -sf ../lib/bcfg2/bin/${FILE} bin/${FILE}; \
    if [ ! "`printf "${FILE}" | cut -c 1-5`x" = "bcfg2x" ]; then \
        ln -sf ../lib/bcfg2/bin/${FILE} bin/b2-${FILE}; \
    fi; \
done
# Make doc available from /usr/local/share/doc/bcfg2
mkdir share 2>/dev/null || exit 1
mkdir share/doc  2>/dev/null || exit 1
mkdir share/doc/bcfg2  2>/dev/null || exit 1
(cp ${builddir}/doc/manual.pdf share/doc/bcfg2/ || true)
cp -r ${builddir}/examples share/doc/bcfg2/
# Make man pages available from /usr/local/man
mv lib/bcfg2/share/man .
# Make tools dirs and copy over tools
mkdir lib/bcfg2/tools || exit 1
cp ${builddir}/tools/* lib/bcfg2/tools/
mkdir sbin 2>/dev/null || exit 1
mkdir share/doc/bcfg2/tools 2>/dev/null || exit 1
# Makes tools with #! line executable
for FILE in `ls lib/bcfg2/tools`; do \
	F="lib/bcfg2/tools/${FILE}"; \
    if [ "`head -1 ${F} | grep ^#\!/`x" != "x" ]; then \
        chmod 755 ${F} ; \
	fi; \
done
# Make executable tools available from /usr/local/sbin, and nonexecutable 
# tools/tools doc available from /usr/local/share/doc/bcfg2/tools
for FILE in `ls lib/bcfg2/tools`; do \
    F="lib/bcfg2/tools/${FILE}"; \
    if [ -x ${F} ]; then \
        ln -sf ../lib/bcfg2/tools/${FILE} sbin/b2-example-tool-${FILE}; \
	else \
		ln -sf ../../../../lib/bcfg2/tools/${FILE} share/doc/bcfg2/tools/${FILE}; \
    fi; \
done
# Make "this encap is installed" sentinal file available in /usr/local/var/encap
mkdir var 2>/dev/null || exit 1
mkdir var/encap 2>/dev/null || exit 1
touch var/encap/${ENCAP_PKGNAME}
]]></prepackage>

<include_file name="b2-regexplace.py" mode="0755"><![CDATA[
#!/usr/local/lib/bcfg2/bin/python

# regexplace: regular expression search and replace
# Stefano Spinucci
# 2006-02-07 (rev 4)
# Daniel Clark
# 2006-08-03 (modified for bcfg2 encap use)
# thanks to roadrunner.py
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52553
# for some ideas and some code
# tested with python 2.4.3

import sys, os, re, string

# pupulate and return 'fileslist[]' with all files inside 'dir' matching 'regx'
def make_files_list(dir, regx):

    # if dir is not a directory, exit with error
    if not os.path.isdir(dir):
        sys.exit(dir + ' is not a valid dir to walk !!!')

    # compile the search regexp
    cregex=re.compile(regx)

    # initialize the file list
    fileslist = []

    # loop on all files and select files matching 'regx'
    # don't include symbolic links
    for root, dirs, files in os.walk(dir):
        for name in files:
            if cregex.search(name) and name not in ("b2-regexplace.sh", "b2-regexplace.py", "postinstall", "postinstall.log", "bcfg2-0.8.2.ep"):
                path = os.path.join(root, name)
                if not os.path.islink(path):
                    fileslist.append(path)

    # return the file list
    return fileslist[:]

# in all files in 'fileslist' search the regexp 'searchregx' and replace
# with 'replacestring'; real substitution in files only if 'simulation' = 0
def replace_in_files(fileslist, searchregx, replacestring, simulation):

    # compile regexp
    cregex=re.compile(searchregx)
    
    # loop on all files
    for xfile in fileslist:

        # initialize the replace flag
        replaceflag=0

        # open file for read  
        readlines=open(xfile,'r').readlines()
        # intialize the list counter
        listindex = -1

        # search and replace in current file printing to the user changed lines
        for currentline in readlines:

            # increment the list counter
            listindex = listindex + 1

            # if the regexp is found
            if cregex.search(currentline):

                # make the substitution
                f=re.sub(searchregx,replacestring,currentline)

                # print the current filename, the old string and the new string
                print '\n' + xfile
                print '- ' + currentline ,
                if currentline[-1:]!='\n': print '\n' ,
                print '+ ' + f ,
                if f[-1:]!='\n': print '\n' ,

                # if substitution is real
                if simulation == 0:

                    # update the whole file variable ('readlines')
                    readlines[listindex] = f
                    replaceflag=1
                            
        # if some text was replaced
        # overwrite the original file
        if replaceflag==1:

            # open the file for writting  
            write_file=open(xfile,'w') 

            # overwrite the file  
            for line in readlines:
                write_file.write(line)

            # close the file
            write_file.close()

# main function
def main():

    # if parameters are wrong, exit with error
    if len(sys.argv) < 5:

        print 'Usage: regexplace.py dirname files-regexp search-regexp replace-string'

        sys.exit(1)

    # make the file list
    fileslist = make_files_list(sys.argv[1], sys.argv[2])

    # real execution
    replace_in_files(fileslist, sys.argv[3], sys.argv[4], 0)        

    # simulated execution
    #replace_in_files(fileslist, sys.argv[3], sys.argv[4], 1)
                
            
if __name__ == '__main__':
    main()
]]></include_file>

<include_file name="b2-regexplace.sh" mode="0755"><![CDATA[
#!/bin/sh

# This fixes paths for the bcfg2 encap packaging.

BASEDIR="`echo ${0} | xargs -n1 dirname`"
REGEXPLACE="${BASEDIR}/b2-regexplace.py"
PYTHON="/usr/local/lib/bcfg2/bin/python"
BINARIES="${REGEXPLACE} ${PYTHON}"
COMPILEALL="/usr/local/lib/bcfg2/lib/python2.4/compileall.py"

printf "**** Running postinstall with BASEDIR=|${BASEDIR}|...\n"
for BINARY in ${BINARIES}; do
    if [ ! -x ${BINARY} ]; then
        printf "\nERROR: ${BINARY} is not executable, exiting...\n"
        exit 1
    fi
done

for FILE in ${COMPILEALL}; do
    if [ ! -e ${FILE} ]; then
        printf "\nERROR: ${FILE} does not exist, exiting...\n"
        exit 1
    fi
done

# Do not run more than once; it does not converge.
# (/usr/local/usr/local/bcfg2.conf bug)
if [ "${1}x" != "firstx" ]; then
    printf "\nb2-regexplace.sh: Already ran\n\t${BASEDIR}/b2-regexplace.sh, not running again...\n"
    exit 0
fi

printf "\nRemoving bcfg2 .pyc files...\n"
find ${BASEDIR} -type f | grep "\.pyc$" | xargs -n1 rm

printf "\nFixing bcfg2 paths...\n"

printf "\nReplacing \"/etc/bcfg2.conf\" with \"/usr/local/etc/bcfg2.conf\"...\n"
${REGEXPLACE} ${BASEDIR} .\* \/etc\/bcfg2.conf \/usr\/local\/etc\/bcfg2.conf

printf "\nReplacing \"/local/sbin/epkg\" with \"/usr/local/bin/epkg\"...\n"
${REGEXPLACE} ${BASEDIR} .\* \/local\/sbin\/epkg \/usr\/local\/bin\/epkg

printf "\nReplacing \"/usr/share/bcfg2\" with \"/usr/local/lib/bcfg2/share/bcfg2\"...\n"
${REGEXPLACE} ${BASEDIR} .\* \/usr\/share\/bcfg2\/ \/usr\/local\/lib\/bcfg2\/share\/bcfg2\/

printf "\nReplacing \"prefix = '/usr'\" with \"prefix = '/usr/local/lib/bcfg2'\"...\n"
${REGEXPLACE} ${BASEDIR} .\* prefix\ =\ \'\/usr\' prefix\ =\ \'/usr/local/lib/bcfg2\'

printf "\nReplacing \"xmllint\" with \"/usr/local/bin/b2-xmllint\"...\n"
${REGEXPLACE} ${BASEDIR} .\* xmllint \/usr\/local\/bin\/b2-xmllint

printf "\nReplacing \"#!/usr/bin/env python\" with "
printf "\"#!/usr/local/lib/bcfg2/bin/python\"...\n"
${REGEXPLACE} ${BASEDIR} .\* \#\!\/usr\/bin\/env\ python \#\!\/usr\/local\/lib\/bcfg2\/bin\/python

printf "\nReplacing \"#!/usr/bin/perl\" with \"#!/usr/bin/env perl\"...\n"
${REGEXPLACE} ${BASEDIR} .\* \#\!\/usr\/bin\/perl \#\!\/usr\/bin\/env\ perl

printf "\nReplacing \"#!/usr/bin/python\" with "
printf "\"#!/usr/local/lib/bcfg2/bin/python\"...\n"
${REGEXPLACE} ${BASEDIR} .\* \#\!\/usr\/bin\/python \#\!\/usr\/local\/lib\/bcfg2\/bin\/python

printf "\nCreating bcfg2 .pyc files...\n"
${PYTHON} ${COMPILEALL} ${BASEDIR}

exit 0
]]></include_file>

<include_file name="postinstall" mode="0755"><![CDATA[
#!/bin/sh
BASEDIR="`echo ${0} | xargs -n1 dirname`"

if [ ! -e ${BASEDIR}/postinstall.log ]; then
    test -x ${BASEDIR}/b2-regexplace.sh || exit 1
    ${BASEDIR}/b2-regexplace.sh first > ${BASEDIR}/postinstall.log 2>&1 3>&1
else
    printf "\npostinstall: already ran\n\t${BASEDIR}/b2-regexplace.sh, not running again...\n" >> ${BASEDIR}/postinstall.log
fi
]]></include_file>


<encapinfo>
description Bcfg2 - Provides a declarative interface to system configuration
prereq pkgspec >= bcfg2-zlib-1.2.3
prereq pkgspec >= bcfg2-libiconv-1.9.2
prereq pkgspec >= bcfg2-gettext-0.14.5
prereq pkgspec >= bcfg2-openssl-0.9.8b
prereq pkgspec >= bcfg2-libstdc++-0.1
prereq pkgspec >= bcfg2-libgcc-0.1
prereq pkgspec >= bcfg2-python-2.4.3
prereq pkgspec >= bcfg2-pyopenssl-0.6
prereq pkgspec >= bcfg2-libxml2-2.6.26
prereq pkgspec >= bcfg2-libxslt-1.1.17
prereq pkgspec >= bcfg2-lxml-1.0.1
</encapinfo>

</encap_profile>