fastbulk - Exit w/success on more conditions
[dragonfly.git] / test / fastbulk / dobuild
CommitLineData
b050e616
MD
1#!/bin/csh
2#
3# This is run from the chroot via fastbulk, which has CDd
4# into a particular pkgsrc directory and wants us to build it.
e7db1956 5# The script is run as /tmp/track/dobuild
b050e616 6
853176ea
MD
7set logname = "$argv[1]"
8
e7db1956
MD
9# We do not want to interfere with builds of other versions
10# of the same package, use a temporary lock file to prevent a
11# conflict.
12#
13if ( $#argv == 1 ) then
14 set pkgwild = "`bmake show-var VARNAME=PKGWILDCARD`.lck"
40db7aaf 15 set pkgname = "`bmake show-var VARNAME=PKGNAME`"
853176ea
MD
16
17 if ( -f /usr/pkgsrc/packages/All/${pkgname}.tgz ) then
18 if ( -f /tmp/logs/good/$logname ) then
19 rm -f /tmp/logs/run/$logname
20 echo "FASTBULK QUICK ${logname}: `date`" \
21 >> /tmp/logs/good/$logname
22 echo "FASTBULK: Package already exists, will not build" \
23 >> /tmp/logs/good/$logname
24 else
25 echo "FASTBULK: Package already exists, will not build"
26 endif
27 exit 0
28 endif
29
e7db1956 30 mkdir -p /tmp/track/locks
ab988e04
MD
31 echo "FASTBULK START ${argv[1]}: `date`"
32 lockf "/tmp/track/locks/$pkgwild" /tmp/track/dobuild ${argv[1]} "$pkgwild"
33 if ( $status == 0 ) then
34 echo "FASTBULK SUCCESS ${argv[1]}: `date`"
35 exit 0
36 else
37 echo "FASTBULK FAILURE ${argv[1]}: `date`"
40db7aaf
MD
38 find /var/db/pkg/$pkgname -name '*.core' -delete
39 rmdir /var/db/pkg/$pkgname >& /dev/null
ab988e04
MD
40 exit 1
41 endif
e7db1956
MD
42endif
43
44# Get the package name and clean up any garbage that might
45# interfere with the build.
b050e616
MD
46#
47set pkgname = "`bmake show-var VARNAME=PKGNAME`"
ab988e04 48set pkgwild = "$argv[2]"
1b3b024a
MD
49unsetenv PKG_PATH
50
40db7aaf
MD
51# Make sure /var/db/pkg/ does not have any .core files messing it up,
52# remove the recorded installation if it becomes empty.
53#
54find /var/db/pkg/$pkgname -name '*.core' -delete
55rmdir /var/db/pkg/$pkgname >& /dev/null
56
1b3b024a 57# Check if already installed, prevent overwrite of
e7db1956
MD
58# previous run's logfile if it exists, by deleting
59# the current run file. Else put in a simple logfile.
1b3b024a
MD
60#
61pkg_info -q -e $pkgname
62if ( $status == 0 ) then
63 if ( -f /tmp/logs/good/$logname ) then
64 rm -f /tmp/logs/run/$logname
65 endif
66 echo "(already installed from previous run)"
b050e616
MD
67 exit 0
68endif
69
ab988e04
MD
70# Delete potential conflicts
71#
72pkg_delete -r "$pkgwild"
73
e7db1956
MD
74# If we already have a binary package just install
75# it.
76#
1b3b024a
MD
77if ( -f /usr/pkgsrc/packages/All/${pkgname}.tgz ) then
78 echo "(found in /usr/pkgsrc/packages)"
79 bmake deinstall DEINSTALLDEPENDS=ALL SKIP_LICENSE_CHECK=yes
80 setenv PKG_PATH /usr/pkgsrc/packages/All
81 echo "pkg_add -f ${pkgname}"
82 pkg_add -f ${pkgname}
83 exit $status
84endif
85
e7db1956
MD
86# We need to build the package.
87#
88# Delete any conflicting installed packages or the one we want to build
89# will refuse to build. The binary package files are left intact.
b050e616
MD
90#
91foreach i ( `bmake show-var VARNAME=CONFLICTS` )
92 echo "DELETING CONFLICTING PACKAGE: $i"
93 pkg_delete -r "$i"
94end
95
ab988e04
MD
96# If the dist file checksum fails and the dist file is over
97# 4 hours old we re-download it.
98#
99
100set dollar = '$'
101set distfiles = "`bmake -V '${dollar}{DISTFILES}'`"
102bmake checksum SKIP_LICENSE_CHECK=yes
103if ( $status != 0 ) then
104 echo "Deleting distfiles ( $distfiles ) if over 4h old"
105 foreach dfile ( $distfiles )
106 find /usr/pkgsrc/distfiles -name "$dfile" -mtime +4h -delete
107 end
108endif
109
b050e616
MD
110# To ensure a clean build deinstall anything that
111# may cause our build repackage to fail.
112#
e7db1956
MD
113# Clean after repackaging to keep the work topology footprint small.
114#
115# We create a binary package and then pkg_add it.
b050e616
MD
116#
117bmake deinstall DEINSTALLDEPENDS=ALL SKIP_LICENSE_CHECK=yes
e7db1956 118bmake repackage SKIP_LICENSE_CHECK=yes
1b3b024a 119if ( $status == 0 ) then
e7db1956 120 bmake clean SKIP_LICENSE_CHECK=yes
1b3b024a
MD
121 setenv PKG_PATH /usr/pkgsrc/packages/All
122 echo "pkg_add -f ${pkgname}"
123 pkg_add -f ${pkgname}
853176ea
MD
124 if ( $status != 0 ) then
125 if ( -f ${PKG_PATH}/${pkgname}.tgz ) then
126 echo "FASTBULK WARNING: Cannot install due to probable conflicts"
127 echo " but the binary package DID build."
128 echo " Exiting w/code 0 to mark as successful."
129 else
130 exit 1
131 endif
132 endif
133 exit 0
1b3b024a 134endif
e7db1956
MD
135
136# comment this bmake out if you want to keep the work dir
137# for failed builds.
138#
139bmake clean SKIP_LICENSE_CHECK=yes
1b3b024a 140exit 1