From 36a1d9a55459f65740f7f39582b753339efc17dc Mon Sep 17 00:00:00 2001 From: clifforama Date: Wed, 3 Nov 2021 16:26:40 -0400 Subject: Initial commit --- mount-from-config.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 mount-from-config.sh (limited to 'mount-from-config.sh') diff --git a/mount-from-config.sh b/mount-from-config.sh new file mode 100644 index 0000000..fc9a2c4 --- /dev/null +++ b/mount-from-config.sh @@ -0,0 +1,38 @@ +#!/system/bin/sh +CONFIG_FILE="$1" +CONFIG_PARAMS="mount_options mount_source mount_target mount_max_retries mount_retry_interval" + +# source user-specified config file +if [ -r "${CONFIG_FILE}" ]; then + . "${CONFIG_FILE}" >> "${LOG_FILE}" 2>&1 + missing_count=0 + for p in ${CONFIG_PARAMS}; do + if [[ -z $(eval "echo \"\$${p}\"") ]]; then + echo "Config file \"${CONFIG_FILE}\" is missing param \"${p}\"." >> "${LOG_FILE}" 2>&1 + missing_count=$((missing_count+1)) + fi + done + if [ ${missing_count} -gt 0 ]; then + exit + fi +else + echo "Unable to read config file \"${CONFIG_FILE}\"." >> "${LOG_FILE}" 2>&1 + exit +fi + +# attempt to mount +mkdir -p "${mount_target}" >> "${LOG_FILE}" 2>&1 +retries=0 +while : ; do + su -c "mount ${mount_options} \"${mount_source}\" \"${mount_target}\"" >> "${LOG_FILE}" 2>&1 + if grep -q "${mount_target}" /proc/mounts; then + echo "Successfully mounted source \"${mount_source}\" at \"${mount_target}\"." >> "${LOG_FILE}" 2>&1 + break + elif [ ${retries} -lt "${mount_max_retries}" ]; then + sleep "${mount_retry_interval}" + retries=$((retries+1)) + else + echo "Failed to mount source \"${mount_source}\" at \"${mount_target}\" after $((retries+1)) attempts (${retries} retries)." >> "${LOG_FILE}" 2>&1 + exit + fi +done -- cgit v1.2.3