source: builder/runrooted @ 105afb5

Last change on this file since 105afb5 was 3c9eb90, checked in by Edwin Eefting <edwin@datux.nl>, 5 years ago

buildroot fixes. libreswan update to 3.32

  • Property mode set to 100755
File size: 7.9 KB
RevLine 
[c5c522c]1#!/bin/bash
2#(C)DatuX 2005 - all rights reserved
3#-kijkt of er een goede (ongewijzigde) buildroot aanwezig is
4#-genereerd indien nodig een nieuwe buildroot (oude word dan gewist)
5#-copy de directory waar het programma staat naar de buildroot
6#-start het programma chrootted
7#-kopieer nieuwe files in de directory (niet de subdirs) terug naar orginenele plek
8#-geeft een overzicht van de gewijzigde files. (als het programma de buildroot dus sloopt)
9#-de tmp dir in de buildroot word niet meegenomene met wijzigingen en word altijd
10# opnieuw gemaakt.
11
[3c9eb90]12if ! which tar-1.13 >/dev/null; then
13    echo "Missing tar-1.13. Please copy ../npl/slackware/tar-1.13 to /bin. "
14    exit 1
15fi
16
17if ! which installpkg >/dev/null; then
18    echo "Missing pkgtools. Please copy binaries from  ../npl/slackware/pkgtools-10.0.0-i486-1.tgz to /bin. "
19    exit 1
20fi
21
22if ! which lockfile-create > /dev/null; then
23    echo "Need lockfile-create. "
24    exit 1
25fi
[c5c522c]26
27if [ -z $1 ]; then
28    echo "Geef scriptnaam op!"
29    echo "$0 <scriptnaam> [nocheck] [nodep]"
30#    echo " rebuildroot: haal hele buildroot weg, alles opnieuw"
31    echo " nocheck:   repareer de buildroot niet. "
32    echo "              (alleen als je zelfde package nog een keer bouwt)"
33    echo " nodep:     installeer dependencies niet"
34    echo " progress: progress indicator tonen. (pv dient geinstalleerd te zijn voor progress indicators)"
35    exit 1
36fi
37
38for PAR in $*; do eval "$PAR=1" &>/dev/null; done
39
[3c9eb90]40#create/mount builroot
41if ! grep buildroots /proc/mounts >/dev/null; then
42    mkdir /tmp/buildroots
43    mount -t tmpfs tmpfs /tmp/buildroots
44fi
45export TMP=/tmp/buildroots
46
47export MAKEFLAGS="-j10 $MAKEFLAGS"
48
[d849d83]49#unieke identifier voor deze lokale checkout. Op dit moment gebruiken we hier het lokale pad voor:
[c5c522c]50SVNID=`pwd|tr / _`
51
[3c9eb90]52export ROOTCOPY=$TMP/buildroot.copy.$SVNID
[c5c522c]53
54#bepaal welke buildroot 'vrij' is om te gebruiken
55NR=0
[3c9eb90]56export BUILDROOT=$TMP/buildroot$NR.$SVNID
[c5c522c]57while ! lockfile-create -r0 $BUILDROOT ; do
58        (( NR++ ))
[3c9eb90]59        BUILDROOT=$TMP/buildroot$NR.$SVNID
[c5c522c]60        if [ "$NR" -ge 10 ]; then
61                echo "No more free buildroots, giving up."
62                exit 1
63        fi
64done
65#always remove lockfile on exit!
66trap "rm $BUILDROOT.lock &>/dev/null" 0
67
68
69PGMPATH=$1
70DIR=`dirname "$PGMPATH"`;
71PGM=`basename "$PGMPATH"`;
72ROOTEDWORKDIR=/tmp/build
73WORKDIR=$BUILDROOT$ROOTEDWORKDIR
74
75if [ ! -x $PGMPATH ] || [ ! -f $PGMPATH ]; then
76    echo "Exectubable $PGMPATH bestaat niet!"
77    exit 1
78fi
79
80#root helemaal rebuilden?
81#if [ "$rebuildroot" ]; then
82#    echo "Deleting old buildroot..."
83#    rm -r $BUILDROOT
84#fi
85
86#ivm snelheid
87#echo "Buildroot opschonen.."
[3c9eb90]88#rm -rf $BUILDROOT$TMP/* &>/dev/null
[c5c522c]89
90
91#buildroot controleren/fixen/voorbereiden?
92if [ "$nocheck" ] ; then
93    echo "(skipping buildroot check..)"
94else
95    mkdir $BUILDROOT &>/dev/null
96    ./chkbuildroot $BUILDROOT $ROOTCOPY $* || exit 1
97fi
98
99
100if [ "$nodep" ]; then
101    echo "(skipping dependency install..)"
102else
103        CONFIG=
104        #bepaal de build dependencies:
105
106        NEEDS=`../npl/findbuilddeps $PGMPATH` || exit 1
107        for NEED in $NEEDS; do
108
109                CONFIG=1
[d2a077a]110                echo -n "Finding dependency $NEED: "
[c5c522c]111                TGZ=`../npl/findpkg "$NEED"` || exit 1
[d2a077a]112                echo -n "$TGZ"
113               
114                PKGNAME=`basename "$TGZ"|sed 's/.tgz$//'`
115
116                #already installed?
117                if [ -e "$BUILDROOT/var/log/packages/$PKGNAME" ]; then
118                        echo " (already installed, skipping)"
119                        continue
120                else
121                        echo " (installing)"
122                fi
[c5c522c]123
124                #Bepaal waar het pakketje in de buildroot moet terecht komen, ivm crosscompiling.
125                #Zon pakketje mag niet in de buildroot zelf, omdat dan de bestaande libraries overschreven kunnen worden met die van een andere architectuur.
126                #eerst moeten we de architectuur van het pakketje weten:
127                NEEDHOST=
128                if NEEDBUILD=`../npl/findbuild "$NEED"`; then
129                    #FIXME: dit klopt niet, bij perlmod_XML_Parser pakt hij nu buildmods.arch ipv perlmod_XML_Parser.arch!
130                    NEEDHOST=`cat $NEEDBUILD.arch 2>/dev/null`
131                fi
132                #als het er een directory naast npl bestaat is het een crosscomplile architectuur:
133                if [ "$NEEDHOST" ] && [ -e ../$NEEDHOST ]; then
134                    #cross-architectuur, install
135                    #in een subdirectory onder buildroot, met naam van architectuur:
136                    echo "(Cross architecture detected, installing package in $NEEDHOST toolchain directory)"
137                    export ROOT=$BUILDROOT/usr/$NEEDHOST/$NEEDHOST
138                else
139                    #gewoon direct in de buildroot pleuren:
140                    export ROOT=$BUILDROOT
141                fi
142
143                installpkg "$TGZ" >/dev/null || exit 1
144
145                #_dev niet gespecificeerd?
146#NO: findbuilddeps does this now
147#               if ! echo "$NEEDS" | grep "$NEED""_dev"; then
148#                       #bestaat er wel een dev?
149#                       if TGZ=`../npl/findpkg "$NEED""_dev" 2>/dev/null`; then
150#                               echo "Auto selecting development package: $TGZ"
151#                               installpkg "$TGZ" >/dev/null || exit 1
152#                       fi
153#               fi
154
155        done
156
157        if [ "$CONFIG" ]; then
158                echo "Nieuwe packages ldconfiggen..."
159                ldconfig -r $BUILDROOT || exit 1
160                echo "etc-update doen"
161                chroot $BUILDROOT "/bin/bash" -l -c "etc-update" || exit 1
162        fi
163
164        #paden fixen ivm cross compile?
165        if [ "$HOST" ]; then
166                echo -n "Adjusting crossplatform library configs in toolchain directory..."
167                #fix pkgconfig files that are in crossplatform-path:
168                sed -i "s@=/usr@=/usr/$NEEDHOST/$NEEDHOST/usr@" $BUILDROOT/usr/$HOST/$HOST/usr/lib/pkgconfig/*.pc
169                #fix *-config files that are in crossplatform-path:
170                sed -i "s@=/usr@=/usr/$HOST/$HOST/usr@" $BUILDROOT/usr/$HOST/$HOST/usr/bin/*-config
171                sed -i "s@\"/usr@\"/usr/$HOST/$HOST/usr@" $BUILDROOT/usr/$HOST/$HOST/usr/bin/*-config
172                echo "DONE"
173        fi
174
175fi
176
177#hack kernel versie tools
178cat arch > $BUILDROOT/bin/arch
179chmod +x $BUILDROOT/bin/arch
180KVER=`ls $BUILDROOT/lib/modules 2>/dev/null|cut -f1 -d'/'`
181if [ "$KVER" == "" ]; then
182        KVER=`cat ../npl/kernel/linux_src/linux_src.version` || exit 1
183fi
184cat uname |sed "s/#KVER#/$KVER/g" > $BUILDROOT/bin/uname
185chmod +x $BUILDROOT/bin/uname
186
187#vanaf hier is er een goede buildroot
188echo "$DIR word gekopieerd naar werkdirectory $WORKDIR"
189cp -a $DIR $WORKDIR || exit 1
190chown -R root:root $WORKDIR || exit 1
191
192#proc is needed for all kinds of things:
193umount $BUILDROOT/proc &>/dev/null
194mount -t proc none $BUILDROOT/proc || exit 1
195
196#pts is needed for programs like 'Expect':
197umount $BUILDROOT/dev/pts &>/dev/null
198mount -t devpts none $BUILDROOT/dev/pts -o rw,nosuid,noexec,gid=5,mode=620 || exit 1
199
200#put the logfile in top of the buildroot and not in /tmp/build, to not 'disrupt' smart SlackBuild that use file-times.
201export LOG="$BUILDROOT/$PGM.log"
202
203#log output and show progress info if pv is installed
204progress()
205{
206        #use old logfile as reference for progress indication
207        SIZE=`zcat $BUILDROOT/tmp/build/$PGM.log.gz 2>/dev/null|wc -c`
208        if [ "$progress" ] && which pv &>/dev/null; then
209                pv -s $SIZE -p -t -e  | tee $LOG
210        else
211                tee $LOG
212        fi
213}
214
215#clear environment, set some variables and do the actual chrooting:
216echo -e "\e[1;33m*** Chroot naar $BUILDROOT en starten van $PGM in $ROOTEDWORKDIR:\e[0m" >&2
217CHROOT=`which chroot`
218env - $CHROOT $BUILDROOT "/bin/bash" -l -c "
219        export MAKEFLAGS='$MAKEFLAGS'
220        cd $ROOTEDWORKDIR
221        export PS4='\[\e[1;32m\]\$LINENO \$PWD > \[\e[0m\]'
222        export HOST=$HOST
223        bash -x ./$PGM" 2>&1 | progress ;
224
225if [ "${PIPESTATUS[0]}" != "0" ]; then
226        echo -e "\e[1;31m*** Er ging iets mis tijdens het bakken in de buildroot!\e[0m" >&2
227        echo "Chroot naar $BUILDROOT zodat je kunt onderzoeken (ctrl-d om te stoppen):"
228        env - $CHROOT $BUILDROOT "/bin/bash" -l -c "
229            export MAKEFLAGS='$MAKEFLAGS'
230            export TERM='$TERM'
231            cd $ROOTEDWORKDIR
232            export HOST=$HOST
233            bash" 2>&1
234
235        umount $BUILDROOT/proc
236        umount $BUILDROOT/dev/pts
237        echo "Om verder te testen/onderzoeken, tik:"
238        echo "chroot $BUILDROOT"
239        echo "Logfile: $LOG"
240        exit 1
241else
242        echo -e "\e[1;32m*** Build gelukt.\e[0m" >&2
243fi
244
245umount $BUILDROOT/proc
246umount $BUILDROOT/dev/pts
247
248echo "* Packages terugmoven naar originele directory..";
249echo $WORKDIR/*.arch ...
250mv $WORKDIR/*.arch $DIR || exit 1
251echo $WORKDIR/*.version ...
252mv $WORKDIR/*.version $DIR || exit 1
[d849d83]253
[0c25615]254#move packages from buildroot to workdir
[d849d83]255for PKG in $WORKDIR/*.pkg; do
256        NAME=`basename $PKG|sed 's/.pkg$//g'`
257        if ! cmp $PKG $DIR/$NAME.pkg; then
258                mv $PKG $DIR || exit 1
259        fi
260done
261
262
[c5c522c]263echo Compressing $LOG ...
264gzip $LOG || exit 1
265mv $LOG.gz $DIR || exit 1
266
267
268echo
269echo "* Klaar ja!";
Note: See TracBrowser for help on using the repository browser.