mbbpatch/MBCPApp/parse.sh
fukiame 0a89bce342 [SQUASH] refactor: treewide: separate patches, provide common common, refactor change_app_logo, commonize and enhance logging
adding new patches is now trivial:

  cd patches
  cp TEMPLATE patch_name_whatever.sh
  # then just fill in patch name and ver clamp if desired

this gets rid of the need for excessive if-elses and not-so-pleasing indents

for logging, instead of using pure echo, 4 new "levels" can be utilized
- `info` : normal
- `good` : info but have green color?
- `warn` : warning
- `err` : error

Signed-off-by: fukiame <fukiame@proton.me>
2026-03-16 01:14:26 +07:00

84 lines
2.1 KiB
Shell

#!/usr/bin/env bash
# shellcheck disable=SC2295
# vim: expandtab tabstop=4 shiftwidth=4
[ -n "$DIRPATH" ] || {
echo 'ERROR : $DIRPATH not set, script ran standalone?'
exit 1
}
. "$DIRPATH/common.sh"
echo '#!/usr/bin/env bash
[ -n "$DIRPATH" ] || {
err "DIRPATH not set, script ran standalone?"
exit 1
}
[ -d "$DIRPATH"/mbapk/mbapk_unpacked ] || {
err "[mbapk_unpacked] folder not found, please unpack APK first !"
exit 127
}
. "$DIRPATH/common.sh"
applyPatch() {
good "Applying patch [$opt]"
if bash "$2" ; then
good "Patch [$opt] applied successfully"
echo "Patch applied by MBCPApp Patcher on $(uname -s -r) with commit : $(git rev-parse --short HEAD) at $(date)." > "mbapk/mbapk_unpacked/assets/mbcp_info/$1.inf"
else
err "Patch [$opt] failed"
fi
}
echo "--------------------------
Patch list for MBCPApp :"
PS3="Select patch options : "' > patch.sh
for f in patches/*.sh ; do
# name without suffix and prefix
n="$(rstrip "$f" '.sh')"
n="$(lstrip "$n" 'patches/')"
# patch infos
pname="$(getvar "2" "# PATCHNAME: " "$f")"
maxver="$(getvar "3" "# MAXVER: " "$f")"
minver="$(getvar "4" "# MINVER: " "$f")"
pname=${pname//[^a-zA-Z0-9_& ]/}
minver="${minver//[^0-9.]/}"
maxver="${maxver//[^0-9.]/}"
#echo "$f|$pname|$minver|$maxver"
[ -n "$pname" ] || {
warn "[parser] $f missing PATCHNAME, not adding"
continue
}
[ -n "$minver" ] && {
[ "$(get_mb_ver)" -gt "$minver" ] || {
info "[parser] skipping [$pname] as current version is lower than patch version clamp"
continue ; }
} || :
[ -n "$maxver" ] && {
[ "$(get_mb_ver)" -lt "$maxver" ] || {
info "[parser] skipping [$pname] as current version is higher than patch version clamp"
continue ; }
} || :
opts_arr+=" '$pname'"
append+=" '$pname') applyPatch $n $f ;;
"
done
opts_arr+=" 'Exit'"
#echo "$opts_arr"
echo "select opt in $opts_arr" >> patch.sh
echo 'do
case "$opt" in' >> patch.sh
echo "$append
'Exit' ) exit ;;
esac
done" >> patch.sh