3 # Common functions for build scripts used by various packages
4 # incorporated (e.g., build, myplc, myplc-devel, vserver-reference)
6 # Marc E. Fiuczynski <mef@cs.princeton.edu>
7 # Copyright (C) 2007 The Trustees of Princeton University
9 # $Id: build.common,v 1.3 2007/08/31 03:17:34 mef Exp $
12 function pl_getDefaultFedoraRelease() {
13 # FC4 is currently the default release
17 function pl_getFedoraRelease() {
18 pl_getDefaultFedoraRelease
19 defaultFedoraRelease=$?
20 if [ -f "/etc/fedora-release" ] ; then
21 fedoraRelease=$(awk ' { if ($2=="Core") print $4; else print $3 } ' /etc/fedora-release)
22 [ $fedoraRelease -lt $defaultFedoraRelease ] && fedoraRelease=$defaultFedoraRelease
24 fedoraRelease=$defaultFedoraRelease
29 # select basearch of the host devel environment
30 pl_FEDORA_ARCH=$(uname -i)
32 # let mkfedora select one of its mirrors
38 # get patch to appropriate yumgroups.xml file
39 # XXX This path should be relative to PLDISTRO, as defined in
41 pl_YUMGROUPSXML="../build/groups/v4_yumgroups.xml"
43 function pl_process_fedora_options () {
46 while getopts "l:r:a:h" opt ; do
50 let shiftcount=$shiftcount+2
53 pl_FEDORA_RELEASE=$OPTARG
54 let shiftcount=$shiftcount+2
57 pl_FEDORA_ARCH=$OPTARG
58 let shiftcount=$shiftcount+2
61 echo "Usage: $0 [OPTION]..."
62 echo " -l url Fedora mirror location (default: $pl_FEDORA_URL)"
63 echo " -r release Fedora release number (default: $pl_FEDORA_RELEASE)"
64 echo " -a arch Fedora architecture (default: $pl_FEDORA_ARCH)"
65 echo " -h This message"
73 function pl_makedevs() {
75 # Clean ${vroot}/dev, but only when ${vroot}!=""
76 [ -n $vroot ] && rm -rf $vroot/dev
79 mknod -m 666 $vroot/dev/null c 1 3
80 mknod -m 666 $vroot/dev/zero c 1 5
81 mknod -m 666 $vroot/dev/full c 1 7
82 mknod -m 644 $vroot/dev/random c 1 8
83 mknod -m 644 $vroot/dev/urandom c 1 9
84 mknod -m 666 $vroot/dev/tty c 5 0
85 mknod -m 666 $vroot/dev/ptmx c 5 2
86 # For bash command substitution
87 ln -nsf ../proc/self/fd $vroot/dev/fd
89 # For df and linuxconf
93 mkdir -p $vroot/dev/pts
95 # (Might have to remove the following for vserver-reference.)
98 mkdir -p $vroot/dev/shm
101 mkdir -p $vroot/dev/net
102 mknod -m 600 $vroot/dev/net/tun c 10 200
104 # For mkinitrd (in case a kernel is being installed)
105 # As well for loop back mounting within a vserver.
106 for i in $(seq 0 7) ; do
107 mknod -m 640 $vroot/dev/loop$i b 7 $i
111 function pl_mkfedora() {
118 [ -n "$pl_FEDORA_URL" ] && options="$options -l $pl_FEDORA_URL"
119 [ -n "$pl_FEDORA_ARCH" ] && options="$options -a $pl_FEDORA_ARCH"
120 [ -n "$pl_FEDORA_RELEASE" ] && options="$options -r $pl_FEDORA_RELEASE"
121 # echo "mkfedora -v $options $root"
122 eval mkfedora -v $options $root
125 function pl_setup_chroot() {
130 pl_mkfedora $root $options
132 # Disable all services in reference image
133 chroot $root sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
135 # FC2 minilogd starts up during shutdown and makes unmounting
136 # impossible. Just get rid of it.
137 rm -f $root/sbin/minilogd
138 ln -nsf /bin/true $root/sbin/minilogd
140 # This tells the Boot Manager that it is okay to update
141 # /etc/resolv.conf and /etc/hosts whenever the network configuration
142 # changes. Users are free to delete this file.
143 touch $vroot/etc/AUTO_UPDATE_NET_FILES
146 # Move specified directories out of a src tree into a dst tree, and
147 # then for each moved directory create a symlink in src to dst.
148 function pl_move_dirs() {
155 for datadir in "$@" ; do
156 mkdir -p ${data}${datadir}
157 if [ -d ${root}/${datadir} -a ! -h ${root}/${datadir} ] ; then
158 (cd ${root} && find ./${datadir} | cpio -p -d -u ../${data}/)
160 rm -rf ${root}/${datadir}
161 mkdir -p $(dirname ${root}/${datadir})
162 ln -nsf /${store}/${datadir} ${root}/${datadir}
166 # Construct an image file from given some directory
167 # XXX in the future maybe use livecdtools?
168 function pl_make_image() {
173 # Leave about 100 MB free space and allow for about 20% inode overhead
174 bytes=$((($(du -sb $root | cut -f1) + $extraspace) * 120 / 100))
176 blocks=$(($bytes / $bs))
177 dd bs=$bs count=$blocks if=/dev/zero of=$image
178 mkfs.ext3 -b $bs -j -F $image
180 # Temporarily mount it
181 tmp=$(mktemp -d tmp.XXXXXX)
182 mount -o loop $image $tmp
183 trap "umount $tmp; rmdir $tmp" ERR INT
186 (cd $root && tar cpf - .) | (cd $tmp && tar xpf -)
194 # Fix permissions on tmp directories
195 function pl_fixtmp_permissions() {
197 chmod 1777 $root/tmp $root/usr/tmp $root/var/tmp
200 function pl_fixdirs() {
203 for datadir in datadirs ; do
204 if [ -h ${root}/${datadir} ] ; then
205 rm -f ${root}/${datadir}
206 mkdir -p ${root}/${datadir}