test -n "${DEST}" || DEST="${DEFAULT_DEST}"
sdb -s "${ID}" push "${FILE}" "${DEST}" || die "SDB copy failed!"
}
+
+wait_sdb() {
+ SDMUX="$1"
+ test -n "${SDMUX}" || die "Missing argument: sdmux"
+ test -n "${INIT_SLEEP}" || die "Missing env: init_sleep"
+
+ CONNECT_CNT=0
+ sdb start-server >&2
+ SLEEP=${INIT_SLEEP}
+
+ sleep "${SLEEP}"
+
+ while [ -z "$(sdb devices | awk -v SDMUX="${SDMUX}" '$1 == SDMUX {print $1}')" ]
+ do
+ printf "." >&2
+ if [ ${SLEEP} -ge ${MAX_SLEEP} ]
+ then
+ die "Timeout: sdb device not found!"
+ fi
+ if [ ${SLEEP} -ge ${RESTART_SLEEP} ]
+ then
+ echo "Restarting ${SDMUX}" >&2
+ restart_device "${SDMUX}"
+ fi
+ sleep "${SLEEP}"
+ SLEEP=$((SLEEP+INC_SLEEP))
+ CONNECT_CNT=$((CONNECT_CNT+1))
+ done
+
+ echo "${CONNECT_CNT}"
+}
echo "### conf ###"
-CONNECT_CNT=0
-sdb start-server
-SLEEP=${INIT_SLEEP}
-
-sleep "${SLEEP}"
-
-while [ -z "$(sdb devices | awk -v SDMUX="${SDMUX}" '$1 == SDMUX {print $1}')" ]
-do
- printf "."
- if [ ${SLEEP} -ge ${MAX_SLEEP} ]
- then
- die "Timeout: sdb device not found!" >&2
- fi
- if [ ${SLEEP} -ge ${RESTART_SLEEP} ]
- then
- echo "Restarting ODROID" >&2
- restart_device "${SDMUX}"
- fi
- sleep "${SLEEP}"
- SLEEP=$((SLEEP+INC_SLEEP))
- CONNECT_CNT=$((CONNECT_CNT+1))
-done
+CONNECT_CNT="$(wait_sdb "${SDMUX}")" || die "wait_sdb: failed!"
printf "\n"
sleep 4