aboutsummaryrefslogtreecommitdiffstats
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
downloadmulti-mount-36a1d9a55459f65740f7f39582b753339efc17dc.tar.gz
Initial commit
-rw-r--r--META-INF/com/google/android/update-binary33
-rw-r--r--META-INF/com/google/android/updater-script1
-rw-r--r--README.md47
-rw-r--r--cifs-sample.conf5
-rw-r--r--customize.sh2
-rw-r--r--module.prop6
-rw-r--r--mount-from-config.sh38
-rw-r--r--service.sh41
8 files changed, 173 insertions, 0 deletions
diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary
new file mode 100644
index 0000000..28b48e5
--- /dev/null
+++ b/META-INF/com/google/android/update-binary
@@ -0,0 +1,33 @@
+#!/sbin/sh
+
+#################
+# Initialization
+#################
+
+umask 022
+
+# echo before loading util_functions
+ui_print() { echo "$1"; }
+
+require_new_magisk() {
+ ui_print "*******************************"
+ ui_print " Please install Magisk v20.4+! "
+ ui_print "*******************************"
+ exit 1
+}
+
+#########################
+# Load util_functions.sh
+#########################
+
+OUTFD=$2
+ZIPFILE=$3
+
+mount /data 2>/dev/null
+
+[ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk
+. /data/adb/magisk/util_functions.sh
+[ $MAGISK_VER_CODE -lt 20400 ] && require_new_magisk
+
+install_module
+exit 0
diff --git a/META-INF/com/google/android/updater-script b/META-INF/com/google/android/updater-script
new file mode 100644
index 0000000..11d5c96
--- /dev/null
+++ b/META-INF/com/google/android/updater-script
@@ -0,0 +1 @@
+#MAGISK
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..0e56a3d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,47 @@
+# Multi-Mount
+
+## Description
+
+This Magisk module mounts one or more filesystems (e.g. CIFS/SMB, NFS, etc.).
+
+
+
+## Requirements
+
+- Magisk v20.4+
+
+- Kernel support for filesystem(s) to be mounted (hint: `grep cifs /proc/filesystems`)
+
+
+
+## Instructions
+
+1. Create config file(s) with filename(s) ending in `.conf` and place them in `/sdcard/.multi-mount` (i.e. the
+ `.multi-mount` directory resides in the same directory that typically contains DCIM, Documents, Download, etc.). Each
+ config file corresponds to a distinct mount configuration and must adhere to the following example:
+
+ mount_options="-t cifs -o vers=2.0,username=user,password=pass"
+ mount_source="//host/share"
+ mount_target="/mnt/cifs-share"
+ mount_max_retries=20
+ mount_retry_interval=15s
+
+2. Install module via Magisk Manager, then reboot.
+
+
+
+## Notes
+
+- Every distinct mount requires its own config file. E.g. to mount multiple CIFS shares, create multiple config files
+ (e.g. `cifs-1.conf`, `cifs-2.conf`, etc.). Filenames are arbitrary, but must end in `.conf`.
+
+- Config files are read at boot. Reboot for changes to take effect.
+
+- In order to mount a network share, the network must be reachable after boot within the timeframe defined by
+ `mount_max_retries` and `mount_retry_interval`.
+
+- If mounting a CIFS share fails, try specifying a different CIFS version.
+
+- While any filesystem supported by the kernel should work, Multi-Mount has only been tested with CIFS on [KonstaKANG's
+ LineageOS 18.1 Android TV (Android 11) for Raspberry Pi 4](https://konstakang.com/devices/rpi4/LineageOS18-ATV/),
+ release 11.10.
diff --git a/cifs-sample.conf b/cifs-sample.conf
new file mode 100644
index 0000000..86a42be
--- /dev/null
+++ b/cifs-sample.conf
@@ -0,0 +1,5 @@
+mount_options="-t cifs -o vers=2.0,username=user,password=pass"
+mount_source="//host/share"
+mount_target="/mnt/cifs-share"
+mount_max_retries=20
+mount_retry_interval=15s
diff --git a/customize.sh b/customize.sh
new file mode 100644
index 0000000..e6a54f3
--- /dev/null
+++ b/customize.sh
@@ -0,0 +1,2 @@
+set_perm $MODPATH/service.sh 0 0 0755
+set_perm $MODPATH/mount-from-config.sh 0 0 0755 \ No newline at end of file
diff --git a/module.prop b/module.prop
new file mode 100644
index 0000000..44fd98e
--- /dev/null
+++ b/module.prop
@@ -0,0 +1,6 @@
+id=multi-mount
+name=Multi-Mount
+version=v1.0.0
+versionCode=1
+author=clifforama
+description=Mounts one or more filesystems (e.g. CIFS/SMB, NFS, etc.)
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
diff --git a/service.sh b/service.sh
new file mode 100644
index 0000000..4e3e5a6
--- /dev/null
+++ b/service.sh
@@ -0,0 +1,41 @@
+#!/system/bin/sh
+# Do NOT assume where your module will be located.
+# ALWAYS use $MODDIR if you need to know where this script and module is placed.
+# This will make sure your module will still work if Magisk changes its mount point in the future
+MODDIR=${0%/*}
+
+export LOG_FILE="${MODDIR}/multi-mount.log"
+LOG_MAX_LINES=1000
+
+BOOTWAIT_MAX_COUNT=20
+BOOTWAIT_COUNT_INTERVAL=15s
+
+CONF_DIR="/sdcard/.multi-mount"
+CONF_FILESPEC="${CONF_DIR}/*.conf"
+
+# wait for system boot to complete
+bootwait_count=0
+until [[ $(getprop sys.boot_completed) || ${bootwait_count} -ge ${BOOTWAIT_MAX_COUNT} ]]; do
+ sleep ${BOOTWAIT_COUNT_INTERVAL}
+ bootwait_count=$((bootwait_count+1))
+done
+if [ ${bootwait_count} -ge ${BOOTWAIT_MAX_COUNT} ]; then
+ exit 1
+fi
+
+# prevent log file from growing too large
+tail -n "${LOG_MAX_LINES}" "${LOG_FILE}" > "${LOGFILE}.tmp"
+mv "${LOGFILE}.tmp" "${LOG_FILE}"
+
+echo "=== $(date) ===" >> "${LOG_FILE}" 2>&1
+
+# process config files in parallel
+config_file_count=0
+for f in ${CONF_FILESPEC}; do
+ config_file_count=$((config_file_count+1))
+ "${MODDIR}/mount-from-config.sh" "${f}" &
+done
+if [ "${config_file_count}" -eq 0 ]; then
+ echo "No config files found." >> "${LOG_FILE}" 2>&1
+fi
+wait