Skip to content

Commit a4865fc

Browse files
implement shellcheck changes
1 parent 87c2aab commit a4865fc

File tree

5 files changed

+39
-30
lines changed

5 files changed

+39
-30
lines changed

compile.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ source magiskmodule/constants.sh
99
GZIP=(gzip --best)
1010
[ -n "$(command -v pigz)" ] && {
1111
GZIP=(pigz --best)
12-
[ $(nproc) -ge 8 ] && GZIP=(pigz -11)
12+
[ "$(nproc)" -ge 8 ] && GZIP=(pigz -11)
1313
}
1414

1515
compressArchiveZip() {
@@ -18,6 +18,7 @@ compressArchiveZip() {
1818
local targetarchive="$(pwd)"/"$2"
1919
(
2020
cd "$folder"
21+
#shellcheck disable=SC2086
2122
zip -r -9 -q "$targetarchive" $files
2223
)
2324
}
@@ -28,7 +29,8 @@ compressArchiveTarGz() {
2829
local targetarchive="$2"
2930
(
3031
cd "$folder"
31-
tar -cf- $files | "${GZIP[@]}" > "../$targetarchive"
32+
#shellcheck disable=SC2086
33+
tar -cf - $files | "${GZIP[@]}" > "../$targetarchive"
3234
)
3335
}
3436

magiskmodule/constants.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
# minimum required SDK level
44
MINAPI=28

magiskmodule/customize.sh

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
[ ! -f "$MODPATH"/constants.sh ] && abort "Missing constants.sh"
44
source "$MODPATH"/constants.sh
55

6-
[ $API -lt $MINAPI ] && abort "Android SDK $API is not supported!"
7-
[ "$BOOTMODE" != "true" ] && abort "Please install this module within the Magisk app."
6+
[ "$API" -lt "$MINAPI" ] && abort "Android SDK $API is not supported!"
7+
[ "$BOOTMODE" != true ] && abort "Please install this module within the Magisk app."
88

99
IFS=$'\n'
1010
SEARCH_ROOT=/
@@ -23,7 +23,7 @@ denylist_run() {
2323
mkdir -p "$FOLDER"
2424

2525
mkdir -p "$FOLDER"/DDC
26-
CUSTOM_VDC_FILES=$(find $SDCARD -name '*.vdc' -not -path "$SDCARD/Android/*")
26+
CUSTOM_VDC_FILES=$(find "$SDCARD" -name '*.vdc' -not -path "$SDCARD/Android/*")
2727
[ -n "$CUSTOM_VDC_FILES" ] && CUSTOM_VDC_FOUND=true || CUSTOM_VDC_FOUND=false
2828
[ -f "$MODPATH"/"$VIPERVDCFILE" ] && VDC_ARCHIVE_FOUND=true || VDC_ARCHIVE_FOUND=false
2929
for file in $(tar -tzf "$MODPATH"/"$VIPERVDCFILE") $CUSTOM_VDC_FILES; do
@@ -52,7 +52,7 @@ if $CUSTOM_VDC_FOUND; then
5252
fi
5353

5454
mkdir -p "$FOLDER"/Kernel
55-
CUSTOM_IRS_FILES=$(find $SDCARD -name '*.irs' -not -path "$SDCARD/Android/*")
55+
CUSTOM_IRS_FILES=$(find "$SDCARD" -name '*.irs' -not -path "$SDCARD/Android/*")
5656
[ -n "$CUSTOM_IRS_FILES" ] && CUSTOM_IRS_FOUND=true || CUSTOM_IRS_FOUND=false
5757
[ -f "$MODPATH"/"$VIPERIRSFILE" ] && IRS_ARCHIVE_FOUND=true || IRS_ARCHIVE_FOUND=false
5858
for file in $(tar -tzf "$MODPATH"/"$VIPERIRSFILE") $CUSTOM_IRS_FILES; do
@@ -87,7 +87,7 @@ presetCompatible() {
8787
}
8888

8989
mkdir -p "$FOLDER"/Preset
90-
CUSTOM_PRESET_FILES=$(find $SDCARD -name '*.xml' -not -path "$SDCARD/Android/*")
90+
CUSTOM_PRESET_FILES=$(find "$SDCARD" -name '*.xml' -not -path "$SDCARD/Android/*")
9191
if [ -n "$CUSTOM_PRESET_FILES" ]; then
9292
ui_print "- Copying custom preset files"
9393
for file in $CUSTOM_PRESET_FILES; do
@@ -119,6 +119,9 @@ osp_detect() {
119119
sed -i "/^\( *\)<apply effect=\"$effect\"\/>/d" "$file"
120120
done
121121
;;
122+
*)
123+
abort "failed to run osp_detect on $file"
124+
;;
122125
esac
123126
}
124127
AUDIO_EFFECTS_FILES="$( \
@@ -130,7 +133,7 @@ for ORIGINAL_FILE in $AUDIO_EFFECTS_FILES; do
130133
ui_print " Patching $ORIGINAL_FILE"
131134
FILE="$MODPATH"/"$(echo "$ORIGINAL_FILE" | sed -e 's|^/system/|/|g' -e 's|^/|/system/|')"
132135
[ -f "$FILE" ] && continue
133-
mkdir -p "$(dirname $FILE)"
136+
mkdir -p "$(dirname "$FILE")"
134137
ORIGINAL_FILE="$SEARCH_ROOT"/"$ORIGINAL_FILE"
135138
case "$FILE" in
136139
*.conf)
@@ -147,6 +150,9 @@ for ORIGINAL_FILE in $AUDIO_EFFECTS_FILES; do
147150
-e "s|<effects>|<effects>\n <effect name=\"$LIBRARY_NAME\" library=\"$EFFECT_NAME\" uuid=\"$EFFECT_UUID\"/>|" \
148151
> "$FILE"
149152
;;
153+
*)
154+
abort "unable to patch $ORIGINAL_FILE"
155+
;;
150156
esac
151157
osp_detect "$FILE"
152158
done
@@ -155,10 +161,10 @@ done
155161
ui_print "- Installing the ViPER4AndroidFX user app"
156162
APK="$MODPATH"/v4afx.apk
157163
[ ! -f "$APK" ] && abort "Missing ViPER4Android APK!"
158-
[ -n "$(pm list packages | grep "^package:$VIPERFXPACKAGE$")" ] && APK_UPGRADE=true || APK_UPGRADE=false
164+
pm list packages | grep -q "^package:$VIPERFXPACKAGE$" && APK_UPGRADE=true || APK_UPGRADE=false
159165
APK_SIZE=$(stat -c %s "$APK")
160166
installAPK() {
161-
pm install --install-location 1 --pkg "$VIPERFXPACKAGE" -S $APK_SIZE < "$APK" &>/dev/null
167+
pm install --install-location 1 --pkg "$VIPERFXPACKAGE" -S "$APK_SIZE" < "$APK" &>/dev/null
162168
}
163169
installAPK || {
164170
$APK_UPGRADE && pm uninstall -k "$VIPERFXPACKAGE" &>/dev/null
@@ -173,27 +179,27 @@ VIPERFXPREFSOWNER="$(stat -c '%U' "$VIPERFXPREFS")"
173179
VIPERFXSHAREDPREFS="$VIPERFXPREFS"/shared_prefs
174180
[ ! -d "$VIPERFXSHAREDPREFS" ] && mkdir "$VIPERFXSHAREDPREFS"
175181
cp -f "$MODPATH"/viperfx_preferences.xml "$VIPERFXSHAREDPREFS"/"${VIPERFXPACKAGE}_preferences.xml"
176-
chown -R $VIPERFXPREFSOWNER:$VIPERFXPREFSOWNER "$VIPERFXPREFS"
182+
chown -R "$VIPERFXPREFSOWNER":"$VIPERFXPREFSOWNER" "$VIPERFXPREFS"
177183
set_perm_recursive "$FOLDER" "$VIPERFXPREFSOWNER" sdcard_rw 771 660 u:object_r:sdcardfs:s0
178184
# this permanently hides the notifications without the possiblity of reenabling them
179-
[ $API -ge 31 ] && pm set-distracting-restriction --flag hide-notifications $VIPERFXPACKAGE
180-
[ $API -ge 33 ] && {
185+
[ "$API" -ge 31 ] && pm set-distracting-restriction --flag hide-notifications "$VIPERFXPACKAGE"
186+
[ "$API" -ge 33 ] && {
181187
# this will tell android that the user made the final decision to not receive notifications
182-
pm revoke $VIPERFXPACKAGE android.permission.POST_NOTIFICATIONS
183-
pm set-permission-flags $VIPERFXPACKAGE android.permission.POST_NOTIFICATIONS user-fixed
188+
pm revoke "$VIPERFXPACKAGE" android.permission.POST_NOTIFICATIONS
189+
pm set-permission-flags "$VIPERFXPACKAGE" android.permission.POST_NOTIFICATIONS user-fixed
184190
}
185191
# this disables battery optimization
186-
[ $API -ge 30 ] && dumpsys deviceidle whitelist +$VIPERFXPACKAGE >/dev/null
192+
[ "$API" -ge 30 ] && dumpsys deviceidle whitelist +"$VIPERFXPACKAGE" >/dev/null
187193
# this disables automatic permissions revoke if unused
188-
[ $API -ge 30 ] && appops set --uid $VIPERFXPACKAGE AUTO_REVOKE_PERMISSIONS_IF_UNUSED ignore
194+
[ "$API" -ge 30 ] && appops set --uid "$VIPERFXPACKAGE" AUTO_REVOKE_PERMISSIONS_IF_UNUSED ignore
189195

190196
while IFS= read -r packagedata; do
191197
package="$(echo "$packagedata" | cut -d'|' -f1)"
192198
package_filename="$(echo "$packagedata" | cut -d'|' -f2)"
193199
package_friendlyname="$(echo "$packagedata" | cut -d'|' -f3)"
194-
[ -n "$(pm list packages | grep "^package:$package$")" ] && {
200+
pm list packages | grep -q "^package:$package$" && {
195201
ui_print "- Disabling $package_friendlyname (p)"
196-
package_apk="$(pm list packages -f $package | grep -E "package:.*=$package$" | sed "s/package:\(.*\)=$package/\1/")"
202+
package_apk="$(pm list packages -f "$package" | grep -E "package:.*=$package$" | sed "s/package:\(.*\)=$package/\1/")"
197203
package_apk_dir="$(dirname "$package_apk" | sed -e 's|^/||' -e 's|^system/||')"
198204
mkdir -p "$MODPATH"/system/"$package_apk_dir"
199205
touch "$MODPATH"/system/"$package_apk_dir"/"$(basename "$package_apk")"

magiskmodule/service.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

3-
cd "$(dirname "$0")"
3+
cd "$(dirname "$0")" || exit
44
source ./constants.sh
55

66
waitUntilBootCompleted() {
77
resetprop -w sys.boot_completed 0 && return
8-
while [ $(getprop sys.boot_completed) -eq 0 ]; do
8+
while [ "$(getprop sys.boot_completed)" -eq 0 ]; do
99
sleep 10
1010
done
1111
}
1212

1313
(
1414
waitUntilBootCompleted
1515
sleep 10
16-
[ -n "$(pm list packages -d | grep $VIPERFXPACKAGE)" ] && pm enable $VIPERFXPACKAGE
16+
pm list packages -d | grep -q "$VIPERFXPACKAGE" && pm enable "$VIPERFXPACKAGE"
1717
) &
1818

1919
(
2020
waitUntilBootCompleted
2121
sleep 60
2222
while true; do
23-
PID=$(pidof $VIPERFXPACKAGE)
24-
[ -z "$PID" ] && am broadcast -a android.intent.action.BOOT_COMPLETED -p $VIPERFXPACKAGE
25-
[ -n "$PID" ] && echo -1000 > /proc/$PID/oom_score_adj
23+
PID=$(pidof "$VIPERFXPACKAGE")
24+
[ -z "$PID" ] && am broadcast -a android.intent.action.BOOT_COMPLETED -p "$VIPERFXPACKAGE"
25+
[ -n "$PID" ] && echo -1000 > /proc/"$PID"/oom_score_adj
2626
sleep 15
2727
done
2828
) &

magiskmodule/uninstall.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
#!/bin/sh
12

2-
cd "$(dirname "$0")"
3+
cd "$(dirname "$0")" || exit
34
source ./constants.sh
45

56
waitUntilBootCompleted() {
67
resetprop -w sys.boot_completed 0 && return
7-
while [ $(getprop sys.boot_completed) -eq 0 ]; do
8+
while [ "$(getprop sys.boot_completed)" -eq 0 ]; do
89
sleep 10
910
done
1011
}

0 commit comments

Comments
 (0)