summaryrefslogtreecommitdiffstats
path: root/encap/src/encap-profiles/bcfg2-0.9.2.ep
blob: 61e4e317df35ef24d2e10703eda9a577d00c36be (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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<?xml version="1.0"?>

<!-- $Id$ -->

<!-- To make this work with a new version of bcfg2, first do a "svn mv" -->
<!-- of this file to the new version name, and then do a global search- -->
<!-- replace of the version with the new version (i.e. search for       -->
<!-- "0.8.3pre3" and replace with "0.8.3") - DO NOT DO IT MANUALLY,     -->
<!-- the version string is referenced by some of the included files.    -->

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

<prereq package="m4-1.4.4" />
<prereq package="patch-2.5.9" />
<prereq package="bcfg2-pkg-config-0.21" />
<prereq package="bcfg2-python-2.4.4" />
<prereq package="bcfg2-pyopenssl-0.6" />
<prereq package="bcfg2-elementtree-1.2.6" />

<environment
        variable="CC"
        value="gcc -static-libgcc"
        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 -YP,/usr/local/lib/bcfg2/lib:/usr/lib:/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://encapsrcdist/mirror/bcfg/bcfg2-0.9.2.tar.gz
     http://mirror.opensysadmin.com/bcfg/bcfg2-0.9.2.tar.gz
     ftp://ftp.mcs.anl.gov/pub/bcfg/bcfg2-0.9.2.tar.gz"
>

<patch options="-p1"><![CDATA[
--- bcfg2-0.9.2/src/lib/Client/XML.py.orig	2006-10-09 23:56:01.000000000 -0400
+++ bcfg2-0.9.2/src/lib/Client/XML.py	2006-10-10 00:02:42.000000000 -0400
@@ -1,24 +1,13 @@
 '''XML lib compatibility layer for the Bcfg2 client'''
 __revision__ = '$Revision: 2064 $'
 
-# library will use lxml, then builtin xml.etree, then ElementTree
+# Changed for EncapPackages - always use ElementTree, or raise an exception
 
 try:
-    from lxml.etree import Element, SubElement, XML, tostring
-    from lxml.etree import XMLSyntaxError as ParseError
-    driver = 'lxml'
+    from elementtree.ElementTree import Element, SubElement, XML, tostring
+    from xml.parsers.expat import ExpatError as ParseError
+    driver = 'etree'
 except ImportError:
-    # lxml not available 
-    try:
-        from xml.etree.ElementTree import Element, SubElement, XML, tostring
-        from xml.parsers.expat import ExpatError as ParseError
-        driver = 'etree-py'
-    except ImportError:
-        try:
-            from elementtree.ElementTree import Element, SubElement, XML, tostring
-            from xml.parsers.expat import ExpatError as ParseError
-            driver = 'etree'
-        except ImportError:
-            print "Failed to load lxml, xml.etree and elementtree.ElementTree"
-            print "Cannot continue"
-            raise SystemExit, 1
+    print "Failed to load elementtree.ElementTree"
+    print "Cannot continue"
+    raise SystemExit, 1

]]></patch>

<configure type="unset" />

<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
test -d bin || mkdir bin
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
test -d share || mkdir share
test -d share/doc || mkdir share/doc
test -d share/doc/bcfg2 || mkdir share/doc/bcfg2
(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
test -d lib/bcfg2/tools || mkdir lib/bcfg2/tools
cp ${builddir}/tools/* lib/bcfg2/tools/
test -d sbin || mkdir sbin
test -d share/doc/bcfg2/tools || mkdir share/doc/bcfg2/tools
# 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
# daemontools stuff
test -d var || mkdir var
test -d var/svc.d || mkdir var/svc.d
test -d var/svc.d/bcfg2-client || mkdir var/svc.d/bcfg2-client
test -d var/svc.d/bcfg2-client/log || mkdir var/svc.d/bcfg2-client/log
test -d var/svc.d/bcfg2-server || mkdir var/svc.d/bcfg2-server
test -d var/svc.d/bcfg2-server/log  || mkdir var/svc.d/bcfg2-server/log
# Make "this encap is installed" sentinal file available in /usr/local/var/encap
test -d  var/encap || mkdir var/encap
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.4

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.9.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 [ ! -f ${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="var/svc.d/bcfg2-client/bcfg2-client.sh" mode="0755"><![CDATA[
#!/bin/sh

# note: variables provided from environment with envdir:
#       /usr/local/etc/default/bcfg2-client/env/OPTIONS
#       /usr/local/etc/default/bcfg2-client/env/RUN_INTERVAL_SECONDS

ENVDIR="/usr/local/etc/default/bcfg2-client/env"

# make sure we have options
if [ ! -f ${ENVDIR}/OPTIONS ]; then
    printf "WARNING: ${ENVDIR}/OPTIONS\n"
    printf "WARNING: does not exist. Using default of \"-q -v -d -n\"\n"
    OPTIONS="-q -v -d -n"
fi

# make sure we have a sleep variable
if [ "${RUN_INTERVAL_SECONDS}x" = "x" ]; then
    printf "WARNING: ${ENVDIR}/RUN_INTERVAL_SECONDS\n"
    printf "WARNING: does not exist or has no value.\n"
    printf "WARNING: Using default of 3600 seconds between runs.\n"
    RUN_INTERVAL_SECONDS=3600
fi

# loop forever
while :
do
    printf "*** starting /usr/local/bin/bcfg2 ${OPTIONS} ...\n"
    /usr/local/bin/bcfg2 ${OPTIONS}
    printf "*** sleeping ${RUN_INTERVAL_SECONDS} seconds ...\n"
    sleep ${RUN_INTERVAL_SECONDS}
done

exit 0
]]></include_file>

<include_file name="var/svc.d/bcfg2-client/run" mode="0755"><![CDATA[
#!/bin/sh
exec 2>&1
printf "*** exec /command/envdir /usr/local/etc/default/bcfg2-client/env ./bcfg2-client.sh ...\n"
exec /command/envdir /usr/local/etc/default/bcfg2-client/env ./bcfg2-client.sh
]]></include_file>

<include_file name="var/svc.d/bcfg2-client/log/run" mode="0755"><![CDATA[
#!/bin/sh
exec 2>&1
exec /command/multilog t /usr/local/var/multilog/bcfg2-client
]]></include_file>

<include_file name="var/svc.d/bcfg2-server/run" mode="0755"><![CDATA[
#!/bin/sh
exec 2>&1
/command/envdir /usr/local/etc/default/bcfg2-server/env /bin/sh -c '\
    printf "*** exec /usr/local/bin/bcfg2-server ${OPTIONS} ...\n"'
exec /command/envdir /usr/local/etc/default/bcfg2-server/env /bin/sh -c '\
    exec /usr/local/bin/bcfg2-server ${OPTIONS}'
]]></include_file>

<include_file name="var/svc.d/bcfg2-server/log/run" mode="0755"><![CDATA[
#!/bin/sh
exec 2>&1
exec /command/multilog t /usr/local/var/multilog/bcfg2-server
]]></include_file>

<include_file name="postinstall" mode="0755"><![CDATA[
#!/bin/sh
BASEDIR="`echo ${0} | xargs -n1 dirname`"
MULTILOG="/usr/local/var/multilog"
DEFAULT="/usr/local/etc/default"

# Fix paths
if [ ! -f ${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

# Make sure log directories exist
test -d /usr/local/var || mkdir /usr/local/var
test -d $MULTILOG || mkdir $MULTILOG
test -d $MULTILOG/bcfg2-client || mkdir $MULTILOG/bcfg2-client
test -d $MULTILOG/bcfg2-server || mkdir $MULTILOG/bcfg2-server

# Make sure environment directories exist
test -d /usr/local/etc || mkdir /usr/local/etc
test -d $DEFAULT || mkdir $DEFAULT
test -d $DEFAULT/bcfg2-client || mkdir $DEFAULT/bcfg2-client
test -d $DEFAULT/bcfg2-client/env || mkdir $DEFAULT/bcfg2-client/env
test -d $DEFAULT/bcfg2-server || mkdir $DEFAULT/bcfg2-server
test -d $DEFAULT/bcfg2-server/env || mkdir $DEFAULT/bcfg2-server/env

# Put in default client environment if it didn't exist
if [ ! -f $DEFAULT/bcfg2-client/.SENTINEL ]; then
    touch $DEFAULT/bcfg2-client/.SENTINEL
    echo "-q -v -d -n" > $DEFAULT/bcfg2-client/env/OPTIONS
    echo "3600" > $DEFAULT/bcfg2-client/env/RUN_INTERVAL_SECONDS
fi

# Put in default server environment if it didn't exist
if [ ! -f $DEFAULT/bcfg2-server/.SENTINEL ]; then
    touch $DEFAULT/bcfg2-server/.SENTINEL
    echo "-v" > $DEFAULT/bcfg2-server/env/OPTIONS
fi
]]></include_file>

<include_file name="preremove" mode="0755"><![CDATA[
#!/bin/sh

printf "Running bcfg2 preremove script...\n"
date

if [ -h /service/bcfg2-client ]; then
    printf "INFO: Removing /service/bcfg2-client...\n"
    /command/svrm /service/bcfg2-client
fi

if [ -h /service/bcfg2-server ]; then
    printf "INFO: Removing /service/bcfg2-server...\n"
    /command/svrm /service/bcfg2-server
fi

printf "Finished bcfg2 preremove script.\n"
]]></include_file>

<encapinfo>
description Bcfg2 - Provides a declarative interface to system configuration
prereq pkgspec >= bcfg2-python-2.4.4
prereq pkgspec >= bcfg2-elementtree-1.2.6
</encapinfo>

</encap_profile>