-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.sh
executable file
·77 lines (61 loc) · 2.03 KB
/
common.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Copyright (C) 2024 chickendrop89
export MODPATH="/data/adb/modules/magisk-swapspace"
export SWAPPROP="$MODPATH/swap.prop"
export SWAPFILE="$MODPATH/swap"
export VFS_CACHE_PRESSURE_SYSCTL_ENTRY="vm.vfs_cache_pressure"
export SWAPPINESS_SYSCTL_ENTRY="vm.swappiness"
cprint(){
printf "- magisk-swapspace: %s \n" "$1"
}
# Modify module properties
modifyProp(){
NAME="$1"
VARPROP="$2"
FILE="$SWAPPROP"
if [ "$NAME" ] && [ ! "$NAME" = "=" ];
then
touch "$FILE" 2>/dev/null
echo "$NAME=$VARPROP" | while read -r prop;
do
newprop="$(echo "$prop" | cut -d '=' -f1)"
sed -i "/${newprop}/d" "$FILE"
cat="$(cat "$FILE")"
echo "$prop" > "$FILE"
echo "$cat" >>"$FILE"
done 2>/dev/null
fi
}
# Delete module properties
deleteProp(){
NAME="$1"
FILE="$SWAPPROP"
noneprop="$NAME="
nonepropn="$noneprop\n"
if [ "$NAME" ] && [ ! "$NAME" = "=" ];
then
sed -i "/${nonepropn}/d" "$FILE" 2>/dev/null
sed -i "/${noneprop}/d" "$FILE" 2>/dev/null
fi
}
# Read module properties
readProp() {
REGEX="s/^$1=//p"
FILE="$SWAPPROP"
cat "$FILE" 2>/dev/null | sed -n "$REGEX" | head -n 1
}
# Set kernel tune - it's as simple as that
setKernelTune() {
KEY="$1"
VALUE="$2"
sysctl -w -q "$KEY=$VALUE"
}