2016-10-30 11:11:26 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
usage() {
|
2017-04-19 21:07:52 +00:00
|
|
|
echo "$ME all <version name> <version code>"
|
2016-10-30 11:11:26 +00:00
|
|
|
echo -e "\tBuild binaries, zip, and sign Magisk"
|
2016-12-05 18:41:05 +00:00
|
|
|
echo -e "\tThis is equlivant to first <build>, then <zip>"
|
2017-04-19 21:07:52 +00:00
|
|
|
echo "$ME clean"
|
2016-10-30 11:11:26 +00:00
|
|
|
echo -e "\tCleanup compiled / generated files"
|
2017-04-19 21:07:52 +00:00
|
|
|
echo "$ME build <verison name> <version code>"
|
2016-10-30 11:11:26 +00:00
|
|
|
echo -e "\tBuild the binaries with ndk"
|
2017-04-19 21:07:52 +00:00
|
|
|
echo "$ME debug <verison name> <version code>"
|
2017-04-18 14:25:36 +00:00
|
|
|
echo -e "\tBuild the binaries with the debug flag on\n\tCall <zip> afterwards if you want to flash on device"
|
2017-04-19 21:07:52 +00:00
|
|
|
echo "$ME zip <version name>"
|
2016-10-30 11:11:26 +00:00
|
|
|
echo -e "\tZip and sign Magisk"
|
2017-04-19 21:07:52 +00:00
|
|
|
echo "$ME uninstaller"
|
2016-10-30 11:11:26 +00:00
|
|
|
echo -e "\tZip and sign the uninstaller"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
echo "************************"
|
|
|
|
echo "* Cleaning up"
|
|
|
|
echo "************************"
|
2016-11-08 21:16:03 +00:00
|
|
|
ndk-build clean 2>/dev/null
|
2017-02-13 22:28:07 +00:00
|
|
|
rm -rfv zip_static/arm
|
|
|
|
rm -rfv zip_static/arm64
|
|
|
|
rm -rfv zip_static/x86
|
|
|
|
rm -rfv zip_static/x64
|
2017-01-06 03:20:16 +00:00
|
|
|
rm -rfv zip_static/META-INF/com/google/android/update-binary
|
2017-03-12 10:13:58 +00:00
|
|
|
rm -rfv zip_static/common/*.sh
|
|
|
|
rm -rfv zip_static/common/*.rc
|
2017-02-05 19:22:37 +00:00
|
|
|
rm -rfv uninstaller/common
|
2016-10-30 11:11:26 +00:00
|
|
|
rm -rfv uninstaller/arm
|
|
|
|
rm -rfv uninstaller/arm64
|
|
|
|
rm -rfv uninstaller/x86
|
|
|
|
rm -rfv uninstaller/x64
|
|
|
|
}
|
|
|
|
|
|
|
|
mkcp() {
|
|
|
|
[ ! -d "$2" ] && mkdir -p "$2"
|
|
|
|
cp -afv $1 $2
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:41:05 +00:00
|
|
|
error() {
|
|
|
|
echo -e "\n! $1\n"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2016-10-30 11:11:26 +00:00
|
|
|
build_bin() {
|
2017-04-19 21:07:52 +00:00
|
|
|
[ -z "$1" -o -z "$2" ] && echo -e "! Missing version info\n" && usage
|
|
|
|
BUILD="Build"
|
2017-05-01 21:00:01 +00:00
|
|
|
[ -z "$DEBUG" ] || BUILD="Debug"
|
2016-10-30 11:11:26 +00:00
|
|
|
echo "************************"
|
2017-04-19 21:07:52 +00:00
|
|
|
echo "* $BUILD: VERSION=$1 CODE=$2"
|
2016-10-30 11:11:26 +00:00
|
|
|
echo "************************"
|
2016-12-05 18:41:05 +00:00
|
|
|
[ -z `which ndk-build` ] && error "Please add ndk-build to PATH!"
|
2017-04-18 14:25:36 +00:00
|
|
|
ndk-build APP_CFLAGS="-DMAGISK_VERSION=$1 -DMAGISK_VER_CODE=$2 $DEBUG" -j${CPUNUM} || error "Magisk binary tools build failed...."
|
2016-10-30 11:11:26 +00:00
|
|
|
echo "************************"
|
|
|
|
echo "* Copying binaries"
|
|
|
|
echo "************************"
|
2017-04-15 18:49:01 +00:00
|
|
|
mkcp libs/armeabi-v7a/magisk zip_static/arm
|
|
|
|
mkcp libs/armeabi-v7a/magiskboot zip_static/arm
|
|
|
|
mkcp libs/arm64-v8a/magisk zip_static/arm64
|
|
|
|
mkcp libs/arm64-v8a/magiskboot zip_static/arm64
|
|
|
|
mkcp libs/x86/magisk zip_static/x86
|
|
|
|
mkcp libs/x86/magiskboot zip_static/x86
|
|
|
|
mkcp libs/x86_64/magisk zip_static/x64
|
|
|
|
mkcp libs/x86_64/magiskboot zip_static/x64
|
2017-03-11 17:24:30 +00:00
|
|
|
mkcp libs/armeabi-v7a/magiskboot uninstaller/arm
|
|
|
|
mkcp libs/arm64-v8a/magiskboot uninstaller/arm64
|
|
|
|
mkcp libs/x86/magiskboot uninstaller/x86
|
|
|
|
mkcp libs/x86_64/magiskboot uninstaller/x64
|
2016-10-30 11:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
zip_package() {
|
2017-04-19 21:07:52 +00:00
|
|
|
[ -z "$1" ] && echo -e "! Missing version info\n" && usage
|
2017-04-21 23:05:10 +00:00
|
|
|
[ ! -f "zip_static/arm/magiskboot" ] && error "Missing binaries!! Please run '$ME build' before zipping"
|
2016-10-30 11:11:26 +00:00
|
|
|
echo "************************"
|
|
|
|
echo "* Adding version info"
|
|
|
|
echo "************************"
|
2017-04-21 23:05:10 +00:00
|
|
|
sed "s/MAGISK_VERSION_STUB/Magisk v$1 Installer/g" scripts/flash_script.sh > zip_static/META-INF/com/google/android/update-binary
|
|
|
|
# sed "s/MAGISK_VERSION_STUB/setprop magisk.version \"$1\"/g" scripts/magic_mask.sh > zip_static/common/magic_mask.sh
|
2016-10-30 11:11:26 +00:00
|
|
|
echo "************************"
|
2017-02-13 22:28:07 +00:00
|
|
|
echo "* Copying files"
|
2016-10-30 11:11:26 +00:00
|
|
|
echo "************************"
|
2017-03-30 22:25:22 +00:00
|
|
|
cp -afv scripts/custom_ramdisk_patch.sh zip_static/common/custom_ramdisk_patch.sh
|
2017-01-31 22:02:43 +00:00
|
|
|
cp -afv scripts/init.magisk.rc zip_static/common/init.magisk.rc
|
2017-02-13 22:28:07 +00:00
|
|
|
echo "************************"
|
|
|
|
echo "* Zipping Magisk v$1"
|
|
|
|
echo "************************"
|
2016-10-30 11:11:26 +00:00
|
|
|
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 11:32:36 +00:00
|
|
|
zip_uninstaller() {
|
2017-03-11 17:24:30 +00:00
|
|
|
[ ! -f "uninstaller/arm/magiskboot" ] && error "Missing binaries!! Please run '$0 build' before zipping"
|
2016-10-30 11:32:36 +00:00
|
|
|
echo "************************"
|
2017-02-13 22:28:07 +00:00
|
|
|
echo "* Copying files"
|
|
|
|
echo "************************"
|
|
|
|
mkcp scripts/magisk_uninstaller.sh uninstaller/common
|
|
|
|
echo "************************"
|
2016-10-30 11:32:36 +00:00
|
|
|
echo "* Zipping uninstaller"
|
|
|
|
echo "************************"
|
|
|
|
cd uninstaller
|
|
|
|
find . -type f -exec chmod 644 {} \;
|
|
|
|
find . -type d -exec chmod 755 {} \;
|
2016-12-05 18:41:05 +00:00
|
|
|
TIMESTAMP=`date "+%Y%m%d"`
|
2016-10-30 11:32:36 +00:00
|
|
|
rm -rf "../Magisk-uninstaller-$TIMESTAMP.zip"
|
|
|
|
zip "../Magisk-uninstaller-$TIMESTAMP.zip" -r .
|
|
|
|
cd ../
|
|
|
|
sign_zip "Magisk-uninstaller-$TIMESTAMP.zip"
|
|
|
|
}
|
|
|
|
|
2016-10-30 11:11:26 +00:00
|
|
|
sign_zip() {
|
2016-12-05 18:41:05 +00:00
|
|
|
if [ ! -f "ziptools/zipadjust" ]; then
|
2016-10-30 11:11:26 +00:00
|
|
|
echo "************************"
|
|
|
|
echo "* Compiling ZipAdjust"
|
|
|
|
echo "************************"
|
2016-12-05 18:41:05 +00:00
|
|
|
gcc -o ziptools/zipadjust ziptools/src/*.c -lz || error "ZipAdjust Build failed...."
|
|
|
|
chmod 755 ziptools/zipadjust
|
2016-10-30 11:11:26 +00:00
|
|
|
fi
|
|
|
|
echo "************************"
|
|
|
|
echo "* First sign $1"
|
|
|
|
echo "************************"
|
2016-12-05 18:41:05 +00:00
|
|
|
java -jar "ziptools/signapk.jar" "ziptools/test.certificate.x509.pem" "ziptools/test.key.pk8" "$1" "${1%.*}-firstsign.zip"
|
2016-10-30 11:11:26 +00:00
|
|
|
echo "************************"
|
|
|
|
echo "* Adjusting $1"
|
|
|
|
echo "************************"
|
2016-12-05 18:41:05 +00:00
|
|
|
ziptools/zipadjust "${1%.*}-firstsign.zip" "${1%.*}-adjusted.zip"
|
2016-10-30 11:11:26 +00:00
|
|
|
echo "************************"
|
|
|
|
echo "* Final sign $1"
|
|
|
|
echo "************************"
|
2016-12-05 18:41:05 +00:00
|
|
|
java -jar "ziptools/minsignapk.jar" "ziptools/test.certificate.x509.pem" "ziptools/test.key.pk8" "${1%.*}-adjusted.zip" "${1%.*}-signed.zip"
|
2016-10-30 11:11:26 +00:00
|
|
|
|
|
|
|
mv "${1%.*}-signed.zip" "$1"
|
|
|
|
rm "${1%.*}-adjusted.zip" "${1%.*}-firstsign.zip"
|
|
|
|
}
|
|
|
|
|
|
|
|
DIR="$(cd "$(dirname "$0")"; pwd)"
|
2017-04-18 14:25:36 +00:00
|
|
|
DEBUG=
|
|
|
|
CPUNUM=`getconf _NPROCESSORS_ONLN`
|
2017-04-19 21:07:52 +00:00
|
|
|
ME=$0
|
2016-10-30 11:11:26 +00:00
|
|
|
|
|
|
|
case $1 in
|
2016-10-30 11:32:36 +00:00
|
|
|
"all" )
|
2017-04-18 14:25:36 +00:00
|
|
|
build_bin $2 $3
|
2016-10-30 11:11:26 +00:00
|
|
|
zip_package $2
|
|
|
|
;;
|
2016-10-30 11:32:36 +00:00
|
|
|
"clean" )
|
2016-10-30 11:11:26 +00:00
|
|
|
cleanup
|
|
|
|
;;
|
2016-10-30 11:32:36 +00:00
|
|
|
"build" )
|
2017-04-18 14:25:36 +00:00
|
|
|
build_bin $2 $3
|
|
|
|
;;
|
|
|
|
"debug" )
|
|
|
|
DEBUG="-DDEBUG"
|
2017-04-19 21:07:52 +00:00
|
|
|
build_bin $2 $3
|
2016-10-30 11:11:26 +00:00
|
|
|
;;
|
2016-10-30 11:32:36 +00:00
|
|
|
"zip" )
|
2017-04-18 14:25:36 +00:00
|
|
|
[ -z "$2" ] && echo -e "! Missing version info\n" && usage
|
2016-10-30 11:11:26 +00:00
|
|
|
zip_package $2
|
|
|
|
;;
|
2016-10-30 11:32:36 +00:00
|
|
|
"uninstaller" )
|
2016-10-30 11:11:26 +00:00
|
|
|
zip_uninstaller
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|