33fe4b753dfa694ab3859f61498805bc7d5195a9
[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 # this is fragile, as the actual layout may vary from one mirror to the other
50 # however this should be in line with the layouts obtained 
51 # when running build/vbuild-fedora-mirror.sh
52
53 function yum_conf_to_build_host () {
54     build_dir=$1; shift
55     BUILD_HOST=$(hostname)
56
57     cat <<EOF
58 [main]
59 cachedir=/var/cache/yum
60 debuglevel=2
61 logfile=/var/log/yum.log
62 pkgpolicy=newest
63 distroverpkg=redhat-release
64 tolerant=1
65 exactarch=1
66 retries=10
67 obsoletes=1
68 gpgcheck=0
69 # Prevent yum-2.4 from loading additional repository definitions
70 # (e.g., from /etc/yum.repos.d/)
71 reposdir=/dev/null
72
73 EOF
74
75     template=$build_dir/mirroring/${pl_DISTRO_NAME}/yum.repos.d/building.repo.in
76     if [ ! -f $template ] ; then
77         echo "# MyPLC/$0: cannot find template $template"
78     else
79         sed -e s,@MIRRORURL@,http://${BUILD_HOST}/mirror/, $template
80     fi
81 }
82
83 # quick and dirty - might break anytime if docbook html output changes
84 function docbook_html_to_drupal () {
85     title=$1; shift
86     html=$1; shift
87     php=$1; shift
88
89     mkdir -p $(dirname $php)
90     if [ ! -f $html ] ; then
91         cat << __header_no_doc__ > $php
92 <?php
93 require_once 'plc_drupal.php';
94 drupal_set_title("$title - unavailable");
95 ?>
96 <p class='plc-warning'> Build-time error - could not locate documentation $html</p>
97 __header_no_doc__
98     else
99         # insert header, makes sure we have a trailing eol
100         (cat << __header_doc__ ; cat $html ) > $php
101 <?php
102 require_once 'plc_drupal.php';
103 drupal_set_title("$title");
104 ?>
105 __header_doc__
106         # ignore ed return status
107         set +e
108         # cuts off around the <body> </body>
109         # preserves the 4 first lines that we just added as a header
110         ed -s $php << __ed_script__
111 /BODY/
112 />/
113 s,><,<,
114 5,-d
115 $
116 ?/BODY?
117 s,><.*,>,
118 +
119 ;d
120 w
121 q
122 __ed_script__
123         set -e
124     fi
125 }