Skip to content

Commit

Permalink
magisk: Fix compatibility with Magisk v28
Browse files Browse the repository at this point in the history
A new library 'libinit-ld.so' got introduced, 'libmagisk<arch>.so' changed to 'libmagisk.so' and the old download server got deprecated.

Rework and simplify update_magisk.sh to account for the new library changes and download links.

Signed-off-by: Louis Poier <lpoier7@proton.me>
  • Loading branch information
PeterKnecht93 committed Dec 20, 2024
1 parent fe815ff commit 8dc43d9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 45 deletions.
12 changes: 5 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,11 @@ update_magisk() {
script_echo " "
script_echo "I: Updating Magisk..."

if [[ "x${BUILD_KERNEL_MAGISK_BRANCH}" == "xcanary" ]]; then
MAGISK_BRANCH="canary"
elif [[ "x${BUILD_KERNEL_MAGISK_BRANCH}" == "xlocal" ]]; then
MAGISK_BRANCH="local"
else
MAGISK_BRANCH=""
fi
case "$BUILD_KERNEL_MAGISK_BRANCH" in
canary) MAGISK_BRANCH="canary" ;;
local) MAGISK_BRANCH="local" ;;
*) MAGISK_BRANCH="stable" ;;
esac

${ORIGIN_DIR}/usr/magisk/update_magisk.sh ${MAGISK_BRANCH} 2>&1 | sed 's/^/ /'
}
Expand Down
4 changes: 2 additions & 2 deletions usr/magisk/initramfs_list
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ file /init usr/magisk/magiskinit 0755 0 0
file /.backup/.magisk usr/magisk/backup_magisk 0705 0 0
dir /overlay.d 0750 0 0
dir /overlay.d/sbin 0750 0 0
file /overlay.d/sbin/magisk32.xz usr/magisk/magisk32.xz 0644 0 0
file /overlay.d/sbin/magisk64.xz usr/magisk/magisk64.xz 0644 0 0
file /overlay.d/sbin/magisk.xz usr/magisk/magisk.xz 0644 0 0
file /overlay.d/sbin/init-ld.xz usr/magisk/init-ld.xz 0644 0 0
file /overlay.d/sbin/stub.xz usr/magisk/stub.xz 0644 0 0
63 changes: 27 additions & 36 deletions usr/magisk/update_magisk.sh
Original file line number Diff line number Diff line change
@@ -1,46 +1,37 @@
#!/bin/bash
#!/usr/bin/env bash

set -e
set -eu

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# [
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

ver="$(cat "$DIR/magisk_version" 2>/dev/null || echo -n 'none')"
MAGISK_CURRENT_VERSION="$(cat "$DIR/magisk_version" 2>/dev/null || echo -n 'none')"
MAGISK_BRANCH="$1"
# ]

if [ "x$1" = "xcanary" ]
then
nver="canary"
magisk_link="https://github.com/topjohnwu/magisk-files/raw/${nver}/app-debug.apk"
elif [ "x$1" = "xlocal" ]
then
nver="local"
magisk_link="https://gitlab.com/TenSeventy7/magisk-files/raw/main/app-debug.apk"
if [[ $MAGISK_BRANCH == local ]]; then
MAGISK_VERSION="local"
MAGISK_LINK="https://gitlab.com/TenSeventy7/magisk-files/raw/main/app-debug.apk"
else
if [ "x$1" = "x" ]; then
nver="$(curl -s https://raw.githubusercontent.com/topjohnwu/magisk-files/master/stable.json | jq '.magisk.version' | cut -d '"' -f 2)"
else
nver="$1"
fi
magisk_link="https://cdn.jsdelivr.net/gh/topjohnwu/magisk-files@${nver}/app-release.apk"
MAGISK_VERSION="$(curl -s "https://raw.githubusercontent.com/topjohnwu/magisk-files/master/$MAGISK_BRANCH.json" | jq '.magisk.version' | cut -d '"' -f 2)"
MAGISK_LINK="$(curl -s "https://raw.githubusercontent.com/topjohnwu/magisk-files/master/$MAGISK_BRANCH.json" | jq '.magisk.link' | cut -d '"' -f 2)"
fi

if [ \( -n "$nver" \) -a \( "$nver" != "$ver" \) -o ! \( -f "$DIR/arm/magiskinit64" \) -o \( "$nver" = "canary" \) -o \( "$nver" = "local" \) ]
then
echo "Updating Magisk from $ver to $nver"
curl -s --output "$DIR/magisk.zip" -L "$magisk_link"
if fgrep 'Not Found' "$DIR/magisk.zip"; then
curl -s --output "$DIR/magisk.zip" -L "${magisk_link%.apk}.zip"
fi

7z e "$DIR/magisk.zip" lib/arm64-v8a/libmagiskinit.so lib/armeabi-v7a/libmagisk32.so lib/arm64-v8a/libmagisk64.so assets/stub.apk -o"$DIR" -y
mv -f "$DIR/libmagiskinit.so" "$DIR/magiskinit"
mv -f "$DIR/libmagisk32.so" "$DIR/magisk32"
mv -f "$DIR/libmagisk64.so" "$DIR/magisk64"
mv -f "$DIR/stub.apk" "$DIR/stub"
xz --force --check=crc32 "$DIR/magisk32" "$DIR/magisk64" "$DIR/stub"

echo -n "$nver" > "$DIR/magisk_version"
if [[ $MAGISK_CURRENT_VERSION != "$MAGISK_VERSION" ]] || [[ $MAGISK_BRANCH == local || $MAGISK_BRANCH == canary ]]; then
echo "Updating Magisk from $MAGISK_CURRENT_VERSION to $MAGISK_VERSION"
curl -s --output "$DIR/magisk.zip" -L "$MAGISK_LINK"

grep -q 'Not Found' "$DIR/magisk.zip" \
&& curl -s --output "$DIR/magisk.zip" -L "${MAGISK_LINK%.apk}.zip"

7z e -so "$DIR/magisk.zip" lib/arm64-v8a/libmagiskinit.so > "$DIR/magiskinit"
7z e -so "$DIR/magisk.zip" lib/arm64-v8a/libmagisk.so > "$DIR/magisk"
7z e -so "$DIR/magisk.zip" lib/arm64-v8a/libinit-ld.so > "$DIR/init-ld"
7z e -so "$DIR/magisk.zip" assets/stub.apk > "$DIR/stub"
xz --force --check=crc32 "$DIR/magisk" "$DIR/init-ld" "$DIR/stub"

echo -n "$MAGISK_VERSION" > "$DIR/magisk_version"
rm "$DIR/magisk.zip"
touch "$DIR/initramfs_list"
else
echo "Nothing to be done: Magisk version $nver"
echo "Nothing to be done: Magisk version $MAGISK_VERSION"
fi

0 comments on commit 8dc43d9

Please sign in to comment.