aboutsummaryrefslogtreecommitdiffstats
path: root/mount-from-config.sh
diff options
context:
space:
mode:
authorclifforama <clifforama@users.noreply.github.com>2021-11-03 16:26:40 -0400
committerclifforama <clifforama@users.noreply.github.com>2021-11-03 16:26:40 -0400
commit36a1d9a55459f65740f7f39582b753339efc17dc (patch)
tree6f7eb462cf66a2cbcebb35dedf680a3e09d30d9a /mount-from-config.sh
downloadmulti-mount-36a1d9a55459f65740f7f39582b753339efc17dc.tar.gz
Initial commit
Diffstat (limited to 'mount-from-config.sh')
-rw-r--r--mount-from-config.sh38
1 files changed, 38 insertions, 0 deletions
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