Remove traces of old NM (3.3.x).
[myplc.git] / build.functions
1 # -*-Shell-script-*-
2 #
3 # Common functions for MyPLC build scripts (build_devel.sh and
4 # build.sh)
5 #
6 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Copyright (C) 2006 The Trustees of Princeton University
8 #
9 # $Id$
10 #
11
12 PATH=/sbin:/bin:/usr/sbin:/usr/bin
13
14 # In both a normal CVS environment and a PlanetLab RPM
15 # build environment, all of our dependencies are checked out into
16 # directories at the same level as us.
17 if [ -d ../build ] ; then
18     PATH=$PATH:../build
19     srcdir=..
20 else
21     echo "Error: Could not find $(cd .. && pwd -P)/build/"
22     exit 1
23 fi
24
25 export PATH
26
27 . build.common
28
29 pl_process_fedora_options $@
30 shiftcount=$?
31 shift $shiftcount
32
33 # XXX Backwards compatibility with old myplc-devel environment
34 # We may be running inside a myplc-devel environment, which can
35 # override these defaults.
36 if [ -f /etc/planetlab/plc_config ] ; then
37     . /etc/planetlab/plc_config
38     [ ! -z "$PLC_DEVEL_FEDORA_RELEASE" ] && pl_FEDORA_RELEASE=$PLC_DEVEL_FEDORA_RELEASE
39     [ ! -z "$PLC_DEVEL_FEDORA_ARCH" ] && pl_FEDORA_ARCH=$PLC_DEVEL_FEDORA_ARCH
40     [ ! -z "$PLC_DEVEL_FEDORA_URL" ] && pl_FEDORA_URL=$PLC_DEVEL_FEDORA_URL
41 fi
42
43 # Do not tolerate errors
44 set -e
45
46 # Be verbose
47 set -x
48
49 function yum_conf_to_build_host () {
50    BUILD_HOST=$(hostname)
51    cat <<EOF
52 [main]
53 cachedir=/var/cache/yum
54 debuglevel=2
55 logfile=/var/log/yum.log
56 pkgpolicy=newest
57 distroverpkg=redhat-release
58 tolerant=1
59 exactarch=1
60 retries=10
61 obsoletes=1
62 gpgcheck=0
63 # Prevent yum-2.4 from loading additional repository definitions
64 # (e.g., from /etc/yum.repos.d/)
65 reposdir=/dev/null
66
67 [base]
68 name=Fedora Core 4 - i386 - base
69 baseurl=http://${BUILD_HOST}/fedora/linux/core/${pl_DISTRO_RELEASE}/${pl_DISTRO_ARCH}/os/
70
71
72 [updates]
73 name=Fedora Core 4 - i386 - updates
74 baseurl=http://${BUILD_HOST}/fedora/linux/core/updates/${pl_DISTRO_RELEASE}/${pl_DISTRO_ARCH}/
75
76 $(if [ "${pl_DISTRO_RELEASE}" -le 6 ] ; then cat << EXTRAS
77 [extras]
78 name=Fedora Core 4 - i386 - extras
79 baseurl=http://${BUILD_HOST}/fedora/linux/extras/${pl_DISTRO_RELEASE}/${pl_DISTRO_ARCH}/
80 EXTRAS
81 fi)
82 EOF
83
84 }
85
86 function sudoers_bootcustom_apache () {
87     cat <<EOF
88 User_Alias WWW = %apache,%root
89 Cmnd_Alias BOOTCUSTOM = /usr/share/bootcd/bootcustom.sh
90 WWW          ALL = NOPASSWD: BOOTCUSTOM 
91 EOF
92 }
93
94 # quick and dirty - might break anytime if docbook html output changes
95 function docbook_html_to_drupal () {
96     title=$1; shift
97     html=$1; shift
98     php=$1; shift
99
100     mkdir -p $(dirname $php)
101     if [ ! -f $html ] ; then
102         cat << __header_no_doc__ > $php
103 <?php
104 require_once 'plc_drupal.php';
105 drupal_set_title("$title - unavailable");
106 ?>
107 <p class='plc-warning'> Build-time error - could not locate documentation $html</p>
108 __header_no_doc__
109     else
110         # insert header, makes sure we have a trailing eol
111         (cat << __header_doc__ ; cat $html ) > $php
112 <?php
113 require_once 'plc_drupal.php';
114 drupal_set_title("$title");
115 ?>
116 __header_doc__
117         # ignore ed return status
118         set +e
119         # cuts off around the <body> </body>
120         # preserves the 4 first lines that we just added as a header
121         ed -s $php << __ed_script__
122 /BODY/
123 />/
124 s,><,<,
125 5,-d
126 $
127 ?/BODY?
128 s,><.*,>,
129 +
130 ;d
131 w
132 q
133 __ed_script__
134         set -e
135     fi
136 }