From 9b9f22a7faf78882576270e1a99577e3e7828fb9 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Thu, 10 Jan 2019 09:56:56 +0800 Subject: Clean up the config file loading code Adjust the whitespace style in the meantime. --- dfly-update | 72 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/dfly-update b/dfly-update index 8d37772..a0827e1 100755 --- a/dfly-update +++ b/dfly-update @@ -438,39 +438,43 @@ _EOF_ } -CONFIGFILE="" ISTART=0 -ISTOP=999 +ISTOP=99 while getopts :c:dhs:S: opt; do - case ${opt} in - c) - CONFIGFILE="${OPTARG}" - ;; - d) - DEBUG=yes - ;; - h) - usage - exit ${EC_USAGE} - ;; - s) - ISTART="${OPTARG}" - ;; - S) - ISTOP="${OPTARG}" - ;; - \?) - log "Invalid option -${OPTARG}" - usage - exit ${EC_ARGS} - ;; - :) - log "Option -${OPTARG} requires an argument" - usage - exit ${EC_ARGS} - ;; - esac + case ${opt} in + c) + CONFIGFILE="${OPTARG}" + if [ -r "${CONFIGFILE}" ]; then + . ${CONFIGFILE} + else + error ${EC_CONFIG} "cannot read config file: ${CONFIGFILE}" + fi + ;; + d) + DEBUG=yes + ;; + h) + usage + exit ${EC_USAGE} + ;; + s) + ISTART="${OPTARG}" + ;; + S) + ISTOP="${OPTARG}" + ;; + \?) + log "Invalid option -${OPTARG}" + usage + exit ${EC_ARGS} + ;; + :) + log "Option -${OPTARG} requires an argument" + usage + exit ${EC_ARGS} + ;; + esac done shift $((OPTIND - 1)) @@ -478,14 +482,6 @@ shift $((OPTIND - 1)) IMGFILE="$1" [ -r "${IMGFILE}" ] || error ${EC_NOFILE} "file not exists: ${IMGFILE}" -if [ -n "${CONFIGFILE}" ]; then - if [ -r "${CONFIGFILE}" ]; then - . ${CONFIGFILE} - else - error ${EC_CONFIG} "cannot read config file: ${CONFIGFILE}" - fi -fi - istep=0 echo "[${istep}] Mounting image ${IMGFILE} to ${MNT_DIR} ..." [ ${istep} -ge ${ISTART} -a ${istep} -le ${ISTOP} ] && -- cgit v1.2.2