summaryrefslogtreecommitdiff
path: root/mk/bulk/pre-build
blob: 9d63eb6c0abe8226f2ca76f7ab4cce5d701ce042 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/sh
# $NetBSD: pre-build,v 1.47 2005/03/31 23:36:15 reed Exp $
#
# Clean up system to be ready for bulk pkg build
#
# (c) 2000 Hubert Feyrer, All Rights Reserved.
#

#set -v		# Debug

# Pull in USR_PKGSRC, CVS_USER:
if [ -f "$BULK_BUILD_CONF" ]; then
    . $BULK_BUILD_CONF
else
    . `dirname $0`/build.conf
fi

PRUNEDISTFILES=${PRUNEDISTFILES:-"no"}
PRUNEPACKAGES=${PRUNEPACKAGES:-"yes"}
PRUNELINKS=${PRUNEPACKAGES:-"yes"}

PKGLINT_PKG_DIR=${USR_PKGSRC}/pkgtools/pkglint

# Extract the name of the files used for the build log and broken build log.
# These have defaults set by bsd.bulk-pkg.mk and may be overridden in
# /etc/mk.conf
BROKENF=`( cd ${PKGLINT_PKG_DIR} ; ${BMAKE} show-var VARNAME=BROKENFILE )`;
export BROKENF
if [ "$BROKENF" = "" ]; then
	echo "Had problems determining the name of the .broken files"
	exit 1
fi
BRKWRKLOG=`( cd ${PKGLINT_PKG_DIR} ; ${BMAKE} show-var VARNAME=BROKENWRKLOG )`;
if [ "$BRKWRKLOG" = "" ]; then
	echo "Had problems determining the name of the .broken.work files"
	exit 1
fi
BLDLOG=`( cd ${PKGLINT_PKG_DIR} ; ${BMAKE} show-var VARNAME=BUILDLOG )`;
if [ "$BLDLOG" = "" ]; then
	echo "Had problems determining the name of the .make files"
	exit 1
fi
LINTPKGSRC_DB=`( cd ${PKGLINT_PKG_DIR} ; ${BMAKE} show-var VARNAME=LINTPKGSRC_DB )`;
if [ "$LINTPKGSRC_DB" = "" ]; then
	echo "Had problems determining the name of the .lintpkgsrc.db file"
	exit 1
fi
STARTFILE=`( cd ${PKGLINT_PKG_DIR} ; ${BMAKE} show-var VARNAME=STARTFILE )`;
if [ "$STARTFILE" = "" ]; then
	echo "Had problems determining the name of the .start file"
	exit 1
fi

LOCALBASE=`( cd ${PKGLINT_PKG_DIR} ; ${BMAKE} show-var VARNAME=LOCALBASE )`;
X11BASE=`( cd ${PKGLINT_PKG_DIR} ; ${BMAKE} show-var VARNAME=X11BASE )`;
DISTDIR=`( cd ${PKGLINT_PKG_DIR} ; ${BMAKE} show-var VARNAME=DISTDIR )`;

# Make sure the pkg-vulnerabilities file is up to date
echo "Making sure vulnerability-list is upto date:"
if [ -z "$UPDATE_VULNERABILITY_LIST" -o "$UPDATE_VULNERABILITY_LIST" = yes ]; then
       ( cd ${USR_PKGSRC}/security/audit-packages                       \
         && ${BMAKE} bulk-install                                       \
         && env PKGVULNDIR=${DISTDIR} download-vulnerability-list )
       echo 'done.'
else
       echo '(skipped)'
fi

# On non-NetBSD platforms we need to keep the bootstrap-files!
if [ x"$BMAKE" = x"bmake" ]; then
	( cd $LOCALBASE && tar cf /tmp/$$.tar                                \
		sbin/mtree sbin/pkg_add sbin/pkg_admin sbin/pkg_create       \
		sbin/pkg_delete sbin/pkg_info sbin/pkg_view sbin/linkfarm    \
		share/mk/sys.mk share/mk/bsd.dep.mk share/mk/bsd.depall.mk   \
		share/mk/bsd.files.mk share/mk/bsd.hostprog.mk               \
		share/mk/bsd.doc.mk share/mk/bsd.inc.mk share/mk/bsd.info.mk \
		share/mk/bsd.kernobj.mk share/mk/bsd.kinc.mk                 \
		share/mk/bsd.kmod.mk share/mk/bsd.lib.mk                     \
		share/mk/bsd.links.mk share/mk/bsd.man.mk                    \
		share/mk/bsd.nls.mk share/mk/bsd.obj.mk                      \
		share/mk/bsd.prog.mk share/mk/bsd.subdir.mk                  \
		share/mk/bsd.sys.mk share/mk/bsd.own.mk                      \
		bin/bmake bin/ftp bin/digest bin/nbsed bin/install-sh        \
		bin/pax bin/tar bin/cpio man/cat1/ftp.1 man/cat1/pax.0       \
		man/cat1/tar.0 man/cat1/cpio.0 man/cat1/pkg_add.0            \
		man/cat1/pkg_admin.0 man/cat1/pkg_create.0                   \
		man/cat1/pkg_delete.0 man/cat1/pkg_info.0                    \
		man/cat1/pkg_view.0 man/cat1/linkfarm.0                      \
		man/man1/digest.1 man/man1/pax.1 man/man1/cpio.1             \
		man/man1/tar.1 man/man1/nbsed.1 man/man1/pkg_add.1           \
		man/man1/pkg_admin.1 man/man1/pkg_create.1                   \
		man/man1/pkg_delete.1 man/man1/pkg_info.1                    \
		man/man1/pkg_view.1 man/man1/linkfarm.1 man/cat8/mtree.0     \
		man/man8/mtree.8 man/cat7/packages.0 )
fi

#
# Clean out everything and its mother
#
PKG_DBDIR=`(cd ${PKGLINT_PKG_DIR}; ${BMAKE} show-var VARNAME=PKG_DBDIR)`
DEPOTBASE=`(cd ${PKGLINT_PKG_DIR}; ${BMAKE} show-var VARNAME=DEPOTBASE)`

for dbdir in ${PKG_DBDIR} ${DEPOTBASE}; do
	echo Removing all installed packages in $dbdir
	if [ -d $dbdir ]; then
		cd $dbdir
		for pkg in *
		do
			if `pkg_info -K $dbdir -qe $pkg`; then
				echo pkg_delete -r $pkg
				pkg_delete -K $dbdir -r $pkg
			fi
		done
		#
		# this should have removed everything.
		# Now force any broken pkgs to deinstall.
		#
		for pkg in *
		do
			if `pkg_info -K $dbdir -qe $pkg`; then
				echo pkg_delete -f $pkg
				pkg_delete -K $dbdir -f $pkg
			fi
		done
	
		# We've tried our best to get rid of the pkgs, now do it
		# the hard way.  If it wasn't for stuff in $X11BASE, I
		# wouldn't have hard feelings about this!
		rm -fr *
	fi
done

cd $LOCALBASE && rm -fr * && rm -fr .??*;
if [ x"$BMAKE" = x"bmake" ]; then
	( cd $LOCALBASE && tar xf /tmp/$$.tar )
fi

# Stuff known to be broken
rm -fr $X11BASE/share/gimp
rm -fr $X11BASE/share/gnome
rm -fr $X11BASE/share/kde
rm -fr $X11BASE/share/netscape
rm -fr /var/tmp/inst*
rm -fr $X11BASE/lib/libgimp*	# gimp doesn't build with old libs around
rm -fr /nonexistent		# broken useradd on pop3d
rm -fr /home/majordom		# mail/majordomo pkg
rm -fr /home/nut		# sysutils/ups-net
rm -fr /var/wwwoffle		# www/wwwoffle
rm -fr /tmp/config-guess-*
rm -fr /tmp/mod*


# Clean up state files
cd ${USR_PKGSRC}
echo Cleaning up leftover state files from previous runs
rm -f */*/$BROKENF */*/$BRKWRKLOG */*/$BLDLOG
rm -f $BROKENF $BRKWRKLOG $BLDLOG $STARTFILE




#
# Install cvs package and do a cvs update here
#
if [ "$CVS_USER" != "" ]; then
	if [ ! -f /usr/bin/cvs ]; then
		echo Installing required cvs pkgs for CVS update
		( cd ${USR_PKGSRC}/devel/cvs ; ${BMAKE} bulk-install )
	fi
	if [ ! -f /usr/bin/ssh ]; then
		echo Installing required ssh pkgs for CVS update
		( cd ${USR_PKGSRC}/security/ssh ; ${BMAKE} bulk-install )
	fi
	echo Performing CVS update - this will take some time
	su - ${CVS_USER} -c "stty sane ; cd ${USR_PKGSRC} ;                  \
		env CVS_RSH=ssh cvs -q update -Pd ${CVS_FLAGS} || exit 0"
        if [ $? != 0 ]
        then
                echo CVS update not successful, aborting.
                exit 1
        fi
	echo CVS update done.
fi

#
# Remove old/broken distfiles and binary packages
#
PACKAGES=`( cd ${PKGLINT_PKG_DIR} ; ${BMAKE} show-var VARNAME=PACKAGES )`;

case "$LINTPKGSRC_CACHE$PRUNEDISTFILES$PRUNEPACKAGES" in
*yes*|*YES*)
	# install pkglint to support any of these options
	( cd ${PKGLINT_PKG_DIR} ; ${BMAKE} PRECLEAN=yes bulk-install )
	;;
esac

case "$LINTPKGSRC_CACHE" in
yes|YES)
	echo "Creating lintpkgsrc cache database."
	lintpkgsrc -K $PACKAGES -P $USR_PKGSRC -M $DISTDIR -E $LINTPKGSRC_DB
	lintpkgsrc_cache="-I $LINTPKGSRC_DB"
	echo done.
	;;
*)
	lintpkgsrc_cache=''
	;;
esac

case "$PRUNEDISTFILES" in
yes|YES)
	echo "Removing old/broken distfiles"
	lintpkgsrc $lintpkgsrc_cache -K $PACKAGES -P $USR_PKGSRC -M $DISTDIR -o -m -r
	echo done.
	;;
*)
	echo "Skipping distfile pruning."
	;;
esac

case "$PRUNEPACKAGES" in
yes|YES)
	echo "Removing old (out of date) binary packages"
	lintpkgsrc $lintpkgsrc_cache -K $PACKAGES -P $USR_PKGSRC -M $DISTDIR -p -r
	echo done.
	;;
*)
	echo "Skipping packages pruning."
	;;
esac

case "$PRUNELINKS" in
yes|YES)
	echo "Checking for and removing orphaned packages links"
	find $PACKAGES -type l -print |  \
	while read f
	do
		if [ ! -d $f -a ! -f $f ]; then
			echo "Removing orphaned link:  \"$f\""
			rm $f
		fi
	done
	echo done.
	;;
*)
	echo "Skipping pruning of packages links."
	;;
esac

# Clean out the packages added above so that the real bulk build
# is started in a consistent state.
for dbdir in ${PKG_DBDIR} ${DEPOTBASE}; do
	echo Removing all installed packages in $dbdir
	if [ -d $dbdir ]; then
		cd $dbdir
		for pkg in *
		do
			if `pkg_info -K $dbdir -qe $pkg`; then
				echo pkg_delete -r $pkg
				pkg_delete -K $dbdir -r $pkg
			fi
		done
	fi
done

cd ${USR_PKGSRC}

# on non-NetBSD, we don't want these to build as they overwrite
# bootstrap-pkgsrc generated files and thus would break the following builds.

if [ x"$BMAKE" = x"bmake" ]; then
	for pkg in archivers/pax devel/bmake devel/mk-files net/tnftp \
	    security/kth-krb4 textproc/nbsed; do
		echo "Don't blow away bootstrap-pkgsrc stuff!" > \
		${pkg}/${BROKENF}
	done
fi

if [ -f mk/bulk/pre-build.local ]; then
	. mk/bulk/pre-build.local
fi

if [ ! -d ${PKG_DBDIR} ]; then
	mkdir ${PKG_DBDIR}
fi

touch $STARTFILE