From nobody@FreeBSD.org  Tue Sep  6 23:06:02 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id ACE1A106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  6 Sep 2011 23:06:02 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 9C22F8FC20
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  6 Sep 2011 23:06:02 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p86N62Et099573
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 6 Sep 2011 23:06:02 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p86N6206099572;
	Tue, 6 Sep 2011 23:06:02 GMT
	(envelope-from nobody)
Message-Id: <201109062306.p86N6206099572@red.freebsd.org>
Date: Tue, 6 Sep 2011 23:06:02 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] remove hardcoding of slice names in nanobsd update scripts
X-Send-Pr-Version: www-3.1
X-GNATS-Notify: delphij@FreeBSD.org

>Number:         160530
>Category:       misc
>Synopsis:       [nanobsd] [patch] remove hardcoding of slice names
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    imp
>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:  Sun Feb 03 22:29:24 UTC 2013
>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@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:
Responsible-Changed-From-To: freebsd-bugs->imp 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed Sep 7 00:27:20 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=160530 

From: Garrett Cooper <yaneurabeya@gmail.com>
To: bug-followup@FreeBSD.org, gcooper@ixsystems.com
Cc:  
Subject: Re: misc/160530: [nanobsd] [patch] remove hardcoding of slice names
Date: Wed, 26 Oct 2011 16:28:01 -0700

 Ping? We've been using a variant of this patch for ~2 months now at iX
 without issue, so I think it's ok to commit...
 Thanks,
 -Garrett
>Unformatted:
