>Number:         160896
>Category:       conf
>Synopsis:       [patch] use getopts, jobs option, delay -c usage improvements 
>to nanobsd.sh
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 22 07:40:07 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Garrett Cooper
>Release:        9.0-BETA2
>Organization:
iXsystems, Inc.
>Environment:
FreeBSD bayonetta.local 9.0-BETA2 FreeBSD 9.0-BETA2 #0 r225653M: Tue Sep 20 
08:36:49 PDT 2011     [email protected]:/usr/obj/usr/src/sys/BAYONETTA  
amd64
>Description:
This patch does the following items:

1. Drops getopt in favor of getopts builtin handling. This is preferred as 
getopt is deprecated by POSIX.
2. Adds a -j option so that users can specify -j via the command line, which is 
passed to make.
3. Delays the sourcing of the nanobsd config_file so that users can depend on 
already on internal variables that are set later, like $NANO_MAKE_CONF_BUILD . 
This makes it possible for developers to depend on this file.

These enhancements were based on some of the code present in the FreeNAS 
sourcebase.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

Index: tools/tools/nanobsd/nanobsd.sh
===================================================================
--- tools/tools/nanobsd/nanobsd.sh      (revision 225704)
+++ tools/tools/nanobsd/nanobsd.sh      (working copy)
@@ -58,7 +58,7 @@
 #NANO_DISKIMGDIR=""
 
 # Parallel Make
-NANO_PMAKE="make -j 3"
+NANO_PMAKE="make"
 
 # The default name for any image we create.
 NANO_IMGNAME="_.disk.full"
@@ -588,6 +588,8 @@
        # after the build completed, for instance to copy the finished
        # image to a more convenient place:
        # cp ${NANO_DISKIMGDIR}/_.disk.image /home/ftp/pub/nanobsd.disk
+       # The following line is needed to keep bash from barfing on the file.
+       :
 )
 
 #######################################################################
@@ -758,102 +760,103 @@
 # Progress Print
 #      Print $2 at level $1.
 pprint() {
-    if [ "$1" -le $PPLEVEL ]; then
-       runtime=$(( `date +%s` - $NANO_STARTTIME ))
-       printf "%s %.${1}s %s\n" "`date -u -r $runtime +%H:%M:%S`" "#####" "$2" 
1>&3
-    fi
+       if [ "$1" -le $PPLEVEL ]; then
+               runtime=$(( $(date +'%s') - ${NANO_STARTTIME} ))
+               printf "%s %.${1}s %s\n" "$(date -u -r $runtime +%H:%M:%S)" 
"#####" "$2" >&3
+       fi
 }
 
 usage () {
-       (
-       echo "Usage: $0 [-bfiknqvw] [-c config_file]"
-       echo "  -b      suppress builds (both kernel and world)"
-       echo "  -f      suppress code slice extraction"
-       echo "  -i      suppress disk image build"
-       echo "  -k      suppress buildkernel"
-       echo "  -n      add -DNO_CLEAN to buildworld, buildkernel, etc"
-       echo "  -q      make output more quiet"
-       echo "  -v      make output more verbose"
-       echo "  -w      suppress buildworld"
-       echo "  -c      specify config file"
-       ) 1>&2
+       cat >&2 <<EOF
+usage: ${0##*/} [-biknqvw] [-c config_file]
+       -b              suppress builds (both kernel and world)
+       -c config_file  config file to use after defining all
+                       internal variables.
+       -i              suppress disk image build
+       -j make-jobs    number of make jobs to invoke
+       -k              suppress buildkernel
+       -n              add -DNO_CLEAN to buildworld, buildkernel, etc
+       -q              make output more quiet
+       -v              make output more verbose
+       -w              suppress buildworld
+EOF
        exit 2
 }
 
 #######################################################################
 # Parse arguments
 
+set +e
+
 do_clean=true
 do_kernel=true
 do_world=true
 do_image=true
 do_copyout_partition=true
+make_jobs=3
+nano_conf=
 
-set +e
-args=`getopt bc:fhiknqvw $*`
-if [ $? -ne 0 ] ; then
-       usage
-       exit 2
-fi
-set -e
-
-set -- $args
-for i
+while getopts 'bc:hij:knqvw' optch
 do
-       case "$i" 
-       in
-       -b)
+       case "$optch" in
+       b)
                do_world=false
                do_kernel=false
-               shift
                ;;
-       -k)
-               do_kernel=false
-               shift
+       c)
+               if [ -f "$OPTARG" ]; then
+                       nano_conf=$OPTARG
+               fi
                ;;
-       -c)
-               . "$2"
-               shift
-               shift
-               ;;
-       -f)
+       f)
                do_copyout_partition=false
-               shift
                ;;
-       -h)
+       h)
                usage
                ;;
-       -i)
+       i)
                do_image=false
-               shift
                ;;
-       -n)
+       j)
+               echo $OPTARG | egrep -q '^[[:digit:]]+$' && [ $OPTARG -gt 0 ]
+               if [ $? -ne 0 ]; then
+                       echo "${0##*/}: -j value must be a positive integer."
+                       usage
+               fi
+               make_jobs=$OPTARG
+               ;;
+       k)
+               do_kernel=false
+               ;;
+       n)
                do_clean=false
-               shift
                ;;
-       -q)
-               PPLEVEL=$(($PPLEVEL - 1))
-               shift
+       q)
+               : $(( PPLEVEL -= 1))
                ;;
-       -v)
-               PPLEVEL=$(($PPLEVEL + 1))
-               shift
+       v)
+               : $(( PPLEVEL += 1))
                ;;
-       -w)
+       w)
                do_world=false
-               shift
                ;;
-       --)
-               shift
-               break
+       *)
+               usage
+               ;;
        esac
 done
 
+shift $(( $OPTIND - 1 ))
+
 if [ $# -gt 0 ] ; then
-       echo "$0: Extraneous arguments supplied"
+       echo "${0##*/}: extraneous arguments supplied"
        usage
 fi
 
+NANO_PMAKE="$NANO_PMAKE -j $make_jobs"
+
+set -e
+
 #######################################################################
 # Setup and Export Internal variables
 #
@@ -865,6 +868,11 @@
 NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build
 NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install
 
+if [ -n "$nano_conf" ]; then
+       echo "Sourcing $nano_conf"
+       . "$nano_conf"
+fi
+
 if [ -d ${NANO_TOOLS} ] ; then
        true
 elif [ -d ${NANO_SRC}/${NANO_TOOLS} ] ; then


>Release-Note:
>Audit-Trail:
>Unformatted:
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "[email protected]"

Reply via email to