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