From d25d1ac9e53b3333944ef4e18795cf1354c179f0 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Tue, 16 Sep 2025 18:56:22 +0000 Subject: Initial commit --- service.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 service.sh (limited to 'service.sh') diff --git a/service.sh b/service.sh new file mode 100644 index 0000000..37f50dd --- /dev/null +++ b/service.sh @@ -0,0 +1,53 @@ +#!/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}/magisk-fstab.log" +LOG_MAX_LINES=1000 + +BOOTWAIT_MAX_COUNT=20 +BOOTWAIT_COUNT_INTERVAL=15s + +CONF_MAIN="${MODDIR}/config/main.conf" +CONF_FSTAB="${MODDIR}/config/fstab.conf" + +# Check if configs are readable + +if [ ! -r "$CONF_MAIN" ]; then + echo "File '$CONF_MAIN' not readable." + exit 2 +fi + +if [ ! -r "$CONF_FSTAB" ]; then + echo "File '$CONF_FSTAB' not readable." + exit 2 +fi + +# Read main config +. "${CONF_MAIN}" >> "${LOG_FILE}" 2>&1 + +# 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 + +if [ -f "${CONF}" ] + "${MODDIR}/fstab.sh" "${CONF_FSTAB}" & +else + echo "${CONF} not found." >> "${LOG_FILE}" 2>&1 +fi + +wait -- cgit v1.2.3