Skip to content

Instantly share code, notes, and snippets.

@rokibhasansagar
Created November 17, 2019 16:52
Show Gist options
  • Select an option

  • Save rokibhasansagar/df319b556e96203c8d5f71a5d2cdc07b to your computer and use it in GitHub Desktop.

Select an option

Save rokibhasansagar/df319b556e96203c8d5f71a5d2cdc07b to your computer and use it in GitHub Desktop.
New Updated `update-binary` for PBRP, only for MediaTek Devices
#!/sbin/sh
# Copyright (C) 2018 ATG Droid
# Copyright (C) 2019 PitchBlack Recovery <pitchblackrecovery@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------- #
### Functions ##
# ---------------------- #
OUTFD=/proc/self/fd/"$2"
ZIP="$3"
DIR=$(dirname "$ZIP")
ui_print() {
until [ ! "$1" ]; do
echo "ui_print $1\nui_print" > "$OUTFD"
shift
done
}
show_progress() {
echo "progress $1 $2" > /proc/self/fd/"$2"
}
set_perm_recursive() {
dirs=$(echo "$*" | awk '{ print substr($0, index($0,$5)) }')
for i in $dirs; do
chown -R "$1"."$2" "$i"; chown -R "$1":"$2" "$i"
find "$i" -type d -exec chmod "$3" {} +
find "$i" -type f -exec chmod "$4" {} +
done
}
file_getprop() {
grep "^$2" "$1" | cut -d= -f2
}
getprop() {
( [ -e "/sbin/getprop" ] && "/sbin/getprop" "$1" ) || file_getprop /default.prop "$1"
}
delete() {
rm -f "$@"
}
delete_recursive() {
rm -rf "$@"
}
abort() {
ui_print "$@"; exit 1
}
# ---------------------- #
### Initialization ###
# ---------------------- #
[ -d "/tmp/pb" ] && rm -rf "/tmp/pb"
mkdir -p /tmp/pb
cd /tmp/pb
unzip -o "$ZIP"
show_progress 0.1000000, 0
ui_print "|---------------------------------------------|"
ui_print "|~~~~~~~ ~~~~~~~|"
ui_print "|=>>-- PitchBlack Recovery Project --<<=|"
ui_print "|===>>>>----- v2.9.0 -----<<<<===|"
ui_print "| |"
ui_print "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|"
ui_print "|===>>>>--- Brought To You By ---<<<<===|"
ui_print "| ------------------------------- |"
ui_print "|~~~~~~~~~~ PitchBlack Team ~~~~~~~~~~|"
ui_print "| ----------------------------- |"
ui_print "| Based on TWRP v3.3.1-x |"
ui_print "|=============================================|"
# Unmount System first, if mounted
/sbin/umount /system || echo ""
# Remount System as read-write
/sbin/mount -o remount,rw /system
PB=/tmp/pb/PBRP
IMG=/tmp/pb/TWRP/recovery.img
ETC=/system/etc/install-recovery.sh
PB1_PATH=/sdcard/PBTWRP
PB2_PATH=/sdcard/PBRP/tools
PB3_PATH=/sdcard/PBRP/themes
UI=/sdcard/PBRP/theme/ui.zip
RES=/sdcard/PBRP/.twrps
OLD=/sdcard/TWRP/PBRP
# Copy awk binary only if recovery doesn't have it
[ ! -f "/sbin/awk" ] && ( cp "META-INF/awk" "/sbin/awk" && chmod 0755 "/sbin/awk" )
# Default MTK Recovery SymLink for TWRP v3.x
RECOVERY="/dev/block/platform/*/*/by-name/recovery"
# Set DD initial to true
DD=true
recovery_partition() {
chk_syml() {
RECOVERY=$(readlink -f "$RECOVERY")
if [ -f "$RECOVERY" ]; then
DD=false
elif [ -b "$RECOVERY" ]; then
case "$RECOVERY" in
/dev/block/mtd*|/dev/block/mmc*)
DD=true ;;
*)
DD=false ;;
esac
else
abort "Failed to get RECOVERY DD format"
fi
}
# if we already have recovery block set then verify and use it
[ "$RECOVERY" ] && chk_syml && return
# otherwise, time to go hunting!
if [ -f /etc/recovery.fstab ]; then
# recovery fstab v1
RECOVERY=$(awk '$1 == "/recovery" {print $3}' /etc/recovery.fstab)
[ "$RECOVERY" ] && chk_syml && return
# recovery fstab v2
RECOVERY=$(awk '$2 == "/recovery" {print $1}' /etc/recovery.fstab)
[ "$RECOVERY" ] && chk_syml && return
fi
for fstab in /fstab.*; do
[ -f "$fstab" ] || continue
# device fstab v2
RECOVERY=$(awk '$2 == "/recovery" {print $1}' "$fstab")
[ "$RECOVERY" ] && chk_syml && return
# device fstab v1
RECOVERY=$(awk '$1 == "/recovery" {print $3}' "$fstab")
[ "$RECOVERY" ] && chk_syml && return
done
if [ -f /proc/emmc ]; then
# emmc layout
RECOVERY=$(awk '$4 == "\"recovery\"" {print $1}' /proc/emmc)
[ "$RECOVERY" ] && RECOVERY=/dev/block/$(echo "$RECOVERY" | cut -f1 -d:) && chk_syml && return
fi
if [ -f /proc/mtd ]; then
# mtd layout
RECOVERY=$(awk '$4 == "\"recovery\"" {print $1}' /proc/mtd)
[ "$RECOVERY" ] && RECOVERY=/dev/block/$(echo "$RECOVERY" | cut -f1 -d:) && chk_syml && return
fi
if [ -f /proc/dumchar_info ]; then
# mtk layout
RECOVERY=$(awk '$1 == "/recovery" {print $5}' /proc/dumchar_info)
[ "$RECOVERY" ] && chk_syml && return
fi
# If anything does not work!
abort "Failed to Find RECOVERY Partition"
}
# Deletion
delete "$ETC" "$UI"
delete_recursive "$PB1_PATH" "$PB2_PATH" "$PB3_PATH" "$RES" "$OLD"
#Flashing
if [ "$DD" = "true" ]; then
dd if="$IMG" of="$RECOVERY"
elif [ "$DD" = "false" ]; then
flash_image "$RECOVERY" "$IMG"
else
abort "Failed to write recovery image!"
fi
#Copy Specific Files
[ ! -d "/sdcard/PBRP" ] && mkdir -p /sdcard/PBRP
cp -r $PB/tools $PB/themes /sdcard/PBRP/
#Copy Backup from TWRP
if [ -d "/sdcard/TWRP/BACKUPS" ]; then
ui_print "Previous TWRP Backup found"
if [ -d "/sdcard/PBRP/BACKUPS" ]; then
cp -r /sdcard/TWRP/BACKUPS/* /sdcard/PBRP/BACKUPS/
else
cp -r /sdcard/TWRP/BACKUPS /sdcard/PBRP/
fi
delete_recursive /sdcard/TWRP
fi
ui_print "| |"
ui_print "|---------------------------------------------|"
ui_print "|---------------------------------------------|"
ui_print "| |"
ui_print "|==>>>---- Thank You ----<<<==|"
ui_print "| ----------------- |"
ui_print "| Rebooting into PitchBlack Recovery |"
ui_print "|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|"
sleep 5s
show_progress 0.1000000, 90
ui_print "|------------Installation finished!-----------|"
/sbin/umount /system
reboot recovery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment