Magisk/build.sh

173 lines
5.3 KiB
Bash
Raw Normal View History

#!/bin/bash
usage() {
2016-11-08 22:16:03 +01:00
echo "$0 all <version name>"
echo -e "\tBuild binaries, zip, and sign Magisk"
echo -e "\tThis is equlivant to first <build>, then <zip>"
2016-10-30 12:32:36 +01:00
echo "$0 clean"
echo -e "\tCleanup compiled / generated files"
2016-10-30 12:32:36 +01:00
echo "$0 build"
echo -e "\tBuild the binaries with ndk"
2016-11-08 22:16:03 +01:00
echo "$0 zip <version name>"
echo -e "\tZip and sign Magisk"
2016-10-30 12:32:36 +01:00
echo "$0 uninstaller"
echo -e "\tZip and sign the uninstaller"
exit 1
}
cleanup() {
echo "************************"
echo "* Cleaning up"
echo "************************"
2016-11-08 22:16:03 +01:00
ndk-build clean 2>/dev/null
2017-02-13 23:28:07 +01:00
rm -rfv zip_static/arm
rm -rfv zip_static/arm64
rm -rfv zip_static/x86
rm -rfv zip_static/x64
rm -rfv zip_static/chromeos
rm -rfv zip_static/META-INF/com/google/android/update-binary
2017-03-12 11:13:58 +01:00
rm -rfv zip_static/common/*.sh
rm -rfv zip_static/common/*.rc
2017-02-05 20:22:37 +01:00
rm -rfv uninstaller/common
rm -rfv uninstaller/arm
rm -rfv uninstaller/arm64
rm -rfv uninstaller/x86
rm -rfv uninstaller/x64
2017-02-13 23:28:07 +01:00
rm -rfv uninstaller/chromeos
}
mkcp() {
[ ! -d "$2" ] && mkdir -p "$2"
cp -afv $1 $2
}
error() {
echo -e "\n! $1\n"
exit 1
}
build_bin() {
echo "************************"
echo "* Building binaries"
echo "************************"
[ -z `which ndk-build` ] && error "Please add ndk-build to PATH!"
ndk-build -j4 || error "Magisk binary tools build failed...."
echo "************************"
echo "* Copying binaries"
echo "************************"
2017-01-31 23:02:43 +01:00
mkcp "libs/armeabi-v7a/*" zip_static/arm
2017-03-11 18:24:30 +01:00
mkcp libs/armeabi-v7a/magiskboot uninstaller/arm
mkcp "libs/arm64-v8a/*" zip_static/arm64
2017-03-11 18:24:30 +01:00
mkcp libs/arm64-v8a/magiskboot uninstaller/arm64
mkcp "libs/x86/*" zip_static/x86
2017-03-11 18:24:30 +01:00
mkcp libs/x86/magiskboot uninstaller/x86
mkcp "libs/x86_64/*" zip_static/x64
2017-03-11 18:24:30 +01:00
mkcp libs/x86_64/magiskboot uninstaller/x64
}
zip_package() {
2017-03-11 18:24:30 +01:00
[ ! -f "zip_static/arm/magiskboot" ] && error "Missing binaries!! Please run '$0 build' before zipping"
echo "************************"
echo "* Adding version info"
echo "************************"
sed "s/MAGISK_VERSION_STUB/Magisk v$1 Boot Image Patcher/g" scripts/flash_script.sh > zip_static/META-INF/com/google/android/update-binary
2016-11-08 22:16:03 +01:00
sed "s/MAGISK_VERSION_STUB/setprop magisk.version \"$1\"/g" scripts/magic_mask.sh > zip_static/common/magic_mask.sh
echo "************************"
2017-02-13 23:28:07 +01:00
echo "* Copying files"
echo "************************"
2017-03-12 11:13:58 +01:00
cp -afv scripts/ramdisk_patch.sh zip_static/common/ramdisk_patch.sh
2017-01-31 23:02:43 +01:00
cp -afv scripts/init.magisk.rc zip_static/common/init.magisk.rc
2017-02-13 23:28:07 +01:00
cp -afv binaries/busybox-arm zip_static/arm/busybox
cp -afv binaries/busybox-arm64 zip_static/arm64/busybox
cp -afv binaries/busybox-x86 zip_static/x86/busybox
cp -afv binaries/busybox-x64 zip_static/x64/busybox
cp -afv binaries/chromeos/. zip_static/chromeos
echo "************************"
echo "* Zipping Magisk v$1"
echo "************************"
cd zip_static
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
rm -rf "../Magisk-v$1.zip"
zip "../Magisk-v$1.zip" -r .
cd ../
sign_zip "Magisk-v$1.zip"
}
2016-10-30 12:32:36 +01:00
zip_uninstaller() {
2017-03-11 18:24:30 +01:00
[ ! -f "uninstaller/arm/magiskboot" ] && error "Missing binaries!! Please run '$0 build' before zipping"
2016-10-30 12:32:36 +01:00
echo "************************"
2017-02-13 23:28:07 +01:00
echo "* Copying files"
echo "************************"
mkcp scripts/magisk_uninstaller.sh uninstaller/common
cp -afv binaries/busybox-arm uninstaller/arm/busybox
cp -afv binaries/busybox-arm64 uninstaller/arm64/busybox
cp -afv binaries/busybox-x86 uninstaller/x86/busybox
cp -afv binaries/busybox-x64 uninstaller/x64/busybox
cp -afv binaries/chromeos/. zip_static/chromeos
echo "************************"
2016-10-30 12:32:36 +01:00
echo "* Zipping uninstaller"
echo "************************"
2017-02-05 20:22:37 +01:00
mkcp scripts/magisk_uninstaller.sh uninstaller/common
2016-10-30 12:32:36 +01:00
cd uninstaller
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
TIMESTAMP=`date "+%Y%m%d"`
2016-10-30 12:32:36 +01:00
rm -rf "../Magisk-uninstaller-$TIMESTAMP.zip"
zip "../Magisk-uninstaller-$TIMESTAMP.zip" -r .
cd ../
sign_zip "Magisk-uninstaller-$TIMESTAMP.zip"
}
sign_zip() {
if [ ! -f "ziptools/zipadjust" ]; then
echo "************************"
echo "* Compiling ZipAdjust"
echo "************************"
gcc -o ziptools/zipadjust ziptools/src/*.c -lz || error "ZipAdjust Build failed...."
chmod 755 ziptools/zipadjust
fi
echo "************************"
echo "* First sign $1"
echo "************************"
java -jar "ziptools/signapk.jar" "ziptools/test.certificate.x509.pem" "ziptools/test.key.pk8" "$1" "${1%.*}-firstsign.zip"
echo "************************"
echo "* Adjusting $1"
echo "************************"
ziptools/zipadjust "${1%.*}-firstsign.zip" "${1%.*}-adjusted.zip"
echo "************************"
echo "* Final sign $1"
echo "************************"
java -jar "ziptools/minsignapk.jar" "ziptools/test.certificate.x509.pem" "ziptools/test.key.pk8" "${1%.*}-adjusted.zip" "${1%.*}-signed.zip"
mv "${1%.*}-signed.zip" "$1"
rm "${1%.*}-adjusted.zip" "${1%.*}-firstsign.zip"
}
DIR="$(cd "$(dirname "$0")"; pwd)"
cd "$DIR"
case $1 in
2016-10-30 12:32:36 +01:00
"all" )
[ -z "$2" ] && echo -e "! Missing version number\n" && usage
build_bin
zip_package $2
;;
2016-10-30 12:32:36 +01:00
"clean" )
cleanup
;;
2016-10-30 12:32:36 +01:00
"build" )
build_bin
;;
2016-10-30 12:32:36 +01:00
"zip" )
[ -z "$2" ] && echo -e "! Missing version number\n" && usage
zip_package $2
;;
2016-10-30 12:32:36 +01:00
"uninstaller" )
zip_uninstaller
;;
* )
usage
;;
esac