svn commit: r220059 - head/usr.sbin/pc-sysinstall/backend
Josh Paetzel
jpaetzel at FreeBSD.org
Sun Mar 27 16:57:54 UTC 2011
Author: jpaetzel
Date: Sun Mar 27 16:57:54 2011
New Revision: 220059
URL: http://svn.freebsd.org/changeset/base/220059
Log:
Fix a syntax error in a little-used function.
Replace expr with $(())
Replace grep > /dev/null with grep -q
Replace "$?" = "0" with $? -eq 0 in tests
Consolidate export statements with variable assignment
Replace tests for ! -z with -n
Approved by: kib (mentor)
Modified:
head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh
head/usr.sbin/pc-sysinstall/backend/functions-cleanup.sh
head/usr.sbin/pc-sysinstall/backend/functions-disk.sh
head/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh
head/usr.sbin/pc-sysinstall/backend/functions-ftp.sh
head/usr.sbin/pc-sysinstall/backend/functions-installcomponents.sh
head/usr.sbin/pc-sysinstall/backend/functions-installpackages.sh
head/usr.sbin/pc-sysinstall/backend/functions-localize.sh
head/usr.sbin/pc-sysinstall/backend/functions-mountoptical.sh
head/usr.sbin/pc-sysinstall/backend/functions-networking.sh
head/usr.sbin/pc-sysinstall/backend/functions-packages.sh
head/usr.sbin/pc-sysinstall/backend/functions-parse.sh
head/usr.sbin/pc-sysinstall/backend/functions-runcommands.sh
head/usr.sbin/pc-sysinstall/backend/functions-unmount.sh
head/usr.sbin/pc-sysinstall/backend/functions-upgrade.sh
head/usr.sbin/pc-sysinstall/backend/functions-users.sh
head/usr.sbin/pc-sysinstall/backend/functions.sh
head/usr.sbin/pc-sysinstall/backend/parseconfig.sh
head/usr.sbin/pc-sysinstall/backend/startautoinstall.sh
Modified: head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh
==============================================================================
--- head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh Sun Mar 27 16:18:51 2011 (r220058)
+++ head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh Sun Mar 27 16:57:54 2011 (r220059)
@@ -33,14 +33,14 @@ check_for_enc_pass()
CURLINE="${1}"
get_next_cfg_line "${CFGF}" "${CURLINE}"
- echo ${VAL} | grep "^encpass=" >/dev/null 2>/dev/null
- if [ "$?" = "0" ] ; then
+ echo ${VAL} | grep -q "^encpass=" 2>/dev/null
+ if [ $? -eq 0 ] ; then
# Found a password, return it
get_value_from_string "${VAL}"
return
fi
- VAL="" ; export VAL
+ export VAL=""
return
};
@@ -51,17 +51,17 @@ get_fs_line_xvars()
ACTIVEDEV="${1}"
LINE="${2}"
- echo $LINE | grep ' (' >/dev/null 2>/dev/null
- if [ "$?" = "0" ] ; then
+ echo $LINE | grep -q ' (' 2>/dev/null
+ if [ $? -eq 0 ] ; then
# See if we are looking for ZFS specific options
- echo $LINE | grep '^ZFS' >/dev/null 2>/dev/null
- if [ "$?" = "0" ] ; then
+ echo $LINE | grep -q '^ZFS' 2>/dev/null
+ if [ $? -eq 0 ] ; then
ZTYPE="NONE"
ZFSVARS="`echo $LINE | cut -d '(' -f 2- | cut -d ')' -f 1 | xargs`"
- echo $ZFSVARS | grep -E "^(disk|file|mirror|raidz(1|2)?|spare|log|cache):" >/dev/null 2>/dev/null
- if [ "$?" = "0" ] ; then
+ echo $ZFSVARS | grep -qE "^(disk|file|mirror|raidz(1|2)?|spare|log|cache):" 2>/dev/null
+ if [ $? -eq 0 ] ; then
ZTYPE=`echo $ZFSVARS | cut -f1 -d:`
ZFSVARS=`echo $ZFSVARS | sed "s|$ZTYPE: ||g" | sed "s|$ZTYPE:||g"`
fi
@@ -79,8 +79,7 @@ get_fs_line_xvars()
fi # End of xtra-options block
# If we got here, set VAR to empty and export
- VAR=""
- export VAR
+ export VAR=""
return
};
@@ -94,12 +93,12 @@ setup_zfs_mirror_parts()
for _zvars in $_mirrline
do
echo "Looping through _zvars: $_zvars" >>${LOGOUT}
- echo "$_zvars" | grep "${2}" >/dev/null 2>/dev/null
- if [ "$?" = "0" ] ; then continue ; fi
+ echo "$_zvars" | grep -q "${2}" 2>/dev/null
+ if [ $? -eq 0 ] ; then continue ; fi
if [ -z "$_zvars" ] ; then continue ; fi
is_disk "$_zvars" >/dev/null 2>/dev/null
- if [ "$?" = "0" ] ; then
+ if [ $? -eq 0 ] ; then
echo "Setting up ZFS mirror disk $_zvars" >>${LOGOUT}
init_gpt_full_disk "$_zvars" >/dev/null 2>/dev/null
rc_halt "gpart bootcode -p /boot/gptzfsboot -i 1 ${_zvars}" >/dev/null 2>/dev/null
@@ -138,12 +137,12 @@ gen_glabel_name()
while
Z=1
do
- glabel status | grep "${NAME}${NUM}" >/dev/null 2>/dev/null
- if [ "$?" != "0" ]
+ glabel status | grep -q "${NAME}${NUM}" 2>/dev/null
+ if [ $? -ne 0 ]
then
break
else
- NUM="`expr ${NUM} + 1`"
+ NUM=$((NUM+1))
fi
if [ $NUM -gt $MAXNUM ]
@@ -154,8 +153,7 @@ gen_glabel_name()
done
- VAL="${NAME}${NUM}"
- export VAL
+ export VAL="${NAME}${NUM}"
};
# Function to setup partitions using gpart
@@ -180,8 +178,8 @@ setup_gpart_partitions()
while read line
do
# Check for data on this slice
- echo $line | grep "^${_dTag}-part=" >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ echo $line | grep -q "^${_dTag}-part=" 2>/dev/null
+ if [ $? -eq 0 ]
then
FOUNDPARTS="0"
# Found a slice- entry, lets get the slice info
@@ -194,8 +192,8 @@ setup_gpart_partitions()
MNT=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 3`
# Check if we have a .eli extension on this FS
- echo ${FS} | grep ".eli" >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ echo ${FS} | grep -q ".eli" 2>/dev/null
+ if [ $? -eq 0 ]
then
FS="`echo ${FS} | cut -d '.' -f 1`"
ENC="ON"
@@ -210,9 +208,9 @@ setup_gpart_partitions()
# Check if the user tried to setup / as an encrypted partition
check_for_mount "${MNT}" "/"
- if [ "${?}" = "0" -a "${ENC}" = "ON" ]
+ if [ $? -eq 0 -a "${ENC}" = "ON" ]
then
- USINGENCROOT="0" ; export USINGENCROOT
+ export USINGENCROOT="0"
fi
# Now check that these values are sane
@@ -223,13 +221,13 @@ setup_gpart_partitions()
# Check that we have a valid size number
expr $SIZE + 1 >/dev/null 2>/dev/null
- if [ "$?" != "0" ]; then
+ if [ $? -ne 0 ]; then
exit_err "ERROR: The size specified on $line is invalid"
fi
# Check that the mount-point starts with /
- echo "$MNT" | grep -e "^/" -e "^none" >/dev/null 2>/dev/null
- if [ "$?" != "0" ]; then
+ echo "$MNT" | grep -qe "^/" -e "^none" 2>/dev/null
+ if [ $? -ne 0 ]; then
exit_err "ERROR: The mount-point specified on $line is invalid"
fi
@@ -242,19 +240,19 @@ setup_gpart_partitions()
# Check if we found a valid root partition
check_for_mount "${MNT}" "/"
- if [ "${?}" = "0" ] ; then
- FOUNDROOT="1" ; export FOUNDROOT
+ if [ $? -eq 0 ] ; then
+ export FOUNDROOT="1"
if [ "${CURPART}" = "2" -a "$_pType" = "gpt" ] ; then
- FOUNDROOT="0" ; export FOUNDROOT
+ export FOUNDROOT="0"
fi
if [ "${CURPART}" = "1" -a "$_pType" = "mbr" ] ; then
- FOUNDROOT="0" ; export FOUNDROOT
+ export FOUNDROOT="0"
fi
fi
check_for_mount "${MNT}" "/boot"
- if [ "${?}" = "0" ] ; then
- USINGBOOTPART="0" ; export USINGBOOTPART
+ if [ $? -eq 0 ] ; then
+ export USINGBOOTPART="0"
if [ "${CURPART}" != "2" -a "${_pType}" = "gpt" ] ; then
exit_err "/boot partition must be first partition"
fi
@@ -280,8 +278,8 @@ setup_gpart_partitions()
XTRAOPTS="${VAR}"
# Check if using zfs mirror
- echo ${XTRAOPTS} | grep "mirror" >/dev/null 2>/dev/null
- if [ "$?" = "0" ] ; then
+ echo ${XTRAOPTS} | grep -q "mirror" 2>/dev/null
+ if [ $? -eq 0 ] ; then
if [ "${_pType}" = "gpt" ] ; then
XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_pDisk}p${CURPART}")
else
@@ -325,10 +323,10 @@ setup_gpart_partitions()
# Clear out any headers
sleep 2
- dd if=/dev/zero of=${_pDisk}p${CURPART} count=2048 >/dev/null 2>/dev/null
+ dd if=/dev/zero of=${_pDisk}p${CURPART} count=2048 2>/dev/null
# If we have a enc password, save it as well
- if [ ! -z "${ENCPASS}" ] ; then
+ if [ -n "${ENCPASS}" ] ; then
echo "${ENCPASS}" >${PARTDIR}-enc/${_pDisk}p${CURPART}-encpass
fi
else
@@ -336,10 +334,10 @@ setup_gpart_partitions()
echo "${FS}:${MNT}:${ENC}:${PLABEL}:MBR:${XTRAOPTS}:${IMAGE}" >${PARTDIR}/${_wSlice}${PARTLETTER}
# Clear out any headers
sleep 2
- dd if=/dev/zero of=${_wSlice}${PARTLETTER} count=2048 >/dev/null 2>/dev/null
+ dd if=/dev/zero of=${_wSlice}${PARTLETTER} count=2048 2>/dev/null
# If we have a enc password, save it as well
- if [ ! -z "${ENCPASS}" ] ; then
+ if [ -n "${ENCPASS}" ] ; then
echo "${ENCPASS}" >${PARTDIR}-enc/${_wSlice}${PARTLETTER}-encpass
fi
fi
@@ -347,11 +345,11 @@ setup_gpart_partitions()
# Increment our parts counter
if [ "$_pType" = "gpt" ] ; then
- CURPART="`expr ${CURPART} + 1`"
+ CURPART=$((CURPART+1))
# If this is a gpt partition, we can continue and skip the MBR part letter stuff
continue
else
- CURPART="`expr ${CURPART} + 1`"
+ CURPART=$((CURPART+1))
if [ "$CURPART" = "3" ] ; then CURPART="4" ; fi
fi
@@ -370,8 +368,8 @@ setup_gpart_partitions()
fi # End of subsection locating a slice in config
- echo $line | grep "^commitDiskLabel" >/dev/null 2>/dev/null
- if [ "$?" = "0" -a "${FOUNDPARTS}" = "0" ]
+ echo $line | grep -q "^commitDiskLabel" 2>/dev/null
+ if [ $? -eq 0 -a "${FOUNDPARTS}" = "0" ]
then
# If this is the boot disk, stamp the right gptboot
@@ -455,20 +453,17 @@ setup_disk_label()
done
# Setup some files which we'll be referring to
- LABELLIST="${TMPDIR}/workingLabels"
- export LABELLIST
+ export LABELLIST="${TMPDIR}/workingLabels"
rm $LABELLIST >/dev/null 2>/dev/null
# Set our flag to determine if we've got a valid root partition in this setup
- FOUNDROOT="-1"
- export FOUNDROOT
+ export FOUNDROOT="-1"
# Check if we are using a /boot partition
- USINGBOOTPART="1"
- export USINGBOOTPART
+ export USINGBOOTPART="1"
# Set encryption on root check
- USINGENCROOT="1" ; export USINGENCROOT
+ export USINGENCROOT="1"
# Make the tmp directory where we'll store FS info & mount-points
rm -rf ${PARTDIR} >/dev/null 2>/dev/null
@@ -516,8 +511,8 @@ check_fstab_mbr()
then
PARTLETTER=`echo "$SLICE" | sed -E 's|^.+([a-h])$|\1|'`
- cat "${FSTAB}" | awk '{ print $2 }' | grep -E '^/$' >/dev/null 2>&1
- if [ "$?" = "0" ]
+ cat "${FSTAB}" | awk '{ print $2 }' | grep -qE '^/$' 2>&1
+ if [ $? -eq 0 ]
then
if [ "${PARTLETTER}" = "a" ]
then
@@ -532,8 +527,8 @@ check_fstab_mbr()
export ROOTIMAGE
fi
- cat "${FSTAB}" | awk '{ print $2 }' | grep -E '^/boot$' >/dev/null 2>&1
- if [ "$?" = "0" ]
+ cat "${FSTAB}" | awk '{ print $2 }' | grep -qE '^/boot$' 2>&1
+ if [ $? -eq 0 ]
then
if [ "${PARTLETTER}" = "a" ]
then
@@ -567,8 +562,8 @@ check_fstab_gpt()
then
PARTNUMBER=`echo "${SLICE}" | sed -E 's|^.+p([0-9]*)$|\1|'`
- cat "${FSTAB}" | awk '{ print $2 }' | grep -E '^/$' >/dev/null 2>&1
- if [ "$?" = "0" ]
+ cat "${FSTAB}" | awk '{ print $2 }' | grep -qE '^/$' 2>&1
+ if [ $? -eq 0 ]
then
if [ "${PARTNUMBER}" = "2" ]
then
@@ -583,8 +578,8 @@ check_fstab_gpt()
export ROOTIMAGE
fi
- cat "${FSTAB}" | awk '{ print $2 }' | grep -E '^/boot$' >/dev/null 2>&1
- if [ "$?" = "0" ]
+ cat "${FSTAB}" | awk '{ print $2 }' | grep -qE '^/boot$' 2>&1
+ if [ $? -eq 0 ]
then
if [ "${PARTNUMBER}" = "2" ]
then
@@ -645,7 +640,7 @@ check_disk_layout()
do
F=1
mount ${slice} /mnt 2>/dev/null
- if [ "$?" != "0" ]
+ if [ $? -ne 0 ]
then
continue
fi
@@ -661,7 +656,7 @@ check_disk_layout()
F="$?"
fi
- if [ "${F}" = "0" ]
+ if [ ${F} -eq 0 ]
then
umount /mnt
break
Modified: head/usr.sbin/pc-sysinstall/backend/functions-cleanup.sh
==============================================================================
--- head/usr.sbin/pc-sysinstall/backend/functions-cleanup.sh Sun Mar 27 16:18:51 2011 (r220058)
+++ head/usr.sbin/pc-sysinstall/backend/functions-cleanup.sh Sun Mar 27 16:57:54 2011 (r220059)
@@ -46,27 +46,27 @@ zfs_cleanup_unmount()
then
# Make sure we haven't already added the zfs boot line when
# Creating a dedicated "/boot" partition
- cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep "vfs.root.mountfrom=" >/dev/null 2>/dev/null
- if [ "$?" != "0" ] ; then
+ cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep -q "vfs.root.mountfrom=" 2>/dev/null
+ if [ $? -ne 0 ] ; then
echo "vfs.root.mountfrom=\"zfs:${ZPOOLNAME}\"" >> ${FSMNT}/boot/loader.conf
fi
- FOUNDZFSROOT="${ZPOOLNAME}" ; export FOUNDZFSROOT
+ export FOUNDZFSROOT="${ZPOOLNAME}"
fi
done
FOUNDZFS="1"
fi
done
- if [ ! -z "${FOUNDZFS}" ]
+ if [ -n "${FOUNDZFS}" ]
then
# Check if we need to add our ZFS flags to rc.conf, src.conf and loader.conf
- cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep 'zfs_load="YES"' >/dev/null 2>/dev/null
- if [ "$?" != "0" ]
+ cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep -q 'zfs_load="YES"' 2>/dev/null
+ if [ $? -ne 0 ]
then
echo 'zfs_load="YES"' >>${FSMNT}/boot/loader.conf
fi
- cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep 'zfs_enable="YES"' >/dev/null 2>/dev/null
- if [ "$?" != "0" ]
+ cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q 'zfs_enable="YES"' 2>/dev/null
+ if [ $? -ne 0 ]
then
echo 'zfs_enable="YES"' >>${FSMNT}/etc/rc.conf
fi
@@ -172,7 +172,7 @@ setup_fstab()
# Figure out if we are using a glabel, or the raw name for this entry
- if [ ! -z "${PARTLABEL}" ]
+ if [ -n "${PARTLABEL}" ]
then
DEVICE="label/${PARTLABEL}"
else
@@ -190,7 +190,7 @@ setup_fstab()
# Set our ROOTFSTYPE for loader.conf if necessary
check_for_mount "${PARTMNT}" "/"
- if [ "$?" = "0" ] ; then
+ if [ $? -eq 0 ] ; then
if [ "${PARTFS}" = "ZFS" ] ; then
ROOTFSTYPE="zfs"
XPOOLNAME=$(get_zpool_name "${PART}")
@@ -263,12 +263,12 @@ setup_gmirror()
sleep 3
- NUM="`expr ${NUM} + 1`"
+ NUM=$((NUM+1))
done
- cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep 'geom_mirror_load="YES"' >/dev/null 2>/dev/null
- if [ "$?" != "0" ]
+ cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep -q 'geom_mirror_load="YES"' 2>/dev/null
+ if [ $? -ne 0 ]
then
echo 'geom_mirror_load="YES"' >>${FSMNT}/boot/loader.conf
fi
@@ -304,8 +304,8 @@ setup_geli_loading()
done
# Make sure we have geom_eli set to load at boot
- cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep 'geom_eli_load="YES"' >/dev/null 2>/dev/null
- if [ "$?" != "0" ]
+ cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep -q 'geom_eli_load="YES"' 2>/dev/null
+ if [ $? -ne 0 ]
then
echo 'geom_eli_load="YES"' >>${FSMNT}/boot/loader.conf
fi
@@ -360,8 +360,8 @@ setup_gjournal()
{
# Make sure we have geom_journal set to load at boot
- cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep 'geom_journal_load="YES"' >/dev/null 2>/dev/null
- if [ "$?" != "0" ]
+ cat ${FSMNT}/boot/loader.conf 2>/dev/null | grep -q 'geom_journal_load="YES"' 2>/dev/null
+ if [ $? -ne 0 ]
then
echo 'geom_journal_load="YES"' >>${FSMNT}/boot/loader.conf
fi
@@ -385,14 +385,14 @@ set_root_pw()
echo_log "Setting root password"
# Check if setting plaintext password
- if [ ! -z "${PW}" ] ; then
+ if [ -n "${PW}" ] ; then
echo "${PW}" > ${FSMNT}/.rootpw
run_chroot_cmd "cat /.rootpw | pw usermod root -h 0"
rc_halt "rm ${FSMNT}/.rootpw"
fi
# Check if setting encrypted password
- if [ ! -z "${ENCPW}" ] ; then
+ if [ -n "${ENCPW}" ] ; then
echo "${ENCPW}" > ${FSMNT}/.rootpw
run_chroot_cmd "cat /.rootpw | pw usermod root -H 0"
rc_halt "rm ${FSMNT}/.rootpw"
@@ -405,7 +405,7 @@ run_final_cleanup()
{
# Check if we need to run any gmirror setup
ls ${MIRRORCFGDIR}/* >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ if [ $? -eq 0 ]
then
# Lets setup gmirror now
setup_gmirror
@@ -413,7 +413,7 @@ run_final_cleanup()
# Check if we need to save any geli keys
ls ${GELIKEYDIR}/* >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ if [ $? -eq 0 ]
then
# Lets setup geli loading
setup_geli_loading
Modified: head/usr.sbin/pc-sysinstall/backend/functions-disk.sh
==============================================================================
--- head/usr.sbin/pc-sysinstall/backend/functions-disk.sh Sun Mar 27 16:18:51 2011 (r220058)
+++ head/usr.sbin/pc-sysinstall/backend/functions-disk.sh Sun Mar 27 16:57:54 2011 (r220059)
@@ -32,7 +32,7 @@ is_disk()
{
for _dsk in `sysctl -n kern.disks`
do
- if [ "$_dsk" = "${1}" ] ; then return 0 ; fi
+ [ "$_dsk" = "${1}" ] && return 0
done
return 1
@@ -47,8 +47,8 @@ get_partition_sysid_mbr()
fdisk ${DISK} >${TMPDIR}/disk-${DISK} 2>/dev/null
while read i
do
- echo "$i" | grep "The data for partition" >/dev/null 2>/dev/null
- if [ "$?" = "0" ] ; then
+ echo "$i" | grep -q "The data for partition" 2>/dev/null
+ if [ $? -eq 0 ] ; then
INPART="0"
PART="`echo ${i} | cut -d ' ' -f 5`"
if [ "$PART" = "$PARTNUM" ] ; then
@@ -58,8 +58,8 @@ get_partition_sysid_mbr()
# In the partition section
if [ "$INPART" = "1" ] ; then
- echo "$i" | grep "^sysid" >/dev/null 2>/dev/null
- if [ "$?" = "0" ] ; then
+ echo "$i" | grep -q "^sysid" 2>/dev/null
+ if [ $? -eq 0 ] ; then
SYSID="`echo ${i} | tr -s '\t' ' ' | cut -d ' ' -f 2`"
break
fi
@@ -69,8 +69,7 @@ get_partition_sysid_mbr()
done < ${TMPDIR}/disk-${DISK}
rm ${TMPDIR}/disk-${DISK}
- VAL="${SYSID}"
- export VAL
+ export VAL="${SYSID}"
};
# Get the partitions MBR label
@@ -82,8 +81,8 @@ get_partition_label_mbr()
fdisk ${DISK} >${TMPDIR}/disk-${DISK} 2>/dev/null
while read i
do
- echo "$i" | grep "The data for partition" >/dev/null 2>/dev/null
- if [ "$?" = "0" ] ; then
+ echo "$i" | grep -q "The data for partition" 2>/dev/null
+ if [ $? -eq 0 ] ; then
INPART="0"
PART="`echo ${i} | cut -d ' ' -f 5`"
if [ "$PART" = "$PARTNUM" ] ; then
@@ -93,8 +92,8 @@ get_partition_label_mbr()
# In the partition section
if [ "$INPART" = "1" ] ; then
- echo "$i" | grep "^sysid" >/dev/null 2>/dev/null
- if [ "$?" = "0" ] ; then
+ echo "$i" | grep -q "^sysid" 2>/dev/null
+ if [ $? -eq 0 ] ; then
LABEL="`echo ${i} | tr -s '\t' ' ' | cut -d ',' -f 2-10`"
break
fi
@@ -104,8 +103,7 @@ get_partition_label_mbr()
done < ${TMPDIR}/disk-${DISK}
rm ${TMPDIR}/disk-${DISK}
- VAL="${LABEL}"
- export VAL
+ export VAL="${LABEL}"
};
# Get a GPT partitions label
@@ -125,8 +123,7 @@ get_partition_label_gpt()
done <${TMPDIR}/disk-${DISK}
rm ${TMPDIR}/disk-${DISK}
- VAL="${LABEL}"
- export VAL
+ export VAL="${LABEL}"
};
# Get a partitions startblock
@@ -146,8 +143,7 @@ get_partition_startblock()
done <${TMPDIR}/disk-${DISK}
rm ${TMPDIR}/disk-${DISK}
- VAL="${SB}"
- export VAL
+ export VAL="${SB}"
};
# Get a partitions blocksize
@@ -167,16 +163,15 @@ get_partition_blocksize()
done <${TMPDIR}/disk-${DISK}
rm ${TMPDIR}/disk-${DISK}
- VAL="${BS}"
- export VAL
+ export VAL="${BS}"
};
# Function which returns the partitions on a target disk
get_disk_partitions()
{
gpart show ${1} >/dev/null 2>/dev/null
- if [ "$?" != "0" ] ; then
- VAL="" ; export VAL
+ if [ $? -ne 0 ] ; then
+ export VAL=""
return
fi
@@ -198,35 +193,35 @@ get_disk_partitions()
fi
done
- VAL="${RSLICES}" ; export VAL
+ export VAL="${RSLICES}"
};
# Function which returns a target disks cylinders
get_disk_cyl()
{
cyl=`diskinfo -v ${1} | grep "# Cylinders" | tr -s ' ' | cut -f 2`
- VAL="${cyl}" ; export VAL
+ export VAL="${cyl}"
};
# Function which returns a target disks sectors
get_disk_sectors()
{
sec=`diskinfo -v ${1} | grep "# Sectors" | tr -s ' ' | cut -f 2`
- VAL="${sec}" ; export VAL
+ export VAL="${sec}"
};
# Function which returns a target disks heads
get_disk_heads()
{
head=`diskinfo -v ${1} | grep "# Heads" | tr -s ' ' | cut -f 2`
- VAL="${head}" ; export VAL
+ export VAL="${head}"
};
# Function which returns a target disks mediasize in sectors
get_disk_mediasize()
{
mediasize=`diskinfo -v ${1} | grep "# mediasize in sectors" | tr -s ' ' | cut -f 2`
- VAL="${mediasize}" ; export VAL
+ export VAL="${mediasize}"
};
# Function which exports all zpools, making them safe to overwrite potentially
@@ -288,8 +283,8 @@ stop_all_gmirror()
GPROV="`gmirror list | grep ". Name: mirror/" | cut -d '/' -f 2`"
for gprov in $GPROV
do
- gmirror list | grep "Name: ${DISK}" >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ gmirror list | grep -q "Name: ${DISK}" 2>/dev/null
+ if [ $? -eq 0 ]
then
echo_log "Stopping mirror $gprov $DISK"
rc_nohalt "gmirror remove $gprov $DISK"
@@ -306,8 +301,8 @@ stop_all_geli()
for i in `ls ${_geld}*`
do
- echo $i | grep '.eli' >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ echo $i | grep -q '.eli' 2>/dev/null
+ if [ $? -eq 0 ]
then
echo_log "Detaching GELI on ${i}"
rc_halt "geli detach ${i}"
@@ -335,8 +330,8 @@ setup_disk_slice()
# We are ready to start setting up the disks, lets read the config and do the actions
while read line
do
- echo $line | grep "^disk${disknum}=" >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ echo $line | grep -q "^disk${disknum}=" 2>/dev/null
+ if [ $? -eq 0 ]
then
# Found a disk= entry, lets get the disk we are working on
@@ -362,8 +357,8 @@ setup_disk_slice()
fi
# Lets look if this device will be mirrored on another disk
- echo $line | grep "^mirror=" >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ echo $line | grep -q "^mirror=" 2>/dev/null
+ if [ $? -eq 0 ]
then
# Found a disk= entry, lets get the disk we are working on
@@ -379,8 +374,8 @@ setup_disk_slice()
fi
# Lets see if we have been given a mirror balance choice
- echo $line | grep "^mirrorbal=" >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ echo $line | grep -q "^mirrorbal=" 2>/dev/null
+ if [ $? -eq 0 ]
then
# Found a disk= entry, lets get the disk we are working on
@@ -389,8 +384,8 @@ setup_disk_slice()
MIRRORBAL="$VAL"
fi
- echo $line | grep "^partition=" >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ echo $line | grep -q "^partition=" 2>/dev/null
+ if [ $? -eq 0 ]
then
# Found a partition= entry, lets read / set it
get_value_from_string "${line}"
@@ -413,7 +408,7 @@ setup_disk_slice()
then
LASTSLICE="1"
else
- LASTSLICE="`expr $LASTSLICE + 1`"
+ LASTSLICE=$((LASTSLICE+1))
fi
if [ $LASTSLICE -gt 4 ]
@@ -425,8 +420,8 @@ setup_disk_slice()
fi
# Check if we have an image file defined
- echo $line | grep "^image=" >/dev/null 2>/dev/null
- if [ "$?" = "0" ] ; then
+ echo $line | grep -q "^image=" 2>/dev/null
+ if [ $? eq 0 ] ; then
# Found an image= entry, lets read / set it
get_value_from_string "${line}"
strip_white_space "$VAL"
@@ -437,8 +432,8 @@ setup_disk_slice()
fi
# Check if we have a partscheme specified
- echo $line | grep "^partscheme=" >/dev/null 2>/dev/null
- if [ "$?" = "0" ] ; then
+ echo $line | grep -q "^partscheme=" 2>/dev/null
+ if [ $? -eq 0 ] ; then
# Found a partscheme= entry, lets read / set it
get_value_from_string "${line}"
strip_white_space "$VAL"
@@ -448,8 +443,8 @@ setup_disk_slice()
fi
fi
- echo $line | grep "^bootManager=" >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ echo $line | grep -q "^bootManager=" 2>/dev/null
+ if [ $? -eq 0 ]
then
# Found a bootManager= entry, lets read /set it
get_value_from_string "${line}"
@@ -457,8 +452,8 @@ setup_disk_slice()
BMANAGER="$VAL"
fi
- echo $line | grep "^commitDiskPart" >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ echo $line | grep -q "^commitDiskPart" 2>/dev/null
+ if [ $? -eq 0 ]
then
# Found our flag to commit this disk setup / lets do sanity check and do it
if [ ! -z "${DISK}" -a ! -z "${PTYPE}" ]
@@ -520,7 +515,7 @@ setup_disk_slice()
fi
# Save any mirror config
- if [ ! -z "$MIRRORDISK" ]
+ if [ -n "$MIRRORDISK" ]
then
# Default to round-robin if the user didn't specify
if [ -z "$MIRRORBAL" ]
@@ -532,7 +527,7 @@ setup_disk_slice()
# Increment our disk counter to look for next disk and unset
unset BMANAGER PTYPE DISK MIRRORDISK MIRRORBAL PSCHEME IMAGE
- disknum="`expr $disknum + 1`"
+ disknum=$((disknum+1))
else
exit_err "ERROR: commitDiskPart was called without procceding disk<num>= and partition= entries!!!"
fi
@@ -548,7 +543,7 @@ stop_gjournal()
_gdsk="$1"
# Check if we need to shutdown any journals on this drive
ls /dev/${_gdsk}*.journal >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ if [ $? -eq 0 ]
then
cd /dev
for i in `ls ${_gdsk}*.journal`
@@ -569,7 +564,7 @@ clear_backup_gpt_table()
# Make sure this is a valid number
is_num "${dSize}" >/dev/null 2>/dev/null
- if [ "$?" != "0" ] ; then return ; fi
+ [ $? -ne 0 ] && return
# Die backup label, DIE
echo_log "Clearing gpt backup table location on disk"
@@ -697,7 +692,7 @@ run_gpart_full()
run_gpart_slice()
{
DISK=$1
- if [ ! -z "$2" ]
+ if [ -n "$2" ]
then
BMANAGER="$2"
fi
@@ -757,7 +752,7 @@ run_gpart_free()
{
DISK=$1
SLICENUM=$2
- if [ ! -z "$3" ]
+ if [ -n "$3" ]
then
BMANAGER="$3"
fi
@@ -770,7 +765,7 @@ run_gpart_free()
# Working on the first slice, make sure we have MBR setup
gpart show ${DISK} >/dev/null 2>/dev/null
- if [ "$?" != "0" -a "$SLICENUM" = "1" ] ; then
+ if [ $? -ne 0 -a "$SLICENUM" = "1" ] ; then
echo_log "Initializing disk, no existing MBR setup"
rc_halt "gpart create -s mbr ${DISK}"
fi
@@ -781,12 +776,12 @@ run_gpart_free()
startblock="63"
else
# Lets figure out where the prior slice ends
- checkslice="`expr ${slicenum} - 1`"
+ checkslice=$((slicenum-1))
# Get starting block of this slice
sblk=`gpart show ${DISK} | grep -v ${DISK} | tr -s '\t' ' ' | sed '/^$/d' | grep " ${checkslice} " | cut -d ' ' -f 2`
blksize=`gpart show ${DISK} | grep -v ${DISK} | tr -s '\t' ' ' | sed '/^$/d' | grep " ${checkslice} " | cut -d ' ' -f 3`
- startblock="`expr ${sblk} + ${blksize}`"
+ startblock=$((sblk+blksiz))
fi
# No slice after the new slice, lets figure out the free space remaining and use it
@@ -803,12 +798,12 @@ run_gpart_free()
sec="${VAL}"
# Multiply them all together to get our total blocks
- totalblocks="`expr ${cyl} \* ${head}`"
- totalblocks="`expr ${totalblocks} \* ${sec}`"
+ totalblocks=$((cyl*head))
+ totalblocks=$((totalblocks*sec))
# Now set the ending block to the total disk block size
- sizeblock="`expr ${totalblocks} - ${startblock}`"
+ sizeblock=$((totalblocks-startblock))
# Install new partition setup
echo_log "Running gpart on ${DISK}"
Modified: head/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh
==============================================================================
--- head/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh Sun Mar 27 16:18:51 2011 (r220058)
+++ head/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh Sun Mar 27 16:57:54 2011 (r220059)
@@ -59,7 +59,7 @@ start_extract_uzip_tar()
MDDEVICE=`mdconfig -a -t vnode -o readonly -f ${INSFILE}`
mkdir -p ${FSMNT}.uzip
mount -r /dev/${MDDEVICE}.uzip ${FSMNT}.uzip
- if [ "$?" != "0" ]
+ if [ $? -ne 0 ]
then
exit_err "ERROR: Failed mounting the ${INSFILE}"
fi
@@ -67,7 +67,7 @@ start_extract_uzip_tar()
# Copy over all the files now!
tar cvf - . 2>/dev/null | tar -xpv -C ${FSMNT} ${TAROPTS} -f - 2>&1 | tee -a ${FSMNT}/.tar-extract.log
- if [ "$?" != "0" ]
+ if [ $? -ne 0 ]
then
cd /
echo "TAR failure occurred:" >>${LOGOUT}
@@ -84,7 +84,7 @@ start_extract_uzip_tar()
;;
tar)
tar -xpv -C ${FSMNT} -f ${INSFILE} ${TAROPTS} >&1 2>&1
- if [ "$?" != "0" ]
+ if [ $? -ne 0 ]
then
exit_err "ERROR: Failed extracting the tar image"
fi
@@ -127,7 +127,7 @@ start_extract_split()
then
echo_log "Extracting" `basename ${dir}`
echo "y" | sh install.sh >/dev/null
- if [ "$?" != "0" ]
+ if [ $? -ne 0 ]
then
exit_err "ERROR: Failed extracting ${dir}"
fi
@@ -143,7 +143,7 @@ start_extract_split()
then
echo_log "Extracting" `basename ${KERNELS}`
echo "y" | sh install.sh generic >/dev/null
- if [ "$?" != "0" ]
+ if [ $? -ne 0 ]
then
exit_err "ERROR: Failed extracting ${KERNELS}"
fi
@@ -160,7 +160,7 @@ start_extract_split()
then
echo_log "Extracting" `basename ${SOURCE}`
echo "y" | sh install.sh all >/dev/null
- if [ "$?" != "0" ]
+ if [ $? -ne 0 ]
then
exit_err "ERROR: Failed extracting ${SOURCE}"
fi
@@ -202,7 +202,7 @@ fetch_install_file()
fetch_file "${FTPPATH}/${INSFILE}.md5" "${OUTFILE}.md5" "0"
# Done fetching, now reset the INSFILE to our downloaded archived
- INSFILE="${OUTFILE}" ; export INSFILE
+ export INSFILE="${OUTFILE}"
};
@@ -244,7 +244,7 @@ fetch_split_files()
NETRC="${OUTFILE}/.netrc"
- cat<<EOF>"${NETRC}"
+ cat <<EOF >"${NETRC}"
machine ${FTPHOST}
login anonymous
password anonymous
@@ -255,14 +255,14 @@ EOF
for d in ${DIRS}
do
- cat<<EOF>>"${NETRC}"
+ cat <<EOF >>"${NETRC}"
cd ${FTPDIR}/${d}
lcd ${OUTFILE}/${d}
mreget *
EOF
done
- cat<<EOF>>"${NETRC}"
+ cat <<EOF >>"${NETRC}"
bye
@@ -272,7 +272,7 @@ EOF
echo "$ INSTALL" | ftp -N "${NETRC}" "${FTPHOST}"
# Done fetching, now reset the INSFILE to our downloaded archived
- INSFILE="${OUTFILE}" ; export INSFILE
+ export INSFILE="${OUTFILE}"
}
# Function which does the rsync download from the server specified in cfg
@@ -283,27 +283,27 @@ start_rsync_copy()
if [ -z "${VAL}" ]; then
exit_err "ERROR: rsyncPath is unset! Please check your config and try again."
fi
- RSYNCPATH="${VAL}" ; export RSYNCPATH
+ export RSYNCPATH="${VAL}"
get_value_from_cfg rsyncHost
if [ -z "${VAL}" ]; then
exit_err "ERROR: rsyncHost is unset! Please check your config and try again."
fi
- RSYNCHOST="${VAL}" ; export RSYNCHOST
+ export RSYNCHOST="${VAL}"
get_value_from_cfg rsyncUser
if [ -z "${VAL}" ]; then
exit_err "ERROR: rsyncUser is unset! Please check your config and try again."
fi
- RSYNCUSER="${VAL}" ; export RSYNCUSER
+ export RSYNCUSER="${VAL}"
get_value_from_cfg rsyncPort
if [ -z "${VAL}" ]; then
exit_err "ERROR: rsyncPort is unset! Please check your config and try again."
fi
- RSYNCPORT="${VAL}" ; export RSYNCPORT
+ export RSYNCPORT="${VAL}"
- COUNT="1"
+ COUNT=1
while
z=1
do
@@ -317,14 +317,14 @@ start_rsync_copy()
--rsync-path="rsync --fake-super" \
-e "ssh -p ${RSYNCPORT}" \
${RSYNCUSER}@${RSYNCHOST}:${RSYNCPATH}/./ ${FSMNT}
- if [ "$?" != "0" ]
+ if [ $? -ne 0 ]
then
echo "Rsync failed! Tries: ${COUNT}"
else
break
fi
- COUNT="`expr ${COUNT} + 1`"
+ COUNT=$((COUNT+1))
done
};
@@ -339,8 +339,8 @@ start_image_install()
# We are ready to start mounting, lets read the config and do it
while read line
do
- echo $line | grep "^disk0=" >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ echo $line | grep -q "^disk0=" 2>/dev/null
+ if [ $? -eq 0 ]
then
# Found a disk= entry, lets get the disk we are working on
get_value_from_string "${line}"
@@ -348,11 +348,11 @@ start_image_install()
DISK="$VAL"
fi
- echo $line | grep "^commitDiskPart" >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
+ echo $line | grep -q "^commitDiskPart" 2>/dev/null
+ if [ $? -eq 0 ]
then
# Found our flag to commit this disk setup / lets do sanity check and do it
- if [ ! -z "${DISK}" ]
+ if [ -n "${DISK}" ]
then
# Write the image
@@ -376,9 +376,9 @@ init_extraction()
# Figure out what file we are using to install from via the config
get_value_from_cfg installFile
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-all
mailing list