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