Project

General

Profile

« Previous | Next » 

Revision ef98fd9f

Added by Scott Ullrich about 16 years ago

Adding NanoBSD upgrade bits

View differences:

etc/rc.firmware
147 147
		rm -f /var/run/config.lock
148 148
		sh /etc/rc.reboot
149 149
	fi
150
	;;
151
pfSenseNanoBSDupgrade)
152

  
153
	# Sanity check - bail early if there's no firmware file!
154
	if [ ! -r $IMG ]; then
155
		echo "2nd parameter has not been passed or file does not exist. Exiting." >> /cf/upgrade_log.txt 2>&1
156
		exit 1
157
	fi
158

  
159
	touch /var/run/firmware.lock
160

  
161
	echo "Firmware upgrade in progress..."  >> /cf/upgrade_log.txt 2>&1
162
	echo "Firmware upgrade in progress..." | wall
163

  
164
	# mount /cf
165
	/etc/rc.conf_mount_rw
166

  
167
	# backup config
168
	/bin/mkdir -p /tmp/configbak
169
	cp -p /conf/* /tmp/configbak 2>/dev/null
170

  
171
	touch /cf/upgrade_log.txt
172
	echo "" > /cf/upgrade_log.txt
173

  
174
	echo "Installing $IMG." >> /cf/upgrade_log.txt 2>&1
175
	echo "Installing $IMG." >> /cf/upgrade_log.txt
176

  
177
	# resolve glabel label that we booted from
178
	BOOT_DEVICE=`/sbin/mount | /usr/bin/grep pfsense | /usr/bin/cut -d'/' -f4 | /usr/bin/cut -d' ' -f1`
179
	# resolve glabel to the real boot dev entry
180
	REAL_BOOT_DEVICE=`/sbin/glabel list | /usr/bin/grep -B2 ufs/${BOOT_DEVICE} | /usr/bin/head -n 1 | /usr/bin/cut -f3 -d' '`
181
	# grab the boot device, example ad1, ad0
182
	BOOT_DRIVE=`/sbin/glabel list | /usr/bin/grep -B2 ufs/pfsense | /usr/bin/head -n 1 | /usr/bin/cut -f3 -d' ' | /usr/bin/cut -d's' -f1`
183
	# test the slice.  if we are on slice 1 we need to flash 2 and vica versa
184
	if [ `echo $REAL_BOOT_DEVICE | /usr/bin/grep "s1"` ]; then 
185
		SLICE="2"
186
		OLDSLICE="1"
187
		TOFLASH="${BOOT_DRIVE}s${SLICE}"
188
		COMPLETE_PATH="${BOOT_DRIVE}s${SLICE}a"
189
		GLABEL_SLICE="pfsense1"
190
	else
191
		SLICE="1"
192
		OLDSLICE="2"		
193
		TOFLASH="${BOOT_DRIVE}s${SLICE}"
194
		COMPLETE_PATH="${BOOT_DRIVE}s${SLICE}a"
195
		GLABEL_SLICE="pfsense0"		
196
	fi
197

  
198
	# Output specifc information that this script is using
199
	echo "SLICE $SLICE" >> /cf/upgrade_log.txt
200
	echo "OLDSLICE $OLDSLICE" >> /cf/upgrade_log.txt
201
	echo "TOFLASH $TOFLASH" >> /cf/upgrade_log.txt
202
	echo "COMPLETE_PATH $COMPLETE_PATH" >> /cf/upgrade_log.txt
203
	echo "GLABEL_SLICE $GLABEL_SLICE" >> /cf/upgrade_log.txt
204

  
205
	# Output environment information to log file
206
	output_env_to_log
207

  
208
	# Foot shooting is fun!
209
	echo "" >> /cf/upgrade_log.txt
210
	echo "/sbin/sysctl kern.geom.debugflags=16" >> /cf/upgrade_log.txt
211
	/sbin/sysctl kern.geom.debugflags=16 >> /cf/upgrade_log.txt 2>&1
212

  
213
	# Remove TOFLASH and get ready for new flash image
214
	echo "" >> /cf/upgrade_log.txt
215
	echo "dd if=/dev/zero of=/dev/${TOFLASH} bs=1m count=1" >> /cf/upgrade_log.txt	
216
	dd if=/dev/zero of=/dev/${TOFLASH} bs=1m count=1 >> /cf/upgrade_log.txt 2>&1
217

  
218
	# Stream gzipped image to dd and explode image to new area
219
	echo "" >> /cf/upgrade_log.txt
220
	echo "/usr/bin/gunzip -S '' -c $IMG | /bin/dd of=/dev/${TOFLASH} bs=16k" >> /cf/upgrade_log.txt
221
	/usr/bin/gunzip -S "" -c $IMG | /bin/dd of=/dev/${TOFLASH} bs=16k >> /cf/upgrade_log.txt 2>&1
222

  
223
	# Ensure that our new system is sound and bail if it is not and file a notice
224
	echo "" >> /cf/upgrade_log.txt
225
	echo "/sbin/fsck_ffs -y /dev/$COMPLETE_PATH" >> /cf/upgrade_log.txt
226
	/sbin/fsck_ffs -y /dev/$COMPLETE_PATH >> /cf/upgrade_log.txt 2>&1
227
	if [ $? != 0 ]; then
228
		/usr/local/bin/php -q -d auto_prepend_file=config.inc <<ENDOFF
229
		<?php
230
			require_once("globals.inc");		
231
			require_once("functions.inc");
232
			file_notice("UpgradeFailure", "{\$g['product_name']} upgrade has failed.   Your system has been left in a usable state.", "UpgradeFailure", "");
233
		?>
234
ENDOFF
235
		rm /var/run/firmware.lock
236
		exit 1
237
	fi
238

  
239
	# Add back the corresponding glabel
240
	echo "" >> /cf/upgrade_log.txt
241
	echo "/sbin/tunefs -L ${GLABEL_SLICE} /dev/$COMPLETE_PATH" >> /cf/upgrade_log.txt
242
	/sbin/tunefs -L ${GLABEL_SLICE} /dev/$COMPLETE_PATH >> /cf/upgrade_log.txt 2>&1
243

  
244
	# Set active boot source
245
	echo "" >> /cf/upgrade_log.txt
246
	echo "/usr/sbin/boot0cfg -s ${SLICE} -v /dev/${BOOT_DRIVE}" >> /cf/upgrade_log.txt
247
	/usr/sbin/boot0cfg -s ${SLICE} -v /dev/${BOOT_DRIVE} >> /cf/upgrade_log.txt 2>&1
248

  
249
	# Set active mount slice in fdisk
250
	echo "" >> /cf/upgrade_log.txt
251
	echo "gpart set -a active -i ${SLICE} ${BOOT_DRIVE}" >> /cf/upgrade_log.txt
252
	gpart set -a active -i ${SLICE} ${BOOT_DRIVE}
253

  
254
	# restore config
255
	cp -p /tmp/configbak/* /conf 2>/dev/null
256

  
257
	# Remove upgrade file
258
	rm -f $IMG
259

  
260
	# Mount newly prepared slice
261
	mkdir /tmp/$GLABEL_SLICE
262
	mount /dev/ufs/$GLABEL_SLICE /tmp/$GLABEL_SLICE
263

  
264
	# If /tmp/$TOFLASH/tmp/post_upgrade_command exists 
265
	# after update then execute the command.
266
	if [ -f /tmp/$TOFLASH/tmp/post_upgrade_command ]; then
267
		sh /tmp/$TOFLASH/tmp/post_upgrade_command >> /cf/upgrade_log.txt 2>&1
268
	fi
269

  
270
	# Update fstab
271
	sed -i "" "s/pfsense${OLDSLICE}/pfsense${SLICE}/g" /tmp/$GLABEL_SLICE/etc/fstab
272
	echo "" >> /cf/upgrade_log.txt
273
	cat /tmp/$GLABEL_SLICE/etc/fstab >> /cf/upgrade_log.txt
274

  
275
	# Unmount newly prepared slice
276
	umount /tmp/$GLABEL_SLICE
277

  
278
	# Remove extra stuff
279
	rm -rf /etc/rc.conf
280
	rm -rf /etc/motd
281
	rm -rf /usr/savecore/*
282

  
283
	date >> /cf/upgrade_log.txt
284
	echo "" >> /cf/upgrade_log.txt
285

  
286
	# remount /cf ro
287
	/etc/rc.conf_mount_ro
288
	/bin/sync
289
	echo "Done." >> /cf/upgrade_log.txt 2>&1
290

  
291
	# Enough fun for now.
292
	echo "" >> /cf/upgrade_log.txt
293
	echo "/sbin/sysctl kern.geom.debugflags=0" >> /cf/upgrade_log.txt
294
	/sbin/sysctl kern.geom.debugflags=0 >> /cf/upgrade_log.txt 2>&1
295

  
296
	rm -f /var/run/firmware.lock
297
	sh /etc/rc.reboot
298

  
150 299
	;;
151 300
pfSenseupgrade)
152 301
	# wait 5 seconds before beginning

Also available in: Unified diff