Generally use shorter, more idiomatic sh expressions in a bunch of

places.
This commit is contained in:
Warner Losh 2015-12-07 04:02:31 +00:00
parent a9598aae97
commit 849f5467cd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=291913

View File

@ -226,16 +226,18 @@ nano_make_kernel_env ( ) {
} }
nano_global_make_env ( ) ( nano_global_make_env ( ) (
[ ! -z "${NANO_ARCH}" ] && echo TARGET_ARCH="${NANO_ARCH}" || true # global settings for the make.conf file, if set
[ ! -z "${NANO_CPUTYPE}" ] && echo TARGET_CPUTYPE="${NANO_CPUTYPE}" || true [ -z "${NANO_ARCH}" ] || echo TARGET_ARCH="${NANO_ARCH}"
[ -z "${NANO_CPUTYPE}" ] || echo TARGET_CPUTYPE="${NANO_CPUTYPE}"
) )
# rm doesn't know -x prior to FreeBSD 10, so cope with a variety of build # rm doesn't know -x prior to FreeBSD 10, so cope with a variety of build
# hosts for now. # hosts for now. This will go away when support in the base goes away.
nano_rm ( ) { rm ( ) {
echo "NANO RM $*"
case $(uname -r) in case $(uname -r) in
7*|8*|9*) rm $* ;; 7*|8*|9*) command rm $* ;;
*) rm -x $* ;; *) command rm -x $* ;;
esac esac
} }
@ -250,18 +252,16 @@ CR0 ( ) {
} }
nano_cleanup ( ) ( nano_cleanup ( ) (
if [ $? -ne 0 ]; then [ $? -eq 0 ] || echo "Error encountered. Check for errors in last log file." 1>&2
echo "Error encountered. Check for errors in last log file." 1>&2
fi
exit $? exit $?
) )
clean_build ( ) ( clean_build ( ) (
pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})" pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})"
if ! nano_rm -rf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then if ! rm -rf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then
chflags -R noschg ${MAKEOBJDIRPREFIX}/ chflags -R noschg ${MAKEOBJDIRPREFIX}/
nano_rm -r ${MAKEOBJDIRPREFIX}/ rm -r ${MAKEOBJDIRPREFIX}/
fi fi
) )
@ -315,17 +315,17 @@ build_kernel ( ) (
clean_world ( ) ( clean_world ( ) (
if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then
pprint 2 "Clean and create object directory (${NANO_OBJ})" pprint 2 "Clean and create object directory (${NANO_OBJ})"
if ! nano_rm -rf ${NANO_OBJ}/ > /dev/null 2>&1 ; then if ! rm -rf ${NANO_OBJ}/ > /dev/null 2>&1 ; then
chflags -R noschg ${NANO_OBJ} chflags -R noschg ${NANO_OBJ}
nano_rm -r ${NANO_OBJ}/ rm -r ${NANO_OBJ}/
fi fi
mkdir -p "${NANO_OBJ}" "${NANO_WORLDDIR}" mkdir -p "${NANO_OBJ}" "${NANO_WORLDDIR}"
printenv > ${NANO_OBJ}/_.env printenv > ${NANO_OBJ}/_.env
else else
pprint 2 "Clean and create world directory (${NANO_WORLDDIR})" pprint 2 "Clean and create world directory (${NANO_WORLDDIR})"
if ! nano_rm -rf "${NANO_WORLDDIR}/" > /dev/null 2>&1 ; then if ! rm -rf "${NANO_WORLDDIR}/" > /dev/null 2>&1 ; then
chflags -R noschg "${NANO_WORLDDIR}" chflags -R noschg "${NANO_WORLDDIR}"
nano_rm -rf "${NANO_WORLDDIR}/" rm -rf "${NANO_WORLDDIR}/"
fi fi
mkdir -p "${NANO_WORLDDIR}" mkdir -p "${NANO_WORLDDIR}"
fi fi
@ -340,7 +340,7 @@ make_conf_install ( ) (
nano_global_make_env nano_global_make_env
echo "${CONF_WORLD}" echo "${CONF_WORLD}"
echo "${CONF_INSTALL}" echo "${CONF_INSTALL}"
if [ ! -z "${NANO_NOPRIV_BUILD}" ]; then if [ -n "${NANO_NOPRIV_BUILD}" ]; then
echo NO_ROOT=t echo NO_ROOT=t
echo METALOG=${NANO_METALOG} echo METALOG=${NANO_METALOG}
fi fi
@ -453,7 +453,7 @@ setup_nanobsd ( ) (
cd usr/local/etc cd usr/local/etc
find . -print | cpio -dumpl ../../../etc/local find . -print | cpio -dumpl ../../../etc/local
cd .. cd ..
nano_rm -rf etc rm -rf etc
ln -s ../../etc/local etc ln -s ../../etc/local etc
) )
fi fi
@ -474,7 +474,7 @@ setup_nanobsd ( ) (
echo "mount -o ro /dev/${NANO_DRIVE}${NANO_SLICE_CFG}" > conf/default/etc/remount echo "mount -o ro /dev/${NANO_DRIVE}${NANO_SLICE_CFG}" > conf/default/etc/remount
# Put /tmp on the /var ramdisk (could be symlink already) # Put /tmp on the /var ramdisk (could be symlink already)
nano_rm -rf tmp rm -rf tmp
ln -s var/tmp tmp ln -s var/tmp tmp
) > ${NANO_OBJ}/_.dl 2>&1 ) > ${NANO_OBJ}/_.dl 2>&1
@ -490,9 +490,9 @@ setup_nanobsd_etc ( ) (
touch etc/diskless touch etc/diskless
# Make root filesystem R/O by default # Make root filesystem R/O by default
[ ! -z "${NANO_NOPRIV_BUILD}" ] && chmod 666 etc/defaults/rc.conf [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 666 etc/defaults/rc.conf
echo "root_rw_mount=NO" >> etc/defaults/rc.conf echo "root_rw_mount=NO" >> etc/defaults/rc.conf
[ ! -z "${NANO_NOPRIV_BUILD}" ] && chmod 444 etc/defaults/rc.conf [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 444 etc/defaults/rc.conf
# save config file for scripts # save config file for scripts
echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf
@ -636,7 +636,7 @@ create_diskimage ( ) (
-y ${NANO_HEADS}` -y ${NANO_HEADS}`
else else
echo "Creating md backing file..." echo "Creating md backing file..."
nano_rm -f ${IMG} rm -f ${IMG}
dd if=/dev/zero of=${IMG} seek=${NANO_MEDIASIZE} count=0 dd if=/dev/zero of=${IMG} seek=${NANO_MEDIASIZE} count=0
MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \ MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \
-y ${NANO_HEADS}` -y ${NANO_HEADS}`
@ -678,7 +678,7 @@ create_diskimage ( ) (
nano_umount ${MNT} nano_umount ${MNT}
# Override the label from the first partition so we # Override the label from the first partition so we
# don't confuse glabel with duplicates. # don't confuse glabel with duplicates.
if [ ! -z ${NANO_LABEL} ]; then if [ -n ${NANO_LABEL} ]; then
tunefs -L ${NANO_LABEL}"${NANO_SLICE_ALTROOT}a" /dev/${MD}${NANO_SLICE_ALTROOT}a tunefs -L ${NANO_LABEL}"${NANO_SLICE_ALTROOT}a" /dev/${MD}${NANO_SLICE_ALTROOT}a
fi fi
fi fi
@ -687,12 +687,12 @@ create_diskimage ( ) (
populate_cfg_slice /dev/${MD}${NANO_SLICE_CFG} "${NANO_CFGDIR}" ${MNT} "${NANO_SLICE_CFG}" populate_cfg_slice /dev/${MD}${NANO_SLICE_CFG} "${NANO_CFGDIR}" ${MNT} "${NANO_SLICE_CFG}"
# Create Data slice, if any. # Create Data slice, if any.
if [ ! -z $NANO_SLICE_DATA -a $NANO_SLICE_CFG = $NANO_SLICE_DATA -a \ if [ -n $NANO_SLICE_DATA -a $NANO_SLICE_CFG = $NANO_SLICE_DATA -a \
$NANO_DATASIZE -ne 0 ]; then $NANO_DATASIZE -ne 0 ]; then
pprint 2 "NANO_SLICE_DATA is the same as NANO_SLICE_CFG, fix." pprint 2 "NANO_SLICE_DATA is the same as NANO_SLICE_CFG, fix."
exit 2 exit 2
fi fi
if [ $NANO_DATASIZE -ne 0 -a ! -z $NANO_SLICE_DATA ] ; then if [ $NANO_DATASIZE -ne 0 -a -n $NANO_SLICE_DATA ] ; then
populate_data_slice /dev/${MD}${NANO_SLICE_DATA} "${NANO_DATADIR}" ${MNT} "${NANO_SLICE_DATA}" populate_data_slice /dev/${MD}${NANO_SLICE_DATA} "${NANO_DATADIR}" ${MNT} "${NANO_SLICE_DATA}"
fi fi
@ -853,7 +853,7 @@ cust_pkgng ( ) (
echo "FAILED: pkg bootstrapping faied" echo "FAILED: pkg bootstrapping faied"
exit 2 exit 2
fi fi
nano_rm -f ${NANO_WORLDDIR}/Pkg/pkg-* rm -f ${NANO_WORLDDIR}/Pkg/pkg-*
# Count & report how many we have to install # Count & report how many we have to install
todo=`ls ${NANO_WORLDDIR}/Pkg | /usr/bin/wc -l` todo=`ls ${NANO_WORLDDIR}/Pkg | /usr/bin/wc -l`
@ -882,7 +882,7 @@ cust_pkgng ( ) (
exit 2 exit 2
fi fi
done done
nano_rm -rf ${NANO_WORLDDIR}/Pkg rm -rf ${NANO_WORLDDIR}/Pkg
) )
####################################################################### #######################################################################
@ -949,21 +949,21 @@ export_var ( ) { # Don't wawnt a subshell
# Call this function to set defaults _after_ parsing options. # Call this function to set defaults _after_ parsing options.
# dont want a subshell otherwise variable setting is thrown away. # dont want a subshell otherwise variable setting is thrown away.
set_defaults_and_export ( ) { set_defaults_and_export ( ) {
test -n "${NANO_OBJ}" || NANO_OBJ=/usr/obj/nanobsd.${NANO_NAME} : ${NANO_OBJ:=/usr/obj/nanobsd.${NANO_NAME}}
test -n "${MAKEOBJDIRPREFIX}" || MAKEOBJDIRPREFIX=${NANO_OBJ} : ${MAKEOBJDIRPREFIX:=${NANO_OBJ}}
test -n "${NANO_DISKIMGDIR}" || NANO_DISKIMGDIR=${NANO_OBJ} : ${NANO_DISKIMGDIR=:${NANO_OBJ}}
NANO_WORLDDIR=${NANO_OBJ}/_.w NANO_WORLDDIR=${NANO_OBJ}/_.w
NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build
NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install
# Override user's NANO_DRIVE if they specified a NANO_LABEL # Override user's NANO_DRIVE if they specified a NANO_LABEL
[ ! -z "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}" || true [ -n "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}" || true
# Set a default NANO_TOOLS to NANO_SRC/NANO_TOOLS if it exists. # Set a default NANO_TOOLS to NANO_SRC/NANO_TOOLS if it exists.
[ ! -d "${NANO_TOOLS}" ] && [ -d "${NANO_SRC}/${NANO_TOOLS}" ] && \ [ ! -d "${NANO_TOOLS}" ] && [ -d "${NANO_SRC}/${NANO_TOOLS}" ] && \
NANO_TOOLS="${NANO_SRC}/${NANO_TOOLS}" || true NANO_TOOLS="${NANO_SRC}/${NANO_TOOLS}" || true
[ ! -z "${NANO_NOPRIV_BUILD}" ] && [ -z "${NANO_METALOG}" ] && \ [ -n "${NANO_NOPRIV_BUILD}" ] && [ -z "${NANO_METALOG}" ] && \
NANO_METALOG=${NANO_OBJ}/_.metalog || true NANO_METALOG=${NANO_OBJ}/_.metalog || true
NANO_STARTTIME=`date +%s` NANO_STARTTIME=`date +%s`