source: trunk/base/portmgr/packaging/buildall.sh

Last change on this file was 123004, checked in by afb@…, 6 years ago

base: remove package support for rpm and deb

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id
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=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        chmod 755 $dir/bootstrap.sh
101        echo "Bootstrapping darwinports in chroot"
102        /sbin/mount_devfs devfs ${dir}/dev
103        /sbin/mount_fdesc -o union fdesc ${dir}/dev
104        chroot $dir /bootstrap.sh && rm $dir/bootstrap.sh
105        umount -f ${dir}/dev
106        umount -f ${dir}/dev
107        hdiutil detach $BASEDEV -force >& /dev/null && BASEDEV=""
108}
109
110# Set up the base chroot image
111prepchroot() {
112        dir=$1
113        rm -f ${CHROOTBASE}.shadow
114        BASEDEV=`hdiutil attach ${CHROOTBASE} -mountpoint $dir -shadow -noverify 2>&1 | awk '/dev/ {if (x == 0) {print $1; x = 1}}'`
115        mkdir -p $dir/.vol
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")
125        umount -f $dir/dev  || (echo "unable to umount fdesc")
126        [ -z "$DPORTSDEV" ] || (hdiutil detach $DPORTSDEV -force >& /dev/null || bomb "unable to detach DPORTSDEV")
127        DPORTSDEV=""
128        if [ ! -z "$BASEDEV" ]; then
129                if ! hdiutil detach $BASEDEV -force >& /dev/null; then
130                        echo "Warning: Unable to detach BASEDEV ($BASEDEV)"
131                fi
132        fi
133}
134
135# main:  This is where we start the show.
136TGTPORTS=""
137PKGTYPE=mpkg
138
139if [ $# -lt 1 ]; then
140        echo "Usage: $0 chrootdir [-p pkgtype] [targetportsfile]"
141        exit 1
142else
143        DIR=$1
144        shift
145        if [ $# -gt 1 ]; then
146                if [ $1 = "-p" ]; then
147                    shift
148                    PKGTYPE=$1
149                    shift
150                fi
151        fi
152        if [ $# -gt 0 ]; then
153                TGTPORTS=$1
154        fi
155fi
156
157mkdir -p outputdir/summary outputdir/Packages outputdir/logs/succeeded outputdir/logs/failed outputdir/tmp
158
159if [ -z "$TGTPORTS" ]; then
160        if [ -f PortIndex ]; then
161                PINDEX=PortIndex
162        elif [ -f darwinports/dports/PortIndex ]; then
163                PINDEX=darwinports/dports/PortIndex
164        else
165                echo "I need a PortIndex file to work from - please put one in the"
166                echo "current directory or unpack a darwinports distribution to get it from"
167                exit 1
168        fi
169        TGTPORTS=outputdir/summary/portsrun
170        awk 'NF == 2 {print $1}' $PINDEX > $TGTPORTS
171else
172        echo "Using command-line provided target of $TGTPORTS"
173fi
174
175mkchrootbase $DIR
176ARCH="`uname -p`"
177if [ "${ARCH}" = "powerpc" ]; then
178        ARCH=ppc
179fi
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 -f /.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                fi
208                type="succeeded"
209        fi
210        mv $DIR/tmp/$pkg.log outputdir/logs/$type
211        teardownchroot $DIR
212        echo "Finished packaging run for $pkg ($type)"
213done
214echo "Packaging run complete."
215exit 0
Note: See TracBrowser for help on using the repository browser.