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