replacing pldistro-fcdistro-*.lst with a pldistro-*.lst with variants embedded
[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 # Make a basic chroot at the specified location given the specified
50 # configuration.
51 make_chroot_from_lst() {
52     root=$1
53     fcdistro=1; shift
54     lst=$2
55
56     packages=$(pl_getPackagesOptions2 $fcdistro $lst)
57     groups=$(pl_getGroupsOptions2 $fcdistro $lst) 
58
59     pl_setup_chroot $root $packages $groups
60 }
61
62 # Move specified directories out of the chroot and into a "data"
63 # directory that will be bind mounted on /data inside the chroot.
64 #move_datadirs() {
65 #    root=$1
66 #    data=$2
67 #    shift 2
68 #    pl_move_dirs $root $data /data "$@"
69 #}
70
71 # Make loopback filesystem from specified location
72 #make_image() {
73 #    root=$1
74 #    image=$2
75 #    pl_make_image $root $image 100000000
76 #}
77
78 function yum_conf_to_build_host () {
79    BUILD_HOST=$(hostname)
80    cat <<EOF
81 [main]
82 cachedir=/var/cache/yum
83 debuglevel=2
84 logfile=/var/log/yum.log
85 pkgpolicy=newest
86 distroverpkg=redhat-release
87 tolerant=1
88 exactarch=1
89 retries=10
90 obsoletes=1
91 gpgcheck=0
92 # Prevent yum-2.4 from loading additional repository definitions
93 # (e.g., from /etc/yum.repos.d/)
94 reposdir=/dev/null
95
96 [base]
97 name=Fedora Core 4 - i386 - base
98 baseurl=http://${BUILD_HOST}/fedora/linux/core/${pl_DISTRO_RELEASE}/${pl_DISTRO_ARCH}/os/
99
100
101 [updates]
102 name=Fedora Core 4 - i386 - updates
103 baseurl=http://${BUILD_HOST}/fedora/linux/core/updates/${pl_DISTRO_RELEASE}/${pl_DISTRO_ARCH}/
104
105 $(if [ "${pl_DISTRO_RELEASE}" -le 6 ] ; then cat << EXTRAS
106 [extras]
107 name=Fedora Core 4 - i386 - extras
108 baseurl=http://${BUILD_HOST}/fedora/linux/extras/${pl_DISTRO_RELEASE}/${pl_DISTRO_ARCH}/
109 EXTRAS
110 fi)
111 EOF
112
113 }
114
115 function sudoers_bootcustom_apache () {
116     cat <<EOF
117 User_Alias WWW = %apache,%root
118 Cmnd_Alias BOOTCUSTOM = /usr/share/bootcd/bootcustom.sh
119 WWW          ALL = NOPASSWD: BOOTCUSTOM 
120 EOF
121 }
122
123 # quick and dirty - might break anytime if docbook html output changes
124 function docbook_html_to_drupal () {
125     title=$1; shift
126     html=$1; shift
127     php=$1; shift
128
129     mkdir -p $(dirname $php)
130     if [ ! -f $html ] ; then
131         cat << __header_no_doc__ > $php
132 <?php
133 require_once 'plc_drupal.php';
134 drupal_set_title("$title - unavailable");
135 ?>
136 <p class='plc-warning'> Build-time error - could not locate documentation $html</p>
137 __header_no_doc__
138     else
139         # insert header, makes sure we have a trailing eol
140         (cat << __header_doc__ ; cat $html ) > $php
141 <?php
142 require_once 'plc_drupal.php';
143 drupal_set_title("$title");
144 ?>
145 __header_doc__
146         # ignore ed return status
147         set +e
148         # cuts off around the <body> </body>
149         # preserves the 4 first lines that we just added as a header
150         ed -s $php << __ed_script__
151 /BODY/
152 />/
153 s,><,<,
154 5,-d
155 $
156 ?/BODY?
157 s,><.*,>,
158 +
159 ;d
160 w
161 q
162 __ed_script__
163         set -e
164     fi
165 }