From fcba9d41e3a27913fec69ed949a09e62ca530092 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Thu, 10 Jan 2019 09:58:17 +0800 Subject: Better handle the argument of specifying the image file --- dfly-update | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/dfly-update b/dfly-update index a0827e1..f248916 100755 --- a/dfly-update +++ b/dfly-update @@ -409,8 +409,9 @@ usage() { cat <<_EOF_ Upgrade a DragonFly BSD system using a binary release/snapshot -Usage: ${0##*/} [-h] [-c ] [-d] - [-s ] [-S +Usage: +${0##*/} [-h] [-c ] [-d] + [-s ] [-S is 0 (the default), +otherwise it is assumed that the image file is already mounted +at \${MNT_DIR} (default to be '${MNT_DIR}'). + v${VERSION} ${AUTHOR} ${URL} @@ -478,14 +484,20 @@ while getopts :c:dhs:S: opt; do done shift $((OPTIND - 1)) -[ $# -ne 1 ] && { usage; exit ${EC_ARGS}; } -IMGFILE="$1" -[ -r "${IMGFILE}" ] || error ${EC_NOFILE} "file not exists: ${IMGFILE}" + +if [ ${ISTART} -eq 0 ]; then + [ $# -eq 1 ] || error ${EC_ARGS} "no image file provided" + IMG="$1" + [ -f "${IMG}" ] || error ${EC_NOFILE} "image file not exists: ${IMG}" +else + DEV=$(get_mount_dev ${MNT_DIR}) + [ -n "${DEV}" ] || error ${EC_MOUNT} "nothing mounted at: ${MNT_DIR}" +fi istep=0 -echo "[${istep}] Mounting image ${IMGFILE} to ${MNT_DIR} ..." +echo "[${istep}] Mounting image to ${MNT_DIR} ..." [ ${istep} -ge ${ISTART} -a ${istep} -le ${ISTOP} ] && - mount_image "${IMGFILE}" "${MNT_DIR}" || + mount_image "${IMG}" "${MNT_DIR}" || echo "(skipped)" istep=$((${istep} + 1)) -- cgit v1.2.2