cosmetic - fixes the labels in myplc yum.conf
[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
52    case "$pl_DISTRO" in
53        Fedora)
54            cat <<EOF
55 [main]
56 cachedir=/var/cache/yum
57 debuglevel=2
58 logfile=/var/log/yum.log
59 pkgpolicy=newest
60 distroverpkg=redhat-release
61 tolerant=1
62 exactarch=1
63 retries=10
64 obsoletes=1
65 gpgcheck=0
66 # Prevent yum-2.4 from loading additional repository definitions
67 # (e.g., from /etc/yum.repos.d/)
68 reposdir=/dev/null
69
70 [base]
71 name=${pl_DISTRO_NAME} - base
72 baseurl=http://${BUILD_HOST}/fedora/linux/core/${pl_DISTRO_RELEASE}/${pl_DISTRO_ARCH}/os/
73
74
75 [updates]
76 name=${pl_DISTRO_NAME} - updates
77 baseurl=http://${BUILD_HOST}/fedora/linux/core/updates/${pl_DISTRO_RELEASE}/${pl_DISTRO_ARCH}/
78
79 $(if [ "${pl_DISTRO_RELEASE}" -le 6 ] ; then cat << EXTRAS
80 [extras]
81 name=${pl_DISTRO_NAME} - extras
82 baseurl=http://${BUILD_HOST}/fedora/linux/extras/${pl_DISTRO_RELEASE}/${pl_DISTRO_ARCH}/
83 EXTRAS
84 fi)
85 EOF
86     ;;
87        *)
88            echo "$0: no support for this distribution $pl_DISTRO"
89            exit 1
90            ;;
91    esac
92 }
93
94 function sudoers_bootcustom_apache () {
95     cat <<EOF
96 User_Alias WWW = %apache,%root
97 Cmnd_Alias BOOTCUSTOM = /usr/share/bootcd/bootcustom.sh
98 WWW          ALL = NOPASSWD: BOOTCUSTOM 
99 EOF
100 }
101
102 # quick and dirty - might break anytime if docbook html output changes
103 function docbook_html_to_drupal () {
104     title=$1; shift
105     html=$1; shift
106     php=$1; shift
107
108     mkdir -p $(dirname $php)
109     if [ ! -f $html ] ; then
110         cat << __header_no_doc__ > $php
111 <?php
112 require_once 'plc_drupal.php';
113 drupal_set_title("$title - unavailable");
114 ?>
115 <p class='plc-warning'> Build-time error - could not locate documentation $html</p>
116 __header_no_doc__
117     else
118         # insert header, makes sure we have a trailing eol
119         (cat << __header_doc__ ; cat $html ) > $php
120 <?php
121 require_once 'plc_drupal.php';
122 drupal_set_title("$title");
123 ?>
124 __header_doc__
125         # ignore ed return status
126         set +e
127         # cuts off around the <body> </body>
128         # preserves the 4 first lines that we just added as a header
129         ed -s $php << __ed_script__
130 /BODY/
131 />/
132 s,><,<,
133 5,-d
134 $
135 ?/BODY?
136 s,><.*,>,
137 +
138 ;d
139 w
140 q
141 __ed_script__
142         set -e
143     fi
144 }