source: trunk/base/portmgr/buildall.sh @ 15487

Last change on this file since 15487 was 15338, checked in by jmpp, 15 years ago

Submitted by: jmpp@
Reviewed by: jberry@

The pormgr/ dir is now out of src/, as it doesn't have much to do with our sources.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.9 KB
Line 
1#!/bin/sh
2
3# Author: Jordan K. Hubbard
4# Date: 2004/12/10
5#
6# Declare all the various shell functions which do the heavy lifting.
7# If you want to see the main body of this script, go to the end of the file.
8
9# What we want to call the base chroot images
10CHROOTBASE=chrootbase.sparseimage
11DPORTSCACHE=dportscache.sparseimage
12FSTYPE=HFSX
13
14# Some conservative (and large) defaults.
15BASE_PADDING=16000000
16DPORTSCACHE_SIZE=65536M
17
18# deal with fatal errors
19bomb() {
20        echo "Error: $*"
21        echo "BASEDEV=${BASEDEV} DPORTSDEV=${DPORTSDEV}"
22        exit 1
23}
24
25# Everything we need to create the base chroot disk image (populated from host)
26mkchrootbase() {
27        if [ -f ${CHROOTBASE} ]; then
28                echo "Using existing ${CHROOTBASE} for efficiency"
29        else
30                dir=$1
31                mkdir -p $dir
32
33                # Add to this list as you find minimum dependencies DP really needs.
34                chrootfiles="bin sbin etc tmp var/log var/spool var/run var/tmp var/db private/etc private/tmp private/var dev/null usr Developer System/Library Library"
35
36                echo "Calculating chroot base image size..."
37                # start with this size to account for other overhead
38                sz=${BASE_PADDING}
39                if [ "`uname -r|tr -d .`" -ge 800 ]; then
40                        # hack-around for Tiger
41                        sz=$((sz + 8000000))
42                else
43                        for i in $chrootfiles; do
44                                mysz=`cd /; du -sk $i |awk '{print $1}'`
45                                sz=$(($sz + $mysz))
46                        done
47                fi
48                echo "Creating bootstrap disk image of ${sz}K bytes"
49                hdiutil create -size ${sz}k -fs ${FSTYPE} -volname base ${CHROOTBASE} > /dev/null
50                BASEDEV=`hdiutil attach ${CHROOTBASE} -mountpoint $dir -noverify 2>&1 | awk '/dev/ {if (x == 0) {print $1; x = 1}}'`
51                echo "Image attached as $BASEDEV"
52                echo "Copying chroot files into bootstrap disk image"
53                for i in $chrootfiles; do
54                        pax -pe -rw /$i $dir 2>/dev/null
55                        # special case for pax
56                        cp /bin/pax $dir/bin/pax
57                done
58                # special case nukes to prevent builder pollution
59                rm -rf $dir/usr/X11R6 $dir/etc/X11
60                rm -rf $dir/opt/local $dir/etc/ports
61                # If there are any work-arounds, apply them now
62                if [ -f chroot-fixups.tar.gz ]; then
63                        echo "Found chroot-fixups.tar.gz - applying to new chroot"
64                        tar xpzf chroot-fixups.tar.gz -C $dir
65                fi
66                if [ -f darwinports.tar.gz ]; then
67                        echo "Found darwinports.tar.gz - copying into chroot"
68                        tar -xpzf darwinports.tar.gz -C $dir
69                elif [ -d darwinports ]; then
70                        pax -rw darwinports $dir
71                else
72                        echo "no darwinports.tar.gz or darwinports directory found - please fix this and try again."
73                        exit 1
74                fi
75                bootstrapdports $dir
76        fi
77        if [ -f ${DPORTSCACHE} ]; then
78                echo "Using existing ${DPORTSCACHE} for efficiency"
79        else
80                echo "Creating dports cache of size ${DPORTSCACHE_SIZE}"
81                hdiutil create -size ${DPORTSCACHE_SIZE} -fs ${FSTYPE} -volname distfiles ${DPORTSCACHE} > /dev/null
82                DPORTSDEV=`hdiutil attach ${DPORTSCACHE} -mountpoint $dir -noverify 2>&1 | awk '/dev/ {if (x == 0) {print $1; x = 1}}'`
83                mkdir -p $dir/distfiles
84                mkdir -p $dir/packages/darwin/powerpc
85                hdiutil detach $DPORTSDEV -force >& /dev/null && DPORTSDEV=""
86        fi
87}
88
89bootstrapdports() {
90        dir=$1
91        cat > $dir/bootstrap.sh << EOF
92#!/bin/sh
93cd darwinports/base
94./configure
95make all install
96make clean
97echo "file:///darwinports/dports" > /opt/local/etc/ports/sources.conf
98echo "BatchMode yes" >> /etc/ssh_config
99EOF
100        if [ "$PKGTYPE" = "dpkg" ]; then
101            echo "/opt/local/bin/port install dpkg" >> $dir/bootstrap.sh
102        fi
103        chmod 755 $dir/bootstrap.sh
104        echo "Bootstrapping darwinports in chroot"
105        /sbin/mount_devfs devfs ${dir}/dev
106        /sbin/mount_fdesc -o union fdesc ${dir}/dev
107        chroot $dir /bootstrap.sh && rm $dir/bootstrap.sh
108        umount -f ${dir}/dev
109        umount -f ${dir}/dev
110        hdiutil detach $BASEDEV -force >& /dev/null && BASEDEV=""
111}
112
113# Set up the base chroot image
114prepchroot() {
115        dir=$1
116        rm -f ${CHROOTBASE}.shadow
117        BASEDEV=`hdiutil attach ${CHROOTBASE} -mountpoint $dir -shadow -noverify 2>&1 | awk '/dev/ {if (x == 0) {print $1; x = 1}}'`
118        mkdir -p $dir/.vol
119        DPORTSDEV=`hdiutil attach ${DPORTSCACHE} -mountpoint $dir/opt/local/var/db/dports -union -noverify 2>&1 | awk '/dev/ {if (x == 0) {print $1; x = 1}}'`
120        /sbin/mount_devfs devfs $dir/dev || bomb "unable to mount devfs"
121        /sbin/mount_fdesc -o union fdesc $dir/dev || bomb "unable to mount fdesc"
122}
123
124# Undo the work of prepchroot
125teardownchroot() {
126        dir=$1
127        umount -f $dir/dev  || (echo "unable to umount devfs")
128        umount -f $dir/dev  || (echo "unable to umount fdesc")
129        [ -z "$DPORTSDEV" ] || (hdiutil detach $DPORTSDEV -force >& /dev/null || bomb "unable to detach DPORTSDEV")
130        DPORTSDEV=""
131        if [ ! -z "$BASEDEV" ]; then
132                if ! hdiutil detach $BASEDEV -force >& /dev/null; then
133                        echo "Warning: Unable to detach BASEDEV ($BASEDEV)"
134                fi
135        fi
136}
137
138# main:  This is where we start the show.
139TGTPORTS=""
140PKGTYPE=rpmpackage
141
142if [ $# -lt 1 ]; then
143        echo "Usage: $0 chrootdir [-p pkgtype] [targetportsfile]"
144        exit 1
145else
146        DIR=$1
147        shift
148        if [ $# -gt 1 ]; then
149                if [ $1 = "-p" ]; then
150                    shift
151                    PKGTYPE=$1
152                    shift
153                fi
154        fi
155        if [ $# -gt 0 ]; then
156                TGTPORTS=$1
157        fi
158fi
159
160mkdir -p outputdir/summary outputdir/Packages outputdir/logs/succeeded outputdir/logs/failed outputdir/tmp
161
162if [ -z "$TGTPORTS" ]; then
163        if [ -f PortIndex ]; then
164                PINDEX=PortIndex
165        elif [ -f darwinports/dports/PortIndex ]; then
166                PINDEX=darwinports/dports/PortIndex
167        else
168                echo "I need a PortIndex file to work from - please put one in the"
169                echo "current directory or unpack a darwinports distribution to get it from"
170                exit 1
171        fi
172        TGTPORTS=outputdir/summary/portsrun
173        awk 'NF == 2 {print $1}' $PINDEX > $TGTPORTS
174else
175        echo "Using command-line provided target of $TGTPORTS"
176fi
177
178mkchrootbase $DIR
179ARCH="`uname -p`"
180if [ "${ARCH}" = "powerpc" ]; then
181        ARCH=ppc
182fi
183
184echo "Starting packaging run for `wc -l $TGTPORTS | awk '{print $1}'` ports."
185for pkg in `cat $TGTPORTS`; do
186        if [ -f badports.txt ]; then
187                if ! grep -q $pkg badports.txt; then
188                    continue
189                fi
190        fi
191        prepchroot $DIR
192        echo "Starting packaging run for $pkg"
193        echo "#!/bin/sh" > $DIR/bootstrap.sh
194        echo 'export PATH=$PATH:/opt/local/bin' >> $DIR/bootstrap.sh
195        echo '/sbin/mount_volfs /.vol' >> $DIR/bootstrap.sh
196        echo "mkdir -p /Package" >> $DIR/bootstrap.sh
197        echo "rm -f /tmp/success" >> $DIR/bootstrap.sh
198        echo "if port -v $PKGTYPE $pkg package.destpath=/Package >& /tmp/$pkg.log; then touch /tmp/success; fi" >> $DIR/bootstrap.sh
199        echo 'umount -f /.vol || (echo "unable to umount volfs"; exit 1)' >> $DIR/bootstrap.sh
200        echo "exit 0" >> $DIR/bootstrap.sh
201        chmod 755 $DIR/bootstrap.sh
202        chroot $DIR /bootstrap.sh || bomb "bootstrap script in chroot returned failure status"
203        if [ ! -f $DIR/tmp/success ]; then
204                echo $pkg >> outputdir/summary/portsfailed
205                type="failed"
206        else
207                echo $pkg >> outputdir/summary/portspackaged
208                if [ "$PKGTYPE" = "mpkg" ]; then
209                    mv $DIR/Package/*.mpkg outputdir/Packages/
210                elif [ "$PKGTYPE" = "rpmpackage" ]; then
211                    mv $DIR/Package/RPMS/${ARCH}/*.rpm outputdir/Packages/
212                elif [ "$PKGTYPE" = "dpkg" ]; then
213                    mv $DIR/Package/*.deb outputdir/Packages/
214                fi
215                type="succeeded"
216        fi
217        mv $DIR/tmp/$pkg.log outputdir/logs/$type
218        teardownchroot $DIR
219        echo "Finished packaging run for $pkg ($type)"
220done
221echo "Packaging run complete."
222exit 0
Note: See TracBrowser for help on using the repository browser.