Projet

Général

Profil

Télécharger (18,4 ko) Statistiques
| Branche: | Révision:

univnautes-tools / builder_scripts / build_snapshots.sh @ 5486cdee

1
#!/bin/sh
2
#
3
# ${PRODUCT_NAME} snapshot building system
4
# (C)2007, 2008, 2009 Scott Ullrich
5
# All rights reserved
6
#
7
# Redistribution and use in source and binary forms, with or without
8
# modification, are permitted provided that the following conditions
9
# are met:
10
#
11
# 1. Redistributions of source code must retain the above copyright
12
#    notice, this list of conditions and the following disclaimer.
13
#
14
# 2. Redistributions in binary form must reproduce the above copyright
15
#    notice, this list of conditions and the following disclaimer in the
16
#    documentation and/or other materials provided with the distribution.
17
#
18
#
19
# This script glues together the various FreeSBIE style pieces of the 
20
# ${PRODUCT_NAME} builder system and will build each style image: ISO, NanoBSD,
21
# DevISO, full update and NanoBSD updates and then copy the results of
22
# all the builds to the public facing WWW server.  This script will 
23
# invoke the scripts directly such as build_iso.sh and build_nano.sh, 
24
# etc.
25
#
26
# Crank up error reporting, debugging.
27
#  set -e
28
#  set -x
29

    
30
if [ ! -f ./pfsense-build.conf ]; then
31
	echo "You must first run ./set_version.sh !"
32
	exit 1
33
fi
34

    
35
NO_UPLOAD=""
36
LOOPED_SNAPSHOTS=""
37

    
38
# Handle command line arguments
39
while test "$1" != "" ; do
40
	case $1 in
41
	--no-ports|--noports|-n)
42
		NO_PORTS=yo
43
		;;
44
	--noupload|-u)
45
		NO_UPLOAD="-u"
46
		;;
47
	--looped)
48
		LOOPED_SNAPSHOTS="true"
49
	esac
50
	shift
51
done
52

    
53
# Source ${PRODUCT_NAME} / FreeSBIE variables
54
# *** DO NOT SOURCE BUILDER_COMMON.SH!
55
# *** IT WILL BREAK EVERYTHING FOR 
56
# *** SOME UNKNOWN LAYERING REASON.
57
# *** 04/07/2008, 11/04/2009                      
58
echo ">>> Execing pfsense-build.conf"
59
. ./builder_defaults.sh
60

    
61
# Unset do not build ports flag
62
rm -f $SCRATCHDIR/pfSense_do_not_build_pfPorts
63

    
64
# Keeps track of how many time builder has looped
65
BUILDCOUNTER=0
66

    
67
# Local variables that are used by builder scripts
68
STAGINGAREA=/tmp/staging
69
RSYNCIP="snapshots.pfsense.org"
70
RSYNCKBYTELIMIT="248000"
71
PINGTIME="999"
72
PINGMAX="40"
73
PINGIP="snapshots.pfsense.org"
74

    
75
export SNAPSHOTSLOGFILE=${SNAPSHOTSLOGFILE:-"$SCRATCHDIR/snapshots-build.log"}
76
export SNAPSHOTSLASTUPDATE=${SNAPSHOTSLASTUPDATE:-"$SCRATCHDIR/snapshots-lastupdate.log"}
77
export MASTER_BUILDER_SSH_LOG_DEST=${MASTER_BUILDER_SSH_LOG_DEST:-snapshots@${RSYNCIP}:/usr/local/www/snapshots/logs/pfSense_${PFSENSETAG}__FreeBSD_${FREEBSD_VERSION}/${TARGET}/build.log}
78

    
79
# Ensure directories exist
80
mkdir -p $STAGINGAREA
81

    
82
if [ -f $SCRATCHDIR/pfPorts_forced_build_required ]; then
83
	rm $SCRATCHDIR/pfPorts_forced_build_required
84
fi
85

    
86
echo "" > $SNAPSHOTSLOGFILE
87
echo "" > $SNAPSHOTSLASTUPDATE
88

    
89
git_last_commit() {
90
	if [ -d "${1}" ]; then
91
		(cd ${1} && git fetch && git reset ${2})>/dev/null
92
		CURRENT_COMMIT=$(cd "${1}" && git log | head -n1 | cut -d' ' -f2)
93
		echo ">>> CURRENT_COMMIT: ${CURRENT_COMMIT} on ${1}"
94
		return $CURRENT_COMMIT
95
	else
96
		update_status ">>> WARNING: pfSenseGITREPO variable not set! Previous commit functions disabled."
97
	fi
98
}
99

    
100
# This routine is called in between runs. We
101
# will sleep for a bit and check for new commits
102
# in between sleeping for short durations.
103
sleep_between_runs() {
104
	COUNTER=0
105
	while [ $COUNTER -lt $maxsleepvalue ]; do
106
		sleep 60
107
		PFSENSE_CURRENT_COMMIT=$(git_last_commit "${GIT_REPO_DIR}/pfSenseGITREPO" origin/${PFSENSETAG})
108
		if [ "$PFSENSE_LAST_COMMIT" != "$PFSENSE_CURRENT_COMMIT" ]; then
109
			update_status ">>> New commit: $CURRENT_AUTHOR - $PFSENSE_CURRENT_COMMIT .. No longer sleepy."
110
			COUNTER="`expr $maxsleepvalue + 60`"
111
			export PFSENSE_LAST_COMMIT="${PFSENSE_CURRENT_COMMIT}"
112
			return
113
		fi
114
		TOOLS_CURRENT_COMMIT=$(git_last_commit "${BUILDER_SCRIPTS}" origin)
115
		if [ "$TOOLS_LAST_COMMIT" != "$TOOLS_CURRENT_COMMIT" ]; then
116
			update_status ">>> New commit: $CURRENT_AUTHOR - $TOOLS_CURRENT_COMMIT .. No longer sleepy."
117
			COUNTER="`expr $maxsleepvalue + 60`"
118
			export TOOLS_LAST_COMMIT="${TOOLS_CURRENT_COMMIT}"
119
			return
120
		fi
121
		COUNTER="`expr $COUNTER + 60`"
122
	done
123
	if [ $COUNTER -ge $maxsleepvalue ]; then
124
		update_status ">>> Sleep timer expired. Restarting build."
125
		maxsleepvalue=0
126
		COUNTER=0
127
	fi
128
}
129

    
130
# This routine is called to write out to stdout
131
# a string.   The string is appeneded to $SNAPSHOTSLOGFILE
132
# and we scp the log file to the builder host if
133
# needed for the real time logging functions.
134
update_status() {
135
	if [ "$1" = "" ]; then
136
		return
137
	fi
138
	echo $1
139
	echo "`date` -|- $1" >> $SNAPSHOTSLOGFILE
140
	if [ -n "$MASTER_BUILDER_SSH_LOG_DEST" -a -z "${NO_UPLOAD}" ]; then
141
		LU=`cat $SNAPSHOTSLASTUPDATE`
142
		CT=`date "+%H%M%S"`
143
		# Only update every minute
144
		if [ "$LU" != "$CT" ]; then 
145
			scp -q $SNAPSHOTSLOGFILE $MASTER_BUILDER_SSH_LOG_DEST
146
			date "+%H%M%S" > $SNAPSHOTSLASTUPDATE
147
		fi
148
	fi
149
}
150

    
151
# Copy the current log file to $filename.old on
152
# the snapshot www server (real time logs)
153
rotate_logfile() {
154
	if [ -n "$MASTER_BUILDER_SSH_LOG_DEST" -a -z "${NO_UPLOAD}" ]; then
155
		scp -q $SNAPSHOTSLOGFILE $MASTER_BUILDER_SSH_LOG_DEST.old
156
	fi
157

    
158
	# Cleanup log file
159
	echo "" > $SNAPSHOTSLOGFILE
160
}
161

    
162
post_tweet() {
163
	TWEET_MESSAGE="$1"
164
	if [ "$TWITTER_USERNAME" = "" ]; then
165
		update_status ">>> ERROR: Could not find TWITTER_USERNAME -- tweet cancelled."
166
		return
167
	fi
168
	if [ "$TWITTER_PASSWORD" = "" ]; then
169
		update_status ">>> ERROR: Could not find TWITTER_PASSWORD -- tweet cancelled."
170
		return
171
	fi
172
	if [ ! -f "/usr/local/bin/curl" ]; then 
173
		update_status ">>> ERROR: Could not find /usr/local/bin/curl -- tweet cancelled."
174
		return
175
	fi
176
	update_status ">>> Tweet:"
177
	update_status ">>> ${TWEET_MESSAGE}"
178
	echo -n ">>> Posting tweet..."
179
	`/usr/local/bin/curl --silent --basic --user "$TWITTER_USERNAME:$TWITTER_PASSWORD" --data status="$TWEET_MESSAGE" http://twitter.com/statuses/update.xml` > $SCRATCHDIR/tweet_diag.txt 2>&1
180
	update_status "Done!"
181
}
182

    
183
dobuilds() {
184
	# Set a common DATESTRING for the build if not set from builder_defaults.sh.
185
	# Rely on builder_defaults.sh doing the right job the first time included from this script.
186

    
187
	# NOTE: This is needed to have autoupdate detect a new version.
188
	# There is max a second difference here with DATESTRING which should not be a problem
189
	echo "$BUILTDATESTRING" > $BUILTDATESTRINGFILE
190
	echo "$DATESTRING" > $DATESTRINGFILE
191

    
192
	cd $BUILDER_SCRIPTS
193
	# Build images
194
	./build.sh --flash-size '1g 2g 4g' "iso memstick memstickserial fullupdate nanobsd nanobsd-vga"
195
	# Copy files
196
	copy_to_staging_iso_updates
197
	copy_to_staging_nanobsd '1g 2g 4g'
198

    
199
	rm $DATESTRINGFILE
200
	rm $BUILTDATESTRINGFILE
201
	# Override it here to have continuous builds with proper labels
202
	export DATESTRING=`date "+%Y%m%d-%H%M"`
203
	export BUILTDATESTRING=`date "+%a %b %d %T %Z %Y"`
204
	echo "$BUILTDATESTRING" > $BUILTDATESTRINGFILE
205
	echo "$DATESTRING" > $DATESTRINGFILE
206
}
207

    
208
copy_to_staging_nanobsd() {
209
	cd $BUILDER_SCRIPTS
210

    
211
	for NANOTYPE in nanobsd nanobsd-vga; do
212
		for FILESIZE in ${1}; do
213
			FILENAMEFULL="${PRODUCT_NAME}-${PFSENSE_VERSION}-${FILESIZE}-${TARGET}-${NANOTYPE}-${DATESTRING}.img.gz"
214
			FILENAMEUPGRADE="${PRODUCT_NAME}-${PFSENSE_VERSION}-${FILESIZE}-${TARGET}-${NANOTYPE}-upgrade-${DATESTRING}.img.gz"
215
			mkdir -p $STAGINGAREA/nanobsd
216
			mkdir -p $STAGINGAREA/nanobsdupdates
217

    
218
			cp $MAKEOBJDIRPREFIXFINAL/$FILENAMEFULL $STAGINGAREA/nanobsd/ 2>/dev/null
219
			cp $MAKEOBJDIRPREFIXFINAL/$FILENAMEUPGRADE $STAGINGAREA/nanobsdupdates 2>/dev/null
220

    
221
			if [ -f $STAGINGAREA/nanobsd/$FILENAMEFULL ]; then
222
				md5 $STAGINGAREA/nanobsd/$FILENAMEFULL > $STAGINGAREA/nanobsd/$FILENAMEFULL.md5 2>/dev/null
223
				sha256 $STAGINGAREA/nanobsd/$FILENAMEFULL > $STAGINGAREA/nanobsd/$FILENAMEFULL.sha256 2>/dev/null
224
			fi
225
			if [ -f $STAGINGAREA/nanobsdupdates/$FILENAMEUPGRADE ]; then
226
				md5 $STAGINGAREA/nanobsdupdates/$FILENAMEUPGRADE > $STAGINGAREA/nanobsdupdates/$FILENAMEUPGRADE.md5 2>/dev/null
227
				sha256 $STAGINGAREA/nanobsdupdates/$FILENAMEUPGRADE > $STAGINGAREA/nanobsdupdates/$FILENAMEUPGRADE.sha256 2>/dev/null
228
			fi
229

    
230
			# Copy NanoBSD auto update:
231
			if [ -f $STAGINGAREA/nanobsdupdates/$FILENAMEUPGRADE ]; then
232
				cp $STAGINGAREA/nanobsdupdates/$FILENAMEUPGRADE $STAGINGAREA/latest-${NANOTYPE}-$FILESIZE.img.gz 2>/dev/null
233
				sha256 $STAGINGAREA/latest-${NANOTYPE}-$FILESIZE.img.gz > $STAGINGAREA/latest-${NANOTYPE}-$FILESIZE.img.gz.sha256 2>/dev/null
234
				# NOTE: Updates need a file with output similar to date  output
235
				# Use the file generated at start of dobuilds() to be consistent on times
236
				cp $BUILTDATESTRINGFILE $STAGINGAREA/version-${NANOTYPE}-$FILESIZE
237
			fi
238
		done
239
	done
240
}
241

    
242
copy_to_staging_iso_updates() {
243
	cd $BUILDER_SCRIPTS
244

    
245
	# Copy ISOs
246
	md5 ${ISOPATH}.gz > ${ISOPATH}.md5
247
	sha256 ${ISOPATH}.gz > ${ISOPATH}.sha256
248
	cp ${ISOPATH}* $STAGINGAREA/ 2>/dev/null
249

    
250
	# Copy memstick items
251
	md5 ${MEMSTICKPATH}.gz > ${MEMSTICKPATH}.md5
252
	sha256 ${MEMSTICKPATH}.gz > ${MEMSTICKPATH}.sha256
253
	cp ${MEMSTICKPATH}* $STAGINGAREA/ 2>/dev/null
254

    
255
	md5 ${MEMSTICKSERIALPATH}.gz > ${MEMSTICKSERIALPATH}.md5
256
	sha256 ${MEMSTICKSERIALPATH}.gz > ${MEMSTICKSERIALPATH}.sha256
257
	cp ${MEMSTICKSERIALPATH}* $STAGINGAREA/ 2>/dev/null
258

    
259
	md5 ${UPDATES_TARBALL_FILENAME} > ${UPDATES_TARBALL_FILENAME}.md5
260
	sha256 ${UPDATES_TARBALL_FILENAME} > ${UPDATES_TARBALL_FILENAME}.sha256
261
	cp ${UPDATES_TARBALL_FILENAME}* $STAGINGAREA/ 2>/dev/null
262
	# NOTE: Updates need a file with output similar to date  output
263
	# Use the file generated at start of dobuilds() to be consistent on times
264
	cp $BUILTDATESTRINGFILE $STAGINGAREA/version 2>/dev/null
265
}
266

    
267
check_for_congestion() {
268
#	cd $BUILDER_SCRIPTS
269
#	echo -n ">>> Waiting for Internet congestion to die down before rsync operations: $PINGTIME "
270
#	while [ "$PINGTIME" -gt "$PINGMAX" ]; do
271
#		PINGTIME=`ping -c1 $PINGIP | grep time | cut -d"=" -f4 | cut -d" " -f1 | cut -d"." -f1`
272
#		echo -n " $PINGTIME"
273
#		sleep 10
274
#	done
275
#	echo ""
276
}
277

    
278
scp_files() {
279
	cd $BUILDER_SCRIPTS
280
	if [ -z "${RSYNC_COPY_ARGUMENTS:-}" ]; then
281
		RSYNC_COPY_ARGUMENTS="-ave ssh --timeout=60 --bwlimit=${RSYNCKBYTELIMIT}" #--bwlimit=50
282
	fi
283
	update_status ">>> Copying files to snapshots.pfsense.org"
284
	if [ ! -f /usr/local/bin/rsync ]; then
285
		update_status ">>> Could not find rsync, installing from ports..."
286
		(cd /usr/ports/net/rsync && make install clean)
287
	fi
288
	rm -f $SCRATCHDIR/ssh-snapshots*
289

    
290
	# Ensure directory(s) are available
291
	ssh snapshots@${RSYNCIP} "mkdir -p /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/livecd_installer"
292
	ssh snapshots@${RSYNCIP} "mkdir -p /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/updates"
293
	ssh snapshots@${RSYNCIP} "mkdir -p /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/nanobsd"
294
	if [ -d $STAGINGAREA/virtualization ]; then
295
		ssh snapshots@${RSYNCIP} "mkdir -p /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/virtualization"
296
	fi
297
	ssh snapshots@${RSYNCIP} "mkdir -p /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/.updaters"
298
	# ensure permissions are correct for r+w
299
	ssh snapshots@${RSYNCIP} "chmod -R ug+rw /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/."
300
	ssh snapshots@${RSYNCIP} "chmod -R ug+rw /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/."
301
	ssh snapshots@${RSYNCIP} "chmod -R ug+rw /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/*/."
302
	check_for_congestion
303
	rsync $RSYNC_COPY_ARGUMENTS $STAGINGAREA/${PRODUCT_NAME}-*iso* \
304
		snapshots@${RSYNCIP}:/usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/livecd_installer/
305
	check_for_congestion
306
	rsync $RSYNC_COPY_ARGUMENTS $STAGINGAREA/${PRODUCT_NAME}-memstick* \
307
		snapshots@${RSYNCIP}:/usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/livecd_installer/
308
	check_for_congestion
309
	rsync $RSYNC_COPY_ARGUMENTS $STAGINGAREA/${PRODUCT_NAME}-*Update* \
310
		snapshots@${RSYNCIP}:/usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/updates/
311
	check_for_congestion
312
	rsync $RSYNC_COPY_ARGUMENTS $STAGINGAREA/nanobsd/* \
313
		snapshots@${RSYNCIP}:/usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/nanobsd/
314
	check_for_congestion
315
	rsync $RSYNC_COPY_ARGUMENTS $STAGINGAREA/nanobsdupdates/* \
316
		snapshots@${RSYNCIP}:/usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/updates/
317
	check_for_congestion
318
	if [ -d $STAGINGAREA/virtualization ]; then
319
		rsync $RSYNC_COPY_ARGUMENTS $STAGINGAREA/virtualization/* \
320
			snapshots@${RSYNCIP}:/usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/virtualization/
321
		check_for_congestion
322
	fi
323

    
324
	# Rather than copy these twice, use ln to link to the latest one.
325

    
326
	ssh snapshots@${RSYNCIP} "rm -f /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/.updaters/latest.tgz"
327
	ssh snapshots@${RSYNCIP} "rm -f /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/.updaters/latest.tgz.sha256"
328

    
329
	LATESTFILENAME="`ls $UPDATESDIR/*.tgz | grep Full | grep -v md5 | grep -v sha256 | tail -n1`"
330
	LATESTFILENAME=`basename ${LATESTFILENAME}`
331
	ssh snapshots@${RSYNCIP} "ln -s /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/updates/${LATESTFILENAME} \
332
		/usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/.updaters/latest.tgz"
333
	ssh snapshots@${RSYNCIP} "ln -s /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/updates/${LATESTFILENAME}.sha256 \
334
		/usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/.updaters/latest.tgz.sha256"
335

    
336
	for i in 1g 2g 4g
337
	do
338
		ssh snapshots@${RSYNCIP} "rm -f /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/.updaters/latest-nanobsd-${i}.img.gz"
339
		ssh snapshots@${RSYNCIP} "rm -f /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/.updaters/latest-nanobsd-${i}.img.gz.sha256"
340
		ssh snapshots@${RSYNCIP} "rm -f /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/.updaters/latest-nanobsd-vga-${i}.img.gz"
341
		ssh snapshots@${RSYNCIP} "rm -f /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/.updaters/latest-nanobsd-vga-${i}.img.gz.sha256"
342

    
343
		FILENAMEUPGRADE="${PRODUCT_NAME}-${PFSENSE_VERSION}-${i}-${TARGET}-nanobsd-upgrade-${DATESTRING}.img.gz"
344
		ssh snapshots@${RSYNCIP} "ln -s /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/updates/${FILENAMEUPGRADE} \
345
			/usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/.updaters/latest-nanobsd-${i}.img.gz"
346
		ssh snapshots@${RSYNCIP} "ln -s /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/updates/${FILENAMEUPGRADE}.sha256 \
347
			/usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/.updaters/latest-nanobsd-${i}.img.gz.sha256"
348

    
349
		FILENAMEUPGRADE="${PRODUCT_NAME}-${PFSENSE_VERSION}-${i}-${TARGET}-nanobsd-vga-upgrade-${DATESTRING}.img.gz"
350
		ssh snapshots@${RSYNCIP} "ln -s /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/updates/${FILENAMEUPGRADE} \
351
			/usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/.updaters/latest-nanobsd-vga-${i}.img.gz"
352
		ssh snapshots@${RSYNCIP} "ln -s /usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/updates/${FILENAMEUPGRADE}.sha256 \
353
			/usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/.updaters/latest-nanobsd-vga-${i}.img.gz.sha256"
354
	done
355

    
356
	check_for_congestion
357
	rsync $RSYNC_COPY_ARGUMENTS $STAGINGAREA/version* \
358
		snapshots@${RSYNCIP}:/usr/local/www/snapshots/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/.updaters
359
	update_status ">>> Finished copying files."
360
}
361

    
362
cleanup_builds() {
363
	cd $BUILDER_SCRIPTS
364
	# Remove prior builds
365
	update_status ">>> Cleaning up after prior builds..."
366
	rm -rf $STAGINGAREA/*
367
	rm -f $UPDATESDIR/*  # Keep updates dir slimmed down
368
	rm -rf $MAKEOBJDIRPREFIXFINAL/*
369
	./build.sh --clean-builder
370
}
371

    
372
build_loop_operations() {
373
	cd $BUILDER_SCRIPTS
374
	update_status ">>> Starting build loop operations"
375
	# --- Items we need to run for a complete build run ---
376
	# Cleanup prior builds
377
	cleanup_builds
378
	# Do the builds
379
	dobuilds
380
	# SCP files to snapshot web hosting area
381
	if [ -z "${NO_UPLOAD}" ]; then
382
		scp_files
383
	fi
384
	# Alert the world that we have some snapshots ready.
385
	update_status ">>> Builder run is complete."
386
	post_tweet "Snapshots for FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}-${PFSENSETAG} have been copied http://snapshots.pfsense.org/FreeBSD_${FREEBSD_BRANCH}/${TARGET}/${PRODUCT_NAME}_${PFSENSETAG}/"
387
}
388

    
389
if [ -z "${LOOPED_SNAPSHOTS}" ]; then
390
	build_loop_operations
391
else
392
	# Main builder loop
393
	while [ /bin/true ]; do
394
		BUILDCOUNTER=`expr $BUILDCOUNTER + 1`
395
		update_status ">>> Starting builder run #${BUILDCOUNTER}..."
396
		# We can disable ports builds
397
		if [ "$NO_PORTS" = "yo" ]; then
398
			update_status ">>> Not building pfPorts at all during this snapshot builder looped run..."
399
			touch $SCRATCHDIR/pfSense_do_not_build_pfPorts
400
		else
401
			if [ "$BUILDCOUNTER" -gt 1 ]; then 
402
				update_status ">>> Previous snapshot runs deteceted, not building pfPorts again..."
403
				touch $SCRATCHDIR/pfSense_do_not_build_pfPorts
404
			else
405
				update_status ">>> Building pfPorts on this snapshot run..."
406
				rm -f $SCRATCHDIR/pfSense_do_not_build_pfPorts
407
			fi
408
		fi
409

    
410
		# Launch the snapshots builder script and pipe its
411
		# contents to the while loop so we can record the 
412
		# script progress in real time to the public facing
413
		# snapshot server (snapshots.pfsense.org).
414
		( build_loop_operations ) | while read LINE
415
		do
416
			update_status "$LINE"
417
		done
418

    
419
		export minsleepvalue=28800
420
		export maxsleepvalue=86400
421
		update_status ">>> Sleeping for at least $minsleepvalue, at most $maxsleepvalue in between snapshot builder runs.  Last known commit ${PFSENSE_LAST_COMMIT}/${TOOLS_LAST_COMMIT}"
422
		update_status ">>> Freezing build process at `date`."
423
		sleep $minsleepvalue
424
		update_status ">>> Thawing build process and resuming checks for pending commits at `date`."
425

    
426
		# Count some sheep or wait until a new commit turns up 
427
		# for one days time.  We will wake up if a new commit
428
		# is deteceted during sleepy time.
429
		sleep_between_runs $maxsleepvalue
430

    
431
		# If REBOOT_AFTER_SNAPSHOT_RUN is defined reboot
432
		# the box after the run. 
433
		if [ ! -z "${REBOOT_AFTER_SNAPSHOT_RUN:-}" ]; then
434
			update_status ">>> Rebooting `hostname` due to \$REBOOT_AFTER_SNAPSHOT_RUN"
435
			shutdown -r now
436
			kill $$
437
		fi
438
		# Rotate log file (.old)
439
		rotate_logfile
440
	done
441
fi
(2-2/7)