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

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

Preserve the outputdir

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.7 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
93sed -e "s;portautoclean.*yes;portautoclean no;" < /etc/ports/ports.conf > /etc/ports/ports.conf.new && mv /etc/ports/ports.conf.new /etc/ports/ports.conf
94EOF
95        if [ "$PKGTYPE" = "dpkg" ]; then
96            echo "/opt/local/bin/port install dpkg" >> $dir/bootstrap.sh
97        fi
98        chmod 755 $dir/bootstrap.sh
99        echo "Bootstrapping darwinports in chroot"
100        /sbin/mount_devfs devfs ${dir}/dev
101        /sbin/mount_fdesc -o union fdesc ${dir}/dev
102        chroot $dir /bootstrap.sh && rm $dir/bootstrap.sh
103        umount -f ${dir}/dev
104        umount -f ${dir}/dev
105        hdiutil detach $BASEDEV >& /dev/null && BASEDEV=""
106}
107
108# Set up the base chroot image
109prepchroot() {
110        dir=$1
111        if [ $STUCK_BASEDEV = 0 ]; then
112                rm -f ${CHROOTBASE}.shadow
113                BASEDEV=`hdiutil attach ${CHROOTBASE} -mountpoint $dir -readonly -shadow -noverify 2>&1 | awk '/dev/ {if (x == 0) {print $1; x = 1}}'`
114                mkdir -p $dir/.vol
115        fi
116        DPORTSDEV=`hdiutil attach ${DPORTSCACHE} -mountpoint $dir/opt/local/var/db/dports -union -noverify 2>&1 | awk '/dev/ {if (x == 0) {print $1; x = 1}}'`
117        /sbin/mount_devfs devfs $dir/dev || bomb "unable to mount devfs"
118        /sbin/mount_fdesc -o union fdesc $dir/dev || bomb "unable to mount fdesc"
119}
120
121# Undo the work of prepchroot
122teardownchroot() {
123        dir=$1
124        umount -f $dir/dev  || (echo "unable to umount devfs"; STUCK_BASEDEV=1)
125        umount -f $dir/dev  || (echo "unable to umount fdesc"; STUCK_BASEDEV=1)
126        [ -z "$DPORTSDEV" ] || (hdiutil detach $DPORTSDEV >& /dev/null || bomb "unable to detach DPORTSDEV")
127        DPORTSDEV=""
128        if [ ! -z "$BASEDEV" ]; then
129                if hdiutil detach $BASEDEV >& /dev/null; then
130                        STUCK_BASEDEV=0
131                        BASEDEV=""
132                else
133                        echo "Warning: Unable to detach BASEDEV ($BASEDEV)"
134                        STUCK_BASEDEV=1
135                fi
136        fi
137}
138
139# main:  This is where we start the show.
140TGTPORTS=""
141PKGTYPE=mpkg
142
143if [ $# -lt 1 ]; then
144        echo "Usage: $0 chrootdir [-p pkgtype] [targetportsfile]"
145        exit 1
146else
147        DIR=$1
148        shift
149        if [ $# -gt 1 ]; then
150                if [ $1 = "-p" ]; then
151                    shift
152                    PKGTYPE=$1
153                    shift
154                fi
155        fi
156        if [ $# -gt 0 ]; then
157                TGTPORTS=$1
158        fi
159fi
160
161if [ -z "$TGTPORTS" ]; then
162        if [ -f PortIndex ]; then
163                PINDEX=PortIndex
164        elif [ -f darwinports/dports/PortIndex ]; then
165                PINDEX=darwinports/dports/PortIndex
166        else
167                echo "I need a PortIndex file to work from - please put one in the"
168                echo "current directory or unpack a darwinports distribution to get it from"
169                exit 1
170        fi
171        mkdir -p outputdir/summary
172        TGTPORTS=outputdir/summary/portsrun
173        awk 'NF == 2 {print $1}' $PINDEX > $TGTPORTS
174fi
175
176mkchrootbase $DIR
177mkdir -p outputdir/Packages outputdir/logs/succeeded outputdir/logs/failed outputdir/tmp
178# Hack to work around sticking volfs problem.
179STUCK_BASEDEV=0
180
181echo "Starting packaging run for `wc -l $TGTPORTS | awk '{print $1}'` ports."
182for pkg in `cat $TGTPORTS`; do
183        if [ -f badports.txt ]; then
184                if ! grep -q $pkg badports.txt; then
185                    continue
186                fi
187        fi
188        prepchroot $DIR
189        echo "Starting packaging run for $pkg"
190        echo "#!/bin/sh" > $DIR/bootstrap.sh
191        echo 'export PATH=$PATH:/opt/local/bin' >> $DIR/bootstrap.sh
192        echo '/sbin/mount_volfs /.vol' >> $DIR/bootstrap.sh
193        echo "mkdir -p /Package" >> $DIR/bootstrap.sh
194        echo "rm -f /tmp/success" >> $DIR/bootstrap.sh
195        echo "if port -v $PKGTYPE $pkg package.destpath=/Package >& /tmp/$pkg.log; then touch /tmp/success; fi" >> $DIR/bootstrap.sh
196        echo 'umount /.vol || (echo "unable to umount volfs"; exit 1)' >> $DIR/bootstrap.sh
197        echo "exit 0" >> $DIR/bootstrap.sh
198        chmod 755 $DIR/bootstrap.sh
199        chroot $DIR /bootstrap.sh || bomb "bootstrap script in chroot returned failure status"
200        if [ ! -f $DIR/tmp/success ]; then
201                echo $pkg >> outputdir/summary/portsfailed
202                type="failed"
203        else
204                echo $pkg >> outputdir/summary/portspackaged
205                if [ "$PKGTYPE" = "mpkg" ]; then
206                    mv $DIR/Package/*.mpkg outputdir/Packages/
207                elif [ "$PKGTYPE" = "dpkg" ]; then
208                    mv $DIR/Package/*.deb outputdir/Packages/
209                fi
210                type="succeeded"
211        fi
212        mv $DIR/tmp/$pkg.log outputdir/logs/$type
213        teardownchroot $DIR
214        echo "Finished packaging run for $pkg ($type)"
215done
216echo "Packaging run complete."
217exit 0
Note: See TracBrowser for help on using the repository browser.