From 3db94314a0af7f3bb691a147a540455abbb60fea Mon Sep 17 00:00:00 2001 From: chickendrop89 Date: Mon, 2 Dec 2024 18:53:56 +0100 Subject: [PATCH] mss: treewide: add a solution to hard-coded paths * A modpath defined by magisk itself will be injected on top of our binary and common scripts * This way we can avoid hard-coding paths and thus, potentional breaking changes to the magisk module structure in the future Signed-off-by: chickendrop89 --- common.sh | 1 - common/install.sh | 12 ++++++++++++ service.sh | 2 +- system/bin/magiskswap | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 common/install.sh diff --git a/common.sh b/common.sh index 2a094a9..dc73cfa 100755 --- a/common.sh +++ b/common.sh @@ -13,7 +13,6 @@ # Copyright (C) 2024 chickendrop89 -export MODPATH="/data/adb/modules/magisk-swapspace" export SWAPPROP="$MODPATH/swap.prop" export SWAPFILE="$MODPATH/swap" diff --git a/common/install.sh b/common/install.sh new file mode 100644 index 0000000..13f3c63 --- /dev/null +++ b/common/install.sh @@ -0,0 +1,12 @@ +#!/system/bin/sh + +# Strip _update from current MODPATH +INJECTED_MODPATH="${MODPATH//_update/}" + +# Insert the variable at the beginning of a file +insert_variable() { + sed -i "1i export MODPATH=$INJECTED_MODPATH" "$1" +} + +insert_variable "$MODPATH/system/bin/magiskswap" # Main binary +insert_variable "$MODPATH/common.sh" # Common functions diff --git a/service.sh b/service.sh index 8ebd5fa..c51f91e 100755 --- a/service.sh +++ b/service.sh @@ -19,7 +19,7 @@ resetprop -w sys.boot_completed 0 # Import common functions from file -. "/data/adb/modules/magisk-swapspace/common.sh" +. "$MODPATH/common.sh" SWAPPINESS_PROP="$(readProp SWAPPINESS)" VFS_CACHE_PRESSURE_PROP="$(readProp VFS-CACHE-PRESSURE)" diff --git a/system/bin/magiskswap b/system/bin/magiskswap index 78a823e..03d5cc3 100755 --- a/system/bin/magiskswap +++ b/system/bin/magiskswap @@ -20,7 +20,7 @@ VALUE=$2; OPTIONALVALUE="$3"; # Import common functions from file -. "/data/adb/modules/magisk-swapspace/common.sh"; +. "$MODPATH/common.sh"; # Abort - Print message and exit abort(){