Skip to content

Commit

Permalink
mss: treewide: add a solution to hard-coded paths
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
chickendrop89 committed Dec 2, 2024
1 parent c31dccb commit 3db9431
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 0 additions & 1 deletion common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

# Copyright (C) 2024 chickendrop89

export MODPATH="/data/adb/modules/magisk-swapspace"
export SWAPPROP="$MODPATH/swap.prop"
export SWAPFILE="$MODPATH/swap"

Expand Down
12 changes: 12 additions & 0 deletions common/install.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
2 changes: 1 addition & 1 deletion system/bin/magiskswap
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down

0 comments on commit 3db9431

Please sign in to comment.