Skip to content

Commit

Permalink
remove device detection , add customCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefino9488 committed Jun 10, 2024
1 parent 0ba49db commit 225ceb9
Showing 1 changed file with 39 additions and 45 deletions.
84 changes: 39 additions & 45 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ clear
echo "========================================================"
echo " Fastboot Flasher"
echo "========================================================"
echo " Connect your device in fastboot mode."
echo "--------------------------------------------------------"
echo "Waiting for device..."
SCRIPT_PATH=$(dirname "$(readlink -f "$0")")
fastboot=tools/linux/platform-tools/fastboot
[ ! -f $fastboot ] && echo "$fastboot not found." && exit 1
Expand All @@ -17,38 +14,17 @@ if [ ! -d "$SCRIPT_PATH/images" ]; then
fi
imagesPath="$SCRIPT_PATH/images"

wait_for_device() {
device=$($fastboot getvar product 2>&1 | grep -F "product:" | tr -s " " | cut -d " " -f 2)

if [ -z "$device" ]; then
echo "No device detected. Waiting for device..."
sleep 5
wait_for_device
fi

if [ "$device" != "xaga" ] && [ "$device" != "xagapro" ] && [ "$device" != "xagain" ]; then
echo "Compatible devices: xaga, xagapro, xagain"
echo "Your device: $device"
read -p "Press any key to exit..." -n1 -s
exit 1
fi
}

wait_for_device

main_menu() {
clear
echo "========================================================"
echo " Fastboot Flasher"
echo "========================================================"
echo " Device detected: $device"
echo "--------------------------------------------------------"
echo "Main Menu:"
echo "1. Flash ROM"
echo "2. Additional Options"
echo "3. Exit / Reboot"
echo "========================================================"
read -p "Enter your choice (1/2/3): " option
read -rp "Enter your choice (1/2/3): " option
echo

case $option in
Expand All @@ -59,9 +35,9 @@ main_menu() {
additional_options
;;
3)
fastboot reboot
$fastboot reboot
echo "Exiting script."
read -p "Press any key to exit..." -n1 -s
read -rp "Press any key to exit..." -n1 -s
exit
;;
*)
Expand All @@ -73,12 +49,12 @@ main_menu() {

flash_rom() {
echo "Do you want to format data? (Y/N)"
read -p "" formatData
read -rp "" formatData

if [[ "$formatData" =~ ^[Yy]$ ]]; then
echo "Formatting data..."
fastboot erase metadata
fastboot erase userdata
$fastboot erase metadata
$fastboot erase userdata
echo "Data formatted successfully."
else
echo "Skipping data formatting."
Expand All @@ -89,7 +65,7 @@ flash_rom() {
echo "2. Default [boot.img]"
echo
echo "Select boot image type:"
read -p "" bootChoice
read -rp "" bootChoice
echo

case $bootChoice in
Expand All @@ -112,12 +88,12 @@ flash_rom() {
echo "Verifying critical images..."
if [ ! -f "boot.img" ]; then
echo "boot.img is missing. Aborting."
read -p "Press any key to return to main menu..." -n1 -s
read -rp "Press any key to return to main menu..." -n1 -s
main_menu
fi
if [ ! -f "vendor_boot.img" ]; then
echo "vendor_boot.img is missing. Aborting."
read -p "Press any key to return to main menu..." -n1 -s
read -rp "Press any key to return to main menu..." -n1 -s
main_menu
fi

Expand All @@ -136,10 +112,10 @@ flash_rom() {
echo
echo "Some required images are missing. Do you want to continue anyway?"
echo 'Type "yes" to continue.'
read -p "" continue
read -rp "" continue
if [ "$continue" != "yes" ]; then
echo "Returning to main menu."
read -p "Press any key to return to main menu..." -n1 -s
read -rp "Press any key to return to main menu..." -n1 -s
main_menu
fi
fi
Expand Down Expand Up @@ -167,7 +143,7 @@ flash_rom() {
echo "Slot a activated successfully."

echo "Press Enter to reboot and return to main menu."
read -p "" -n1 -s
read -rp "" -n1 -s
$fastboot reboot
main_menu
}
Expand All @@ -180,9 +156,10 @@ additional_options() {
echo "1. Flash Boot Image"
echo "2. Flash Vendor Boot"
echo "3. Format Data"
echo "4. Return to Main Menu"
echo "4. Custom Command"
echo "5. Return to Main Menu"
echo "========================================================"
read -p "Enter your choice (1/2/3/4): " option
read -rp "Enter your choice (1/2/3/4/5): " option
echo

case $option in
Expand All @@ -196,6 +173,9 @@ additional_options() {
format_data
;;
4)
custom_command
;;
5)
main_menu
;;
*)
Expand All @@ -211,7 +191,7 @@ flash_boot() {
echo "2. Default [boot.img]"
echo
echo "Select boot image type:"
read -p "" bootChoice
read -rp "" bootChoice
echo

case $bootChoice in
Expand All @@ -238,7 +218,7 @@ flash_boot() {
echo "$bootImage not found."
fi

read -p "Press any key to return to additional options..." -n1 -s
read -rp "Press any key to return to additional options..." -n1 -s
additional_options
}

Expand All @@ -248,7 +228,7 @@ flash_vendor_boot() {
echo "2. TWRP Vendor Boot [twrp_vendor_boot.img]"
echo
echo "Select vendor boot image type:"
read -p "" vendorBootChoice
read -rp "" vendorBootChoice
echo

case $vendorBootChoice in
Expand All @@ -275,7 +255,7 @@ flash_vendor_boot() {
echo "$vendorBootImage not found."
fi

read -p "Press any key to return to additional options..." -n1 -s
read -rp "Press any key to return to additional options..." -n1 -s
additional_options
}

Expand All @@ -284,9 +264,23 @@ format_data() {
$fastboot erase metadata
$fastboot erase userdata
echo "Data formatted successfully."
read -p "Press any key to return to additional options..." -n1 -s
read -rp "Press any key to return to additional options..." -n1 -s
additional_options
}

custom_command() {
echo "Enter the command you want to execute:"
read -rp "" customCommand
echo

if [[ "$customCommand" == fastboot* ]]; then
customCommand="$fastboot ${customCommand#fastboot}"
fi

echo "Executing command: $customCommand"
eval "$customCommand"
read -rp "Press any key to return to additional options..." -n1 -s
additional_options
}

main_menu
# End of script
main_menu

0 comments on commit 225ceb9

Please sign in to comment.