Skip to content

Instantly share code, notes, and snippets.

@Fire7ly
Created July 29, 2022 04:34
Show Gist options
  • Save Fire7ly/52cf49c10fc65ecfcc1eb7a61d5e5d50 to your computer and use it in GitHub Desktop.
Save Fire7ly/52cf49c10fc65ecfcc1eb7a61d5e5d50 to your computer and use it in GitHub Desktop.
A Simple Bash Script Which Flash GSI On Realme Devices It Working Fine With My Realme C3 Device For Now...
#!/bin/bash
# A Bash Script Which Is Used To Flash GSIS On Realme Devices, It Can Flash Gsi On Dynamic Partition Using Fastboot
# Summary About Working Under The Hood!!
# 1. Reboot Into Bootloader From Any State.
# EX :
# - Adb ( device or recovery mode both supported ...)
# - Fastboot ( If It Detect Fastbootd Mode, It Will Reboot Your Device Back Into Bootloader Mode To Avoide Damage ...)
# 2. Flash vbmeta Image To Disable Verification And Verity.
# 3. Reboot Into Fastbootd To Get Partition Stracture Of Dynamic Images And Erase System Image As Well As Purge Useless Images { Those Are Associated With Rui And No Need To Boot A GSI System Imge }
# 4. Rebbot Into Fastbootd Again To Sync Changes Then Flash GSI System Image As system.img
# 5. Check Weather Boot.img Is Present If Exist Flash Boot.img Else Ask From User If He Forget About Boot.img And Wait For Response Weather It Can "Y/y" For "YES" or "N/n" For "No".
# If Response Is Yes It Will Again Find boot.img And Flash That If This Time Boot.img Still Missing it Directly Denied And Move Forword..
# 6. Reboot Into Bootloader To Delete Userdata As Well As Cache And Reboot Into Recovery To Format Data From Recovery To Ensure That 100% GSI Boot..
# MADE WITH ❤️ BY FIRE7LY
# Root User Checkout...
if [[ $UID -ne 0 ]]; then
echo -e "\e[31mPlease Run This Script With Sudo...\e[0m"
exit 1
fi
# Initialise All Veriable ...
font_path="./.figlet-fonts"
tool="./bin"
# Fix Adb Issue on some devices Because repo adb tool is too way old...
get_working_sdk_tool () {
echo -e "\e[32mChecking Adb Version ...\e[0m"
adb_version=$(adb --version | grep version | awk '{print $5}')
case $adb_version in
1.0.4*)
echo -e "INFO : Installed Adb Version $adb_version Good Enough ..."
adb=$(which adb)
fastboot=$(which fastboot)
;;
*)
echo -e "INFO : Adb Version 1.0.41 Or Higher Needed But Version $adb_version Detected. \nIt May Cause To Fail 'fastboot reboot recovery' So, For Safty Switchd Adb & Fastboot From Tool"
adb="$tool/adb"
fastboot="$tool/fastboot"
# Get Sdk From Git Repo If Not Present ...
[ ! -d $tool ] && mkdir bin
[ ! -f $adb ] && echo "Adb Not Present In Tool Downloading From Git Repo" && wget -q https://github.com/Fire7ly/FUM/raw/main/tool/adb -O $adb && chmod 777 $adb
[ ! -f $fastboot ] && echo "Fastboot Not Present In Tool Downloading From Git Repo" && wget -q https://github.com/Fire7ly/FUM/raw/main/tool/fastboot -O $fastboot && chmod 777 $fastboot
;;
esac
$adb kill-server && $adb start-server
}
# Check Font Directory ...
get_font () {
if [ -d ${font_path} ]; then
[ -f ${font_path}/Bloody.flf ] && bloody="-f "Bloody" -d ${font_path}/"
else
[ ! -f ${font_path}/Bloody.flf ] && mkdir $font_path && wget -q https://github.com/xero/figlet-fonts/raw/master/Bloody.flf -O ${font_path}/Bloody.flf
fi
# Check If Packages Installed ...
if [ -f /usr/bin/lolcat ] && [ -f /usr/bin/lolcat ]; then
echo "initializing ..." | lolcat
else
apt install lolcat -y figlet -y 2>/dev/null |grep "null" | cut -d '.' -f 1
sudo ln -s $(which lolcat) /usr/bin/lolcat
fi
}
# Banner Stuff ...
banner () {
echo "Installing requirements..." | lolcat -a -d 30
figlet $bloody -w $(tput cols) -c GSIxFLASHER | lolcat
COLUMNS=$(tput cols)
d=" Todat Is : $(date +%Y-%m-%d)"
title="By Fire7ly For Realme C3"
printf "%*s\n" $(((${#title}+$COLUMNS)/2)) "$title" | lolcat
printf "%*s\n" $(((${#d}+$COLUMNS)/2)) "$d"
echo -e "\e[32mAll requirements done\e[0m"
}
get_state () {
# Check Device State ...
echo -e "\e[32mWaiting For Device Connection ...\e[0m"
device=$($adb devices -l | cut -d ':' -f 4 | grep -e RMX -e rmx -e Realme -e realme | cut -d ' ' -f 1)
state=$($adb devices | sed 's/List of devices attached//g' | grep -e recovery -e device | awk '{print $2}')
if [ -z $device ]; then
echo -e "\e[31mAdb: Device is not present in adb mode ..\e[0m\e[32m\nChecking In fastboot Mode ...\e[0m"
state=$(fastboot devices | awk '{print $2}')
else
echo Connected Device Name Is : $device
echo Connection State Is : $state mode
fi
is_devie () {
$adb wait-for-device 1>&2>/dev/null
echo -e "\e[32mAdb (device): Device Rebooted Successfully To Bootloader!\e[0m"
$adb reboot bootloader 1>&2>/dev/null
get_work
}
is_recovery () {
$adb wait-for-recovery 1>&2>/dev/null
echo -e "\e[32mAdb (recovery): Device Rebooted Successfully To Bootloader!\e[0m"
$adb reboot bootloader 1>&2>/dev/null
get_work
}
get_fastboot () {
userspace=$($fastboot getvar is-userspace 2>&1 | grep -e yes -e no | cut -d ' ' -f 2)
if [[ $userspace == "yes" ]]; then
$fastboot reboot bootloader
echo -e "\e[32mFastbootd: Device Rebooted Successfully To Bootloader!\e[0m"
get_work
elif [[ $userspace == "no" ]]; then
echo -e "\e[32mBootloader: Device Connecte Successfully!\e[0m"
get_work
else
echo "Fuck hell ..."
fi
}
}
get_work () {
$fastboot reboot fastboot
echo -e "\e[32mDevice Rebooted Successfully To Fastbooted!\e[0m"
$fastboot --disable-verification flash vbmeta vbmeta.img
echo -e "\e[32mVbmeta Flashed Successfully!\e[0m"
$fastboot erase system
echo -e "\e[32mSystem Erased!\e[0m"
# List Of Useless Partitons In Rui For Nuke Them...
useless_partitons="my_product my_engineering my_company my_carrier my_region my_heytap my_stock my_preload my_manifest"
# Loop To Delete Partition From $useless_partitons
for partition in $useless_partitons; do
$fastboot delete-logical-partition $partition
echo -e "\e[32mDelete Useless Partition $partition!\e[0m"
done
$fastboot reboot fastboot
echo -e "\e[32mDevice Successfully Rebooting Fastboot!\e[0m"
$fastboot flash system system.img
echo -e "\e[32mSystem Flashing SuccessFully!\e[0m"
if [ -f boot.img ]; then
$fastboot flash boot boot.img
echo -e "\e[32mBoot Flashing SuccessFully!\e[0m"
else
while true; do
read -p "Boot.img Is Not Present If You Missed That, Then Copy Boot.img (y/n) : " response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
[ -f "boot.img" ] && $fastboot flash boot boot.img && echo -e "\e[32mBoot Flashing SuccessFully!\e[0m"
break;
elif [[ $response =~ ^([nN][oO]|[Nn])$ ]]; then
echo -e "\e[31mYou Choise No! \nFlashing Boot.img Aborted...\e[0m"
break;
else
echo -e "\e[31mInvalid response\e[0m"
fi
done
fi
$fastboot reboot bootloader
echo -e "\e[32mDevice Successfully Rebooted To Bootloader!\e[0m"
$fastboot erase userdata
echo -e "\e[32mErased Userdata Successfully!\e[0m"
$fastboot reboot recovery
echo -e "\e[32mRebooting To recovery Format & Reboot Your Device.\e[0m"
}
main () {
get_font
banner
get_working_sdk_tool
get_state
if [[ $state = "device" ]]; then
is_device
elif [[ $state = "recovery" ]]; then
is_recovery
elif [[ $state = "fastboot" ]]; then
get_fastboot
else
echo -e "You Are Sure It It Connected ...\nelse You Fucked Up\nYou Are Dumbass\nYou are Ghay"
fi
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment