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.1.2.3 2007/08/30 17:43:08 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
35 pl_getDefaultFedoraRelease
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/net
94 mknod -m 600 $vroot/dev/net/tun c 10 200
97 mkdir -p $vroot/dev/pts
100 mkdir -p $vroot/dev/shm
102 # For mkinitrd (in case a kernel is being installed)
103 for i in $(seq 0 7) ; do
104 mknod -m 640 $vroot/dev/loop$i b 7 $i
108 function pl_mkfedora() {
115 [ -n "$pl_FEDORA_URL" ] && options="$options -l $pl_FEDORA_URL"
116 [ -n "$pl_FEDORA_ARCH" ] && options="$options -a $pl_FEDORA_ARCH"
117 [ -n "$pl_FEDORA_RELEASE" ] && options="$options -r $pl_FEDORA_RELEASE"
118 # echo "mkfedora -v $options $root"
119 eval mkfedora -v $options $root
122 function pl_setup_chroot() {
127 pl_mkfedora $root $options
129 # Disable all services in reference image
130 chroot $root sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
132 # FC2 minilogd starts up during shutdown and makes unmounting
133 # impossible. Just get rid of it.
134 rm -f $root/sbin/minilogd
135 ln -nsf /bin/true $root/sbin/minilogd
137 # This tells the Boot Manager that it is okay to update
138 # /etc/resolv.conf and /etc/hosts whenever the network configuration
139 # changes. Users are free to delete this file.
140 touch $vroot/etc/AUTO_UPDATE_NET_FILES
143 # Move specified directories out of a src tree into a dst tree, and
144 # then for each moved directory create a symlink in src to dst.
145 function pl_move_dirs() {
152 for datadir in "$@" ; do
153 mkdir -p ${data}${datadir}
154 if [ -d ${root}/${datadir} -a ! -h ${root}/${datadir} ] ; then
155 (cd ${root} && find ./${datadir} | cpio -p -d -u ../${data}/)
157 rm -rf ${root}/${datadir}
158 mkdir -p $(dirname ${root}/${datadir})
159 ln -nsf /${store}/${datadir} ${root}/${datadir}
163 # Construct an image file from given some directory
164 # XXX in the future maybe use livecdtools?
165 function pl_make_image() {
170 # Leave about 100 MB free space and allow for about 20% inode overhead
171 bytes=$((($(du -sb $root | cut -f1) + $extraspace) * 120 / 100))
173 blocks=$(($bytes / $bs))
174 dd bs=$bs count=$blocks if=/dev/zero of=$image
175 mkfs.ext3 -b $bs -j -F $image
177 # Temporarily mount it
178 tmp=$(mktemp -d tmp.XXXXXX)
179 mount -o loop $image $tmp
180 trap "umount $tmp; rmdir $tmp" ERR INT
183 (cd $root && tar cpf - .) | (cd $tmp && tar xpf -)
191 # Fix permissions on tmp directories
192 function pl_fixtmp_permissions() {
194 chmod 1777 $root/tmp $root/usr/tmp $root/var/tmp
197 function pl_fixdirs() {
200 for datadir in datadirs ; do
201 if [ -h ${root}/${datadir} ] ; then
202 rm -f ${root}/${datadir}
203 mkdir -p ${root}/${datadir}