From owner-freebsd-bugs@FreeBSD.ORG Tue Sep 6 23:10:06 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C1280106566B for ; Tue, 6 Sep 2011 23:10:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 9811B8FC08 for ; Tue, 6 Sep 2011 23:10:05 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p86NA5LY096347 for ; Tue, 6 Sep 2011 23:10:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p86NA5S0096346; Tue, 6 Sep 2011 23:10:05 GMT (envelope-from gnats) Resent-Date: Tue, 6 Sep 2011 23:10:05 GMT Resent-Message-Id: <201109062310.p86NA5S0096346@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Garrett Cooper Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ACE1A106564A for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/160530: [patch] remove hardcoding of slice names X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Sep 2011 23:10:06 -0000 >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@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: