xref: /dflybsd-src/tools/snapshots/doclean (revision 3dae329d35d1dae41262ccd4683c472ab19bd48e)
1b412cc49SMatthew Dillon#!/bin/csh
2b412cc49SMatthew Dillon#
3b412cc49SMatthew Dillon# Create a working chroot for snapshot building
4b412cc49SMatthew Dillon#
5b412cc49SMatthew Dillon
6b412cc49SMatthew Dillonsource config
7b412cc49SMatthew Dillon
8*3dae329dSSascha Wildner# slow and steady wins the race, don't interfere
9*3dae329dSSascha Wildner# with other stuff
10*3dae329dSSascha Wildnerset ncpu = 1
11*3dae329dSSascha Wildner#set ncpu = `sysctl -n hw.ncpu`
12b412cc49SMatthew Dillonset pushdsilent
13b412cc49SMatthew Dillonset xdate = "date"
14b412cc49SMatthew Dillon
15*3dae329dSSascha Wildner# needed for ports 'ex' script execution
16*3dae329dSSascha Wildner#
17*3dae329dSSascha Wildnersetenv TERM xterm
18*3dae329dSSascha Wildner
19b412cc49SMatthew Dillonecho "`$xdate` - SNAPSHOTS DOCLEAN BEGIN"
20b412cc49SMatthew Dillon
21b412cc49SMatthew Dillon# Options
22b412cc49SMatthew Dillon#
23b412cc49SMatthew Dillonforeach arg ( $argv )
24b412cc49SMatthew Dillon    switch ( $arg )
25b412cc49SMatthew Dillon    case "realquick":
26b412cc49SMatthew Dillon	set quick = 1
27b412cc49SMatthew Dillon	set realquick = 1
28b412cc49SMatthew Dillon	breaksw
29b412cc49SMatthew Dillon    case "quick":
30b412cc49SMatthew Dillon	set quick = 1
31b412cc49SMatthew Dillon	breaksw
32b412cc49SMatthew Dillon    default:
33b412cc49SMatthew Dillon	echo "Unknown option $arg"
34b412cc49SMatthew Dillon	echo "`$xdate` - SNAPSHOTS DOCLEAN END"
35b412cc49SMatthew Dillon 	exit 1
36b412cc49SMatthew Dillon    endsw
37b412cc49SMatthew Dillonend
38b412cc49SMatthew Dillon
39b412cc49SMatthew Dillon# Remove environment
40b412cc49SMatthew Dillon#
41b412cc49SMatthew Dillonif ( "$build" == "" ) then
42b412cc49SMatthew Dillon    echo "build variable not set"
43b412cc49SMatthew Dillon    echo "`$xdate` - SNAPSHOTS DOCLEAN END"
44b412cc49SMatthew Dillon    exit 1
45b412cc49SMatthew Dillonendif
46b412cc49SMatthew Dillon
47*3dae329dSSascha Wildnerif ( -e $build/root/usr/src/nrelease && -e $build/root/dev/null ) then
48*3dae329dSSascha Wildner    echo "`$xdate` - Cleanup previous nrelease"
49*3dae329dSSascha Wildner    chroot $build/root csh -c "cd /usr/src/nrelease; make -DNOPROFILE -DWITHOUT_SRCS clean"
50*3dae329dSSascha Wildnerendif
51*3dae329dSSascha Wildner
52b412cc49SMatthew Dillonif ( -e $build/root/dev/null ) then
53*3dae329dSSascha Wildner    sync; sleep 1
54b412cc49SMatthew Dillon    echo "`$xdate` - Unmount devfs from $build/root/dev"
55b412cc49SMatthew Dillon    umount $build/root/dev
56b412cc49SMatthew Dillon    if ( $? > 0 ) then
57b412cc49SMatthew Dillon	echo "`$xdate` - Unable to umount $build/root/dev"
58b412cc49SMatthew Dillon	echo "`$xdate` - SNAPSHOTS DOCLEAN END"
59b412cc49SMatthew Dillon	exit 1
60b412cc49SMatthew Dillon    endif
61b412cc49SMatthew Dillonendif
62b412cc49SMatthew Dillon
63*3dae329dSSascha Wildnersync; sleep 1
64*3dae329dSSascha Wildnerumount $build/root/usr/distfiles >& /dev/null
65*3dae329dSSascha Wildnerumount $build/root/usr/src >& /dev/null
66*3dae329dSSascha Wildnerumount $build/root/usr/dports >& /dev/null
67b412cc49SMatthew Dillon
68b412cc49SMatthew Dillonif ( $?quick == 0 ) then
69b412cc49SMatthew Dillon    echo "`$xdate` - Destroying root environment at $build/root"
70b412cc49SMatthew Dillon    sleep 5
71b412cc49SMatthew Dillon    rm -rf $build/root >& /dev/null
72b412cc49SMatthew Dillon    if ( -d $build/root ) then
73b412cc49SMatthew Dillon	chflags -R noschg $build/root
74b412cc49SMatthew Dillon    endif
75b412cc49SMatthew Dillon    rm -rf $build/root
76b412cc49SMatthew Dillonendif
77b412cc49SMatthew Dillonmkdir -p $build/distfiles
78b412cc49SMatthew Dillonmkdir -p $build/root
79b412cc49SMatthew Dillonmkdir -p $build/root/usr
80b412cc49SMatthew Dillon
81b412cc49SMatthew Dillonecho "`$xdate` - Log files are in $build/*.out"
82b412cc49SMatthew Dillon
83b412cc49SMatthew Dillon# Ignore quick/realquick options if there is no prior
84b412cc49SMatthew Dillon# installation
85b412cc49SMatthew Dillon#
86b412cc49SMatthew Dillonif ( ! -e $build/root/etc/networks ) then
87b412cc49SMatthew Dillon    unset realquick
88b412cc49SMatthew Dillonendif
89*3dae329dSSascha Wildnerif ( ! -d $build/src ) then
90b412cc49SMatthew Dillon    unset quick
91b412cc49SMatthew Dillon    unset realquick
92b412cc49SMatthew Dillonendif
93*3dae329dSSascha Wildnerif ( ! -d $build/dports ) then
94b412cc49SMatthew Dillon    unset quick
95b412cc49SMatthew Dillon    unset realquick
96b412cc49SMatthew Dillonendif
97b412cc49SMatthew Dillon
98b412cc49SMatthew Dillon# Clone the repos, create trakcing branches as necessary, checkout,
99b412cc49SMatthew Dillon# and update (using fetch)
100b412cc49SMatthew Dillon#
101b412cc49SMatthew Dillon# DragonFly sources
102b412cc49SMatthew Dillon#
103*3dae329dSSascha Wildnerpushd $build
104*3dae329dSSascha Wildner
105*3dae329dSSascha Wildnerif ( ! -d src ) then
106b412cc49SMatthew Dillon    echo "`$xdate` - Cloning $dflygit"
107b412cc49SMatthew Dillon    git clone -n $dflygit src
108b412cc49SMatthew Dillonendif
109*3dae329dSSascha Wildnerpushd $build/src
110b412cc49SMatthew Dillonif ( "`git branch | fgrep $dfly_branch`" == "" ) then
111b412cc49SMatthew Dillon    echo "`$xdate` - Branching-src $dfly_branch"
112b412cc49SMatthew Dillon    git branch $dfly_branch origin/$dfly_branch
113b412cc49SMatthew Dillonendif
114b412cc49SMatthew Dillonecho "`$xdate` - Updating src"
115b412cc49SMatthew Dillongit checkout $dfly_branch
116b412cc49SMatthew Dillongit pull
117b412cc49SMatthew Dillonpopd
118b412cc49SMatthew Dillon
119b412cc49SMatthew Dillon# Package sources
120b412cc49SMatthew Dillon#
121*3dae329dSSascha Wildnerif ( ! -d dports ) then
122*3dae329dSSascha Wildner    echo "`$xdate` - Cloning $dportsgit"
123*3dae329dSSascha Wildner    git clone -n $dportsgit dports
124b412cc49SMatthew Dillonendif
125*3dae329dSSascha Wildnerpushd $build/dports
126*3dae329dSSascha Wildnerif ( "`git branch | fgrep $dports_branch`" == "" ) then
127*3dae329dSSascha Wildner    echo "`$xdate` - Branching-dports $dports_branch"
128*3dae329dSSascha Wildner    git branch $dports_branch origin/$dports_branch
129b412cc49SMatthew Dillonendif
130*3dae329dSSascha Wildnerecho "`$xdate` - Updating dports"
131*3dae329dSSascha Wildnergit checkout $dports_branch
132b412cc49SMatthew Dillongit pull
133b412cc49SMatthew Dillonpopd
134b412cc49SMatthew Dillon
135*3dae329dSSascha Wildner# null mounts
136*3dae329dSSascha Wildner#
137*3dae329dSSascha Wildnermkdir -p $build/root/usr/src
138*3dae329dSSascha Wildnermkdir -p $build/root/usr/dports
139*3dae329dSSascha Wildnermkdir -p $build/root/usr/distfiles
140*3dae329dSSascha Wildner
141*3dae329dSSascha Wildnerecho "`$xdate` - Mounting src, dports, distfiles"
142*3dae329dSSascha Wildnermount_null $build/src $build/root/usr/src
143*3dae329dSSascha Wildnermount_null $build/dports $build/root/usr/dports
144*3dae329dSSascha Wildnermount_null $build/distfiles $build/root/usr/distfiles
145*3dae329dSSascha Wildner
146*3dae329dSSascha Wildnerpopd
147*3dae329dSSascha Wildner# popped build
148*3dae329dSSascha Wildner
149b412cc49SMatthew Dillon# Install/upgrade environment
150b412cc49SMatthew Dillon#
151b412cc49SMatthew Dillonpushd $build/root/usr/src
152b412cc49SMatthew Dillon
153b412cc49SMatthew Dillonif ( $?realquick ) then
154b412cc49SMatthew Dillon    echo "`$xdate` - Not running build/quickworld - realquick mode"
155b412cc49SMatthew Dillonelse
156b412cc49SMatthew Dillonif ( $?quick ) then
157b412cc49SMatthew Dillon    echo "`$xdate` - Starting quickworld, tail -f $build/build.out"
158b412cc49SMatthew Dillon    make -j $ncpu quickworld >& $build/build.out
159b412cc49SMatthew Dillon    if ( $? ) then
160b412cc49SMatthew Dillon	echo "`$xdate` - primary environment quickworld failed"
161b412cc49SMatthew Dillon	echo "`$xdate` - SNAPSHOTS DOCLEAN END"
162b412cc49SMatthew Dillon	exit 1
163b412cc49SMatthew Dillon    endif
164b412cc49SMatthew Dillonelse
165b412cc49SMatthew Dillon    echo "`$xdate` - Starting buildworld, tail -f $build/build.out"
166b412cc49SMatthew Dillon    make -j $ncpu buildworld >& $build/build.out
167b412cc49SMatthew Dillon    if ( $? ) then
168b412cc49SMatthew Dillon	echo "`$xdate` - primary environment buildworld failed"
169b412cc49SMatthew Dillon	echo "`$xdate` - SNAPSHOTS DOCLEAN END"
170b412cc49SMatthew Dillon	exit 1
171b412cc49SMatthew Dillon    endif
172b412cc49SMatthew Dillonendif
173b412cc49SMatthew Dillonendif
174b412cc49SMatthew Dillon
175b412cc49SMatthew Dillonif ( $?realquick == 0 ) then
176b412cc49SMatthew Dillon    echo "`$xdate` - Installing the world, tail -f $build/install.out"
177b412cc49SMatthew Dillon    make installworld DESTDIR=$build/root >& $build/install.out
178b412cc49SMatthew Dillon    pushd etc
179b412cc49SMatthew Dillon    make distribution DESTDIR=$build/root >& $build/install.out
180b412cc49SMatthew Dillon    popd
181b412cc49SMatthew Dillon    echo "`$xdate` - Upgrading the world, tail -f $build/upgrade.out"
182b412cc49SMatthew Dillon    make upgrade DESTDIR=$build/root >& $build/upgrade.out
183b412cc49SMatthew Dillonendif
184b412cc49SMatthew Dillon
185b412cc49SMatthew Dillon# Setup the chroot environment, including packages nrelease needs to
186b412cc49SMatthew Dillon# build.
187b412cc49SMatthew Dillon#
188b412cc49SMatthew Dillonecho "`$xdate` - Setting up chroot environment in $build/root"
189b412cc49SMatthew Dillonecho "`$xdate` - Mounting devfs"
190b412cc49SMatthew Dillonif ( ! -e $build/root/dev/null ) then
191b412cc49SMatthew Dillon    mount_devfs dummy $build/root/dev
192b412cc49SMatthew Dillonendif
193b412cc49SMatthew Dillon
194b412cc49SMatthew Dillon#mkdir -m 1777 $build/root/tmp
195b412cc49SMatthew Dillon#mkdir -m 1777 $build/root/var/tmp
196b412cc49SMatthew Dillon
197b412cc49SMatthew Dillonif ( $?realquick == 0 ) then
198b412cc49SMatthew Dillon    echo "`$xdate` - Setting up ldd"
199b412cc49SMatthew Dillon    chroot $build/root /etc/rc.d/ldconfig start
200b412cc49SMatthew Dillonendif
201b412cc49SMatthew Dilloncp /etc/resolv.conf $build/root/etc/
202*3dae329dSSascha Wildnerrm -rf $build/root/usr/obj/dports
203*3dae329dSSascha Wildnermkdir -p $build/root/usr/obj/dports
204b412cc49SMatthew Dillon
205*3dae329dSSascha Wildnercat > $build/root/etc/make.conf << EOF
206*3dae329dSSascha Wildner
207*3dae329dSSascha Wildner# set by doclean
208*3dae329dSSascha Wildner#
209*3dae329dSSascha Wildnergit_UNSET=CONTRIB PERL DIALOG
210*3dae329dSSascha Wildner
211*3dae329dSSascha WildnerEOF
212*3dae329dSSascha Wildner
213*3dae329dSSascha Wildnerif ( ! -e $build/root/usr/local/bin/bmake ) then
214*3dae329dSSascha Wildner    echo "`$xdate` - Bootstrapping dports, tail -f $build/bootstrap.out"
215*3dae329dSSascha Wildner    chroot $build/root csh -c "cd /usr/dports/devel/bmake; make all install" >& $build/bootstrap.out
216b412cc49SMatthew Dillon    if ( $? > 0 ) then
217*3dae329dSSascha Wildner	echo "`$xdate` - dports bootstrap had problems"
218b412cc49SMatthew Dillon	echo "`$xdate` - SNAPSHOTS DOCLEAN END"
219b412cc49SMatthew Dillon	exit 1
220b412cc49SMatthew Dillon    endif
221b412cc49SMatthew Dillonendif
222b412cc49SMatthew Dillon
223*3dae329dSSascha Wildner# The nrelease build needs cdrecord and git.  Try to get the binary package
224b412cc49SMatthew Dillon# first and then build whatever else is needed from source.  These packages
225b412cc49SMatthew Dillon# are not part of the nrelease snapshot build, they are used by nrelease
226b412cc49SMatthew Dillon# to do the build.
227b412cc49SMatthew Dillon#
228*3dae329dSSascha Wildnerif ( ! -e $build/root/usr/local/bin/mkisofs ) then
229*3dae329dSSascha Wildner    echo "`$xdate` - Setting up cdrecord and friends, tail -f $build/nrelease1.out"
230*3dae329dSSascha Wildner    #chroot $build/root csh -c "pkg_radd cdrecord"
231*3dae329dSSascha Wildner    if ( ! -e $build/root/usr/local/bin/mkisofs ) then
232b412cc49SMatthew Dillon	    echo "`$xdate` - Binary package not found, building from source"
233*3dae329dSSascha Wildner	    chroot $build/root csh -c "cd /usr/dports/sysutils/cdrtools; make -DBATCH all install"
234*3dae329dSSascha Wildner    endif
235*3dae329dSSascha Wildnerendif
236*3dae329dSSascha Wildner
237*3dae329dSSascha Wildnerif ( ! -e $build/root/usr/local/bin/git ) then
238*3dae329dSSascha Wildner    echo "`$xdate` - Setting up git from dports, tail -f $build/nrelease2.out"
239*3dae329dSSascha Wildner    #chroot $build/root csh -c "pkg_radd git"
240*3dae329dSSascha Wildner    if ( ! -e $build/root/usr/local/bin/git ) then
241*3dae329dSSascha Wildner	    echo "`$xdate` - Binary package not found, building from source"
242*3dae329dSSascha Wildner	    chroot $build/root csh -c "cd /usr/dports/devel/git; make -DBATCH all install"
243b412cc49SMatthew Dillon    endif
244b412cc49SMatthew Dillonendif
245b412cc49SMatthew Dillon
246b412cc49SMatthew Dillonecho "`$xdate` - SNAPSHOTS DOCLEAN END"
247*3dae329dSSascha Wildner
248