source: trunk/base/src/portmgr/buildall.sh @ 10289

Last change on this file since 10289 was 10289, checked in by jkh, 15 years ago

Add missing references to libiconv port. Discovered by the buildall.sh
script, which doesn't allow a port to have "implict" references that
just happen to be satisfied by something that builds (or may not!)
earlier.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.6 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=8000000
16DPORTSCACHE_SIZE=32767M
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 private 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                for i in $chrootfiles; do
40                        mysz=`cd /; du -sk $i |awk '{print $1}'`
41                        sz=$(($sz + $mysz))
42                done
43                echo "Creating bootstrap disk image of ${sz}K bytes"
44                hdiutil create -size ${sz}k -fs ${FSTYPE} -volname base ${CHROOTBASE} > /dev/null
45                BASEDEV=`hdiutil attach ${CHROOTBASE} -mountpoint $dir -noverify 2>&1 | awk '/dev/ {if (x == 0) {print $1; x = 1}}'`
46                echo "Image attached as $BASEDEV"
47                echo "Copying chroot files into bootstrap disk image"
48                for i in $chrootfiles; do
49                        pax -pe -rw /$i $dir 2>/dev/null
50                        # special case for pax
51                        cp /bin/pax $dir/bin/pax
52                done
53                # special case nuke to prevent builder pollution
54                rm -rf $dir/usr/X11R6
55                # If there are any work-arounds, apply them now
56                if [ -f chroot-fixups.tar.gz ]; then
57                        echo "Found chroot-fixups.tar.gz - applying to new chroot"
58                        tar xpzf chroot-fixups.tar.gz -C $dir
59                fi
60                if [ -f darwinports.tar.gz ]; then
61                        echo "Found darwinports.tar.gz - copying into chroot"
62                        tar -xpzf darwinports.tar.gz -C $dir
63                elif [ -d darwinports ]; then
64                        pax -rw darwinports $dir
65                else
66                        echo "no darwinports.tar.gz or darwinports directory found - please fix this and try again."
67                        exit 1
68                fi
69                bootstrapdports $dir
70        fi
71        if [ -f ${DPORTSCACHE} ]; then
72                echo "Using existing ${DPORTSCACHE} for efficiency"
73        else
74                echo "Creating dports cache of size ${DPORTSCACHE_SIZE}"
75                hdiutil create -size ${DPORTSCACHE_SIZE} -fs ${FSTYPE} -volname distfiles ${DPORTSCACHE} > /dev/null
76                DPORTSDEV=`hdiutil attach ${DPORTSCACHE} -mountpoint $dir -noverify 2>&1 | awk '/dev/ {if (x == 0) {print $1; x = 1}}'`
77                mkdir -p $dir/distfiles
78                mkdir -p $dir/receipts
79                mkdir -p $dir/software
80                mkdir -p $dir/packages/darwin/powerpc
81                hdiutil detach $DPORTSDEV >& /dev/null && DPORTSDEV=""
82        fi
83}
84
85bootstrapdports() {
86        dir=$1
87        cat > $dir/bootstrap.sh << EOF
88#!/bin/sh
89cd darwinports/base
90./configure
91make all install
92make clean
93EOF
94        if [ "$PKGTYPE" = "dpkg" ]; then
95            echo "/opt/local/bin/port install dpkg" >> $dir/bootstrap.sh
96        fi
97        chmod 755 $dir/bootstrap.sh
98        echo "Bootstrapping darwinports in chroot"
99        /sbin/mount_devfs devfs ${dir}/dev
100        /sbin/mount_fdesc -o union fdesc ${dir}/dev
101        chroot $dir /bootstrap.sh && rm $dir/bootstrap.sh
102        umount -f ${dir}/dev
103        umount -f ${dir}/dev
104        hdiutil detach $BASEDEV >& /dev/null && BASEDEV=""
105}
106
107# Set up the base chroot image
108prepchroot() {
109        dir=$1
110        if [ $STUCK_BASEDEV = 0 ]; then
111                rm -f ${CHROOTBASE}.shadow
112                BASEDEV=`hdiutil attach ${CHROOTBASE} -mountpoint $dir -readonly -shadow -noverify 2>&1 | awk '/dev/ {if (x == 0) {print $1; x = 1}}'`
113                mkdir -p $dir/.vol
114        fi
115        DPORTSDEV=`hdiutil attach ${DPORTSCACHE} -mountpoint $dir/opt/local/var/db/dports -union -noverify 2>&1 | awk '/dev/ {if (x == 0) {print $1; x = 1}}'`
116        /sbin/mount_devfs devfs $dir/dev || bomb "unable to mount devfs"
117        /sbin/mount_fdesc -o union fdesc $dir/dev || bomb "unable to mount fdesc"
118}
119
120# Undo the work of prepchroot
121teardownchroot() {
122        dir=$1
123        umount -f $dir/dev  || (echo "unable to umount devfs"; STUCK_BASEDEV=1)
124        umount -f $dir/dev  || (echo "unable to umount fdesc"; STUCK_BASEDEV=1)
125        [ -z "$DPORTSDEV" ] || (hdiutil detach $DPORTSDEV >& /dev/null || bomb "unable to detach DPORTSDEV")
126        DPORTSDEV=""
127        if [ ! -z "$BASEDEV" ]; then
128                if hdiutil detach $BASEDEV >& /dev/null; then
129                        STUCK_BASEDEV=0
130                        BASEDEV=""
131                else
132                        echo "Warning: Unable to detach BASEDEV ($BASEDEV)"
133                        STUCK_BASEDEV=1
134                fi
135        fi
136}
137
138# main:  This is where we start the show.
139TGTPORTS=""
140PKGTYPE=mpkg
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
160if [ -z "$TGTPORTS" ]; then
161        if [ -f PortIndex ]; then
162                PINDEX=PortIndex
163        elif [ -f darwinports/dports/PortIndex ]; then
164                PINDEX=darwinports/dports/PortIndex
165        else
166                echo "I need a PortIndex file to work from - please put one in the"
167                echo "current directory or unpack a darwinports distribution to get it from"
168                exit 1
169        fi
170        mkdir -p outputdir/summary
171        TGTPORTS=outputdir/summary/portsrun
172        awk 'NF == 2 {print $1}' $PINDEX > $TGTPORTS
173fi
174
175mkchrootbase $DIR
176mkdir -p outputdir/Packages outputdir/logs/succeeded outputdir/logs/failed outputdir/tmp
177# Hack to work around sticking volfs problem.
178STUCK_BASEDEV=0
179
180echo "Starting packaging run for `wc -l $TGTPORTS | awk '{print $1}'` ports."
181for pkg in `cat $TGTPORTS`; do
182        if [ -f badports.txt ]; then
183                if ! grep -q $pkg badports.txt; then
184                    continue
185                fi
186        fi
187        prepchroot $DIR
188        echo "Starting packaging run for $pkg"
189        echo "#!/bin/sh" > $DIR/bootstrap.sh
190        echo 'export PATH=$PATH:/opt/local/bin' >> $DIR/bootstrap.sh
191        echo '/sbin/mount_volfs /.vol' >> $DIR/bootstrap.sh
192        echo "mkdir -p /Package" >> $DIR/bootstrap.sh
193        echo "rm -f /tmp/success" >> $DIR/bootstrap.sh
194        echo "if port -k -v $PKGTYPE $pkg package.destpath=/Package >& /tmp/$pkg.log; then touch /tmp/success; fi" >> $DIR/bootstrap.sh
195        echo 'umount /.vol || (echo "unable to umount volfs"; exit 1)' >> $DIR/bootstrap.sh
196        echo "exit 0" >> $DIR/bootstrap.sh
197        chmod 755 $DIR/bootstrap.sh
198        chroot $DIR /bootstrap.sh || bomb "bootstrap script in chroot returned failure status"
199        if [ ! -f $DIR/tmp/success ]; then
200                echo $pkg >> outputdir/summary/portsfailed
201                type="failed"
202        else
203                echo $pkg >> outputdir/summary/portspackaged
204                if [ "$PKGTYPE" = "mpkg" ]; then
205                    mv $DIR/Package/*.mpkg outputdir/Packages/
206                elif [ "$PKGTYPE" = "dpkg" ]; then
207                    mv $DIR/Package/*.deb outputdir/Packages/
208                fi
209                type="succeeded"
210        fi
211        mv $DIR/tmp/$pkg.log outputdir/logs/$type
212        teardownchroot $DIR
213        echo "Finished packaging run for $pkg ($type)"
214done
215echo "Packaging run complete."
216exit 0
Note: See TracBrowser for help on using the repository browser.