misc/160530: [patch] remove hardcoding of slice names

Garrett Cooper gcooper at ixsystems.com
Tue Sep 6 23:10:06 UTC 2011


>Number:         160530
>Category:       misc
>Synopsis:       [patch] remove hardcoding of slice names
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 06 23:10:04 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Garrett Cooper
>Release:        9.0-BETA1
>Organization:
iXsystems, Inc.
>Environment:
FreeBSD burnout.ixsystems.com 9.0-BETA1 FreeBSD 9.0-BETA1 #0 r224989: Sun Aug 21 14:12:11 PDT 2011     gcooper at burnout.ixsystems.com:/usr/obj/usr/src/sys/BURNOUT  amd64
>Description:
The current nanobsd updatep* scripts encourage hardcoding via hardcoded slice numbers, which makes it much more difficult to make maintainable scripts.

This patch takes a first step at cleaning up the scripts to use variables instead, s.t. the scripts can be broken up in the next patch to generalized functions called from the top-level script or the individual updatep* scripts.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

Index: tools/tools/nanobsd/Files/root/updatep1
===================================================================
--- tools/tools/nanobsd/Files/root/updatep1	(revision 224946)
+++ tools/tools/nanobsd/Files/root/updatep1	(working copy)
@@ -32,23 +32,26 @@
 #	ssh somewhere cat image.s1 | sh updatep1
 #
 
+PARTNUM=1
+OTHER_PARTNUM=2
+
 set -e
 
 . /etc/nanobsd.conf
 
-if mount | grep ${NANO_DRIVE}s1 > /dev/null ; then
-	echo "You are running partition 1 already"
-	echo "you probably want to use 'updatep2' instead"
+if mount | grep ${NANO_DRIVE}s$PARTNUM > /dev/null ; then
+	echo "You are running partition $PARTNUM already"
+	echo "you probably want to use 'updatep$OTHER_PARTNUM' instead"
 	exit 1
 fi
 
 # Blow away old system.
-dd if=/dev/zero of=/dev/${NANO_DRIVE}s1 bs=1m count=1 > /dev/null 2>&1
+dd if=/dev/zero of=/dev/${NANO_DRIVE}s$PARTNUM bs=1m count=1 > /dev/null 2>&1
 
 # Copy in new system
-dd of=/dev/${NANO_DRIVE}s1 obs=64k
+dd of=/dev/${NANO_DRIVE}s$PARTNUM obs=64k
 
 # Check that it worked
-fsck_ffs -n /dev/${NANO_DRIVE}s1a
+fsck_ffs -n /dev/${NANO_DRIVE}s${PARTNUM}a
 
-gpart set -a active -i 1 ${NANO_DRIVE}
+gpart set -a active -i $PARTNUM ${NANO_DRIVE}
Index: tools/tools/nanobsd/Files/root/updatep2
===================================================================
--- tools/tools/nanobsd/Files/root/updatep2	(revision 224946)
+++ tools/tools/nanobsd/Files/root/updatep2	(working copy)
@@ -32,30 +32,33 @@
 #	ssh somewhere cat image.s1 | sh updatep2
 #
 
+PARTNUM=2
+OTHER_PARTNUM=1
+
 set -e
 
 . /etc/nanobsd.conf
 
-if mount | grep ${NANO_DRIVE}s2 > /dev/null ; then
-	echo "You are running partition 2 already"
-	echo "you probably want to use 'updatep1' instead"
+if mount | grep ${NANO_DRIVE}s$PARTNUM > /dev/null ; then
+	echo "You are running partition $PARTNUM already"
+	echo "you probably want to use 'updatep$OTHER_PARTNUM' instead"
 	exit 1
 fi
 
 # Blow away old system.
-dd if=/dev/zero of=/dev/${NANO_DRIVE}s2 bs=1m count=1 > /dev/null 2>&1
+dd if=/dev/zero of=/dev/${NANO_DRIVE}s$PARTNUM bs=1m count=1 > /dev/null 2>&1
 
 # Copy in new system
-dd of=/dev/${NANO_DRIVE}s2 obs=64k
+dd of=/dev/${NANO_DRIVE}s$PARTNUM obs=64k
 
 # Check that it worked
-fsck_ffs -n /dev/${NANO_DRIVE}s2a
+fsck_ffs -n /dev/${NANO_DRIVE}s${PARTNUM}a
 
 # Update the /etc/fstab
 trap "umount /mnt" 1 2 15 EXIT
-mount /dev/${NANO_DRIVE}s2a /mnt
-sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/" /mnt/conf/base/etc/fstab
-sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/" /mnt/etc/fstab
+mount /dev/${NANO_DRIVE}s${PARTNUM}a /mnt
+sed -i "" "s/${NANO_DRIVE}s$OTHER_PARTNUM/${NANO_DRIVE}s$PARTNUM/" /mnt/conf/base/etc/fstab
+sed -i "" "s/${NANO_DRIVE}s$OTHER_PARTNUM/${NANO_DRIVE}s$PARTNUM/" /mnt/etc/fstab
 umount /mnt
 trap 1 2 15 EXIT
-gpart set -a active -i 2 ${NANO_DRIVE}
+gpart set -a active -i $PARTNUM ${NANO_DRIVE}


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list