Merge branch 'vendor/OPENPAM'
[dragonfly.git] / tools / snapshots / doclean
1 #!/bin/csh
2 #
3 # Create a working chroot for snapshot building
4 #
5
6 source config
7
8 set ncpu = `sysctl -n hw.ncpu`
9 set pushdsilent
10 set xdate = "date"
11
12 echo "`$xdate` - SNAPSHOTS DOCLEAN BEGIN"
13
14 # Options
15 #
16 foreach 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
30 end
31
32 # Remove environment
33 #
34 if ( "$build" == "" ) then
35     echo "build variable not set"
36     echo "`$xdate` - SNAPSHOTS DOCLEAN END"
37     exit 1
38 endif
39
40 if ( -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
48 endif
49
50 # remount the nullfs mount read-only just in case the umount fails.
51 #
52 umount $build/root/usr/pkgsrc/distfiles >& /dev/null
53 mount -u -o ro $build/root/usr/pkgsrc/distfiles >& /dev/null
54
55 if ( $?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
63 endif
64 mkdir -p $build/distfiles
65 mkdir -p $build/root
66 mkdir -p $build/root/usr
67
68 echo "`$xdate` - Log files are in $build/*.out"
69
70 # Ignore quick/realquick options if there is no prior
71 # installation
72 #
73 if ( ! -e $build/root/etc/networks ) then
74     unset realquick
75 endif
76 if ( ! -d $build/root/usr/src ) then
77     unset quick
78     unset realquick
79 endif
80 if ( ! -d $build/root/usr/pkgsrc ) then
81     unset quick
82     unset realquick
83 endif
84
85 # Clone the repos, create trakcing branches as necessary, checkout,
86 # and update (using fetch)
87 #
88 # DragonFly sources
89 #
90 pushd $build/root/usr
91 if ( $?quick == 0 ) then
92     echo "`$xdate` - Cloning $dflygit"
93     rm -rf src
94     git clone -n $dflygit src
95 endif
96 popd
97 pushd $build/root/usr/src
98 if ( "`git branch | fgrep $dfly_branch`" == "" ) then
99     echo "`$xdate` - Branching-src $dfly_branch"
100     git branch $dfly_branch origin/$dfly_branch
101 endif
102 echo "`$xdate` - Updating src"
103 git checkout $dfly_branch
104 git pull
105 popd
106
107 # Package sources
108 #
109 pushd $build/root/usr
110 if ( $?quick == 0 ) then
111     echo "`$xdate` - Cloning $pkgsrcgit"
112     rm -rf pkgsrc
113     git clone -n $pkgsrcgit pkgsrc
114 endif
115 popd
116 pushd $build/root/usr/pkgsrc
117 if ( "`git branch | fgrep $pkgsrc_branch`" == "" ) then
118     echo "`$xdate` - Branching-pkgsrc $pkgsrc_branch"
119     git branch $pkgsrc_branch origin/$pkgsrc_branch
120 endif
121 echo "`$xdate` - Updating pkgsrc"
122 git checkout $pkgsrc_branch
123 git pull
124 popd
125
126 # Install/upgrade environment
127 #
128 pushd $build/root/usr/src
129
130 if ( $?realquick ) then
131     echo "`$xdate` - Not running build/quickworld - realquick mode"
132 else
133 if ( $?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
141 else
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
149 endif
150 endif
151
152 if ( $?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
160 endif
161
162 popd
163
164 # Setup the chroot environment, including packages nrelease needs to
165 # build.
166 #
167 echo "`$xdate` - Setting up chroot environment in $build/root"
168 echo "`$xdate` - Mounting devfs"
169 if ( ! -e $build/root/dev/null ) then
170     mount_devfs dummy $build/root/dev
171 endif
172 echo "`$xdate` - Mounting distfiles"
173 mount_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
178 if ( $?realquick == 0 ) then
179     echo "`$xdate` - Setting up ldd"
180     chroot $build/root /etc/rc.d/ldconfig start
181 endif
182 cp /etc/resolv.conf $build/root/etc/
183
184 if ( ! -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
192 endif
193
194 if ( ! -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
203 endif
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 #
210 if ( ! -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
217 endif
218
219 echo "`$xdate` - SNAPSHOTS DOCLEAN END"