#!/bin/bash

ADB="./adb"
echo
echo "**************************************************"
echo "Automated root for LG Optimus G, G2, G Pro, G Flex"
echo "Original idea by IOMonster (thecubed on XDA)"
echo "http://tinyw.in/mXhw"
echo "Original linux script and Sprint root by Shelnutt2"
echo "Original LG root backdoor idea by giantpune"
echo
echo "Current IOroot by autoprime"
echo "**************************************************"
echo
echo "**************************************************"
echo "Unlock your phone and phone screen!"
echo "Turn on airplane mode!"
echo "Press enter to continue..."
echo "**************************************************"
read -rsp $'\r\n'
echo
echo
echo
echo
echo "Waiting for ADB..."
echo "Is proper USB Debugging mode set?"
echo "Did you check phone screen for Yes/No prompt?"
echo "(select checkbox to always remember then hit yes)"
$ADB "wait-for-device"
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo "Determining model..."
Model=`$ADB shell getprop ro.product.model | tr -d '\r'`
if [[ "$Model" == "LG-LS970" || "$Model" == "LG-E975" || "$Model" == "LG-F180K" || "$Model" == "LG-F180L" || "$Model" == "LG-F180S" || "$Model" == "LG-E971" || "$Model" == "LG-E973" || "$Model" == "LG-E975K" || "$Model" == "LG-E975R" || "$Model" == "LG-E975T" || "$Model" == "LG-E976" || "$Model" == "LG-E977" ]]; then
    echo "Found a LG Optimus G!"
    echo "Creating G_security..."
    echo
    $ADB shell "echo -en \\\x0d > /sdcard/G_security"
elif [[ "$Model" == "LG-LS980" ]]; then
    echo "Found LG-LS980!"
    echo
    echo "Checking firmware version..."
    OTAVER=`$ADB shell getprop ro.lge.swversion | tr -d '\r'`
    if [[ $OTAVER == "LS980ZV7" || $OTAVER == "LS980ZV8" ]]; then
        echo "Found ZV7 or ZV8 Sprint firmware!"
        echo "Pushing SPR g2_security..."
        $ADB push g2_security_spr /sdcard/g2_security
    elif [[ $OTAVER == "LS980ZVA" ]]; then
        echo "Found ZVA Sprint firmware!"
        echo "Pushing LS980 ytiruces_1a"
        $ADB push ytiruces_1a_ls980 /sdcard/ytiruces_1a
    fi
elif [[ "$Model" == "LG-D802" || "$Model" == "LG-D805" || "$Model" == "LG-D806" ]]; then
    echo "Found LG-D802 or LG-D805 or LG-D806!"
    echo
    echo "Checking firmware version..."
    FWVER=`$ADB shell getprop ro.build.version.release | tr -d '\r'`
    if [[ $FWVER == "4.2.2" ]]; then
        echo "Found 4.2.2"
        echo "Pushing Stock Jellybean g2_security..."
        $ADB push g2_security /sdcard/g2_security
    elif [[ $FWVER == "4.4" ]]; then
        echo "Found 4.4"
        echo "Pushing nothing because it's not out yet..."
        $ADB push
    fi
elif [[ "$Model" == "LG-D800" ]]; then
    echo "Found ATT LG-D800!"
    echo
    echo "Checking OTA version..."
    OTAVER=`$ADB shell getprop ro.lge.swversion | tr -d '\r'`
    if [[ $OTAVER == "D80010d" ]]; then
        echo "Found non-OTA ATT phone!"
        echo "Pushing ATT g2_security..."
        $ADB push g2_security /sdcard/g2_security
    elif [[ $OTAVER == "D80010o" ]]; then
        echo "Found OTA ATT phone!"
        echo "Pushing ATT ytiruces_1a ..."
        $ADB push ytiruces_1a_att /sdcard/ytiruces_1a
    else
        echo
        echo
        echo "We don't have an unlock for this ATT OTA version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
    fi
elif [[ "$Model" == "LG-D801" ]]; then
    echo "Found LG-D801 phone!"
    echo
    echo "Checking Device Fingerprint"
    FINGERPRINT=`$ADB shell getprop ro.build.fingerprint | tr -d '\r'`
    CARRIER=`$ADB shell getprop ro.build.target_operator | tr -d '\r'`
    if [[ $FINGERPRINT == "lge/g2_tmo_us/g2:4.2.2/JDQ39B/D80110c.1376399304:user/release-keys" ]]; then
        echo "Found D80110c TMO phone!"
        echo "Pushing TMO g2_security..."
        $ADB push g2_security /sdcard/g2_security
    elif [[ $FINGERPRINT == "lge/g2_tmo_us/g2:4.2.2/JDQ39B/D80110g.1385543495:user/release-keys" ]]; then
        echo "Found D80110g TMO phone!"
        echo "Pushing TMO ytiruces_1a..."
        $ADB push ytiruces_1a_tmo /sdcard/ytiruces_1a
    elif [[ $CARRIER == "CLR" ]]; then
        echo "Found OTA Claro D801 phone!"
        echo "Pushing D803 ytiruces_1a ..."
        $ADB push ytiruces_1a_d803 /sdcard/ytiruces_1a
    elif [[ $CARRIER == "WND" ]]; then
        echo "Found Wind D801 phone!"
        echo "Pushing D803 ytiruces_1a ..."
        $ADB push ytiruces_1a_d803 /sdcard/ytiruces_1a
    elif [[ $CARRIER == "VTR" ]]; then
        echo "Found Videotron D801 phone!"
        echo "Pushing D803 ytiruces_1a ..."
        $ADB push ytiruces_1a_d803 /sdcard/ytiruces_1a
    else
        echo
        echo
        echo "We don't have an unlock for this D801 version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
        fi
elif [[ "$Model" == "LG-F320L" ]]; then
    echo "Found LGU F320L!"
    echo
    echo "Checking OTA version..."
    OTAVER=`$ADB shell getprop ro.lge.swversion | tr -d '\r'`
    FINGERPRINT=`$ADB shell getprop ro.build.fingerprint | tr -d '\r'`
    FWVER=`$ADB shell getprop ro.build.version.release | tr -d '\r'`
    if [[ $OTAVER == "F320L10k" ]]; then
        echo "Found LGU 10k!"
        echo "Pushing LGU g2_security..."
        $ADB push g2_security /sdcard/g2_security
    elif [[ $OTAVER == "F320L11g" ]]; then
        echo "Found LGU 11g!"
        echo "Pushing LGU ytiruces_1a ..."
        $ADB push ytiruces_1a /sdcard/ytiruces_1a
    elif [[ $OTAVER == "F320L11k" ]]; then
        echo "Found LGU 11k!"
        echo "Pushing LGU ytiruces_1a ..."
        $ADB push ytiruces_1a /sdcard/ytiruces_1a
    elif [[ $FWVER == "4.4" ]]; then
        echo "Found LGU KitKat phone!"
        echo "Pushing LGU ytiruces_1a ..."
        $ADB push ytiruces_1a_kk /mnt/shell/emulated/0/ytiruces_1a
    else
        echo
        echo
        echo "We don't have an unlock for this LGU OTA version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
    fi
elif [[ "$Carrier" == "LG-F320S" ]]; then
    echo "Found SKT phone!"
    echo
    echo "Checking OTA version..."
    OTAVER=`$ADB shell getprop ro.lge.swversion | tr -d '\r'`
    FINGERPRINT=`$ADB shell getprop ro.build.fingerprint | tr -d '\r'`
    FWVER=`$ADB shell getprop ro.build.version.release | tr -d '\r'`
    if [[ $OTAVER == "F320S10k" ]]; then
        echo "Found non-OTA SKT phone!"
        echo "Pushing SKT g2_security..."
        $ADB push g2_security /sdcard/g2_security
    elif [[ $OTAVER == "F320S11g" ]]; then
        echo "Found OTA SKT phone!"
        echo "Pushing SKT ytiruces_1a ..."
        $ADB push ytiruces_1a /sdcard/ytiruces_1a
    elif [[ $OTAVER == "F320S11k" ]]; then
        echo "Found OTA SKT phone!"
        echo "Pushing SKT ytiruces_1a ..."
        $ADB push ytiruces_1a /sdcard/ytiruces_1a
    elif [[ $FWVER == "4.4" ]]; then
        echo "Found OTA SKT phone!"
        echo "Pushing SKT ytiruces_1a ..."
        $ADB push ytiruces_1a_kk /mnt/shell/emulated/0/ytiruces_1a
    else
        echo
        echo
        echo "We don't have an unlock for this SKT OTA version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
    fi
elif [[ "$Carrier" == "LG-F320K" ]]; then
    echo "Found KT phone!"
    echo
    echo "Checking OTA version..."
    OTAVER=`$ADB shell getprop ro.lge.swversion | tr -d '\r'`
    FINGERPRINT=`$ADB shell getprop ro.build.fingerprint | tr -d '\r'`
    FWVER=`$ADB shell getprop ro.build.version.release | tr -d '\r'`
    if [[ $OTAVER == "F320K10k" ]]; then
        echo "Found non-OTA KT phone!"
        echo "Pushing KT g2_security..."
        $ADB push g2_security /sdcard/g2_security
    elif [[ $OTAVER == "F320K11g" ]]; then
        echo "Found OTA KT phone!"
        echo "Pushing KT ytiruces_1a ..."
        $ADB push ytiruces_1a /sdcard/ytiruces_1a
    elif [[ $OTAVER == "F320K11k" ]]; then
        echo "Found OTA KT phone!"
        echo "Pushing KT ytiruces_1a ..."
        $ADB push ytiruces_1a /sdcard/ytiruces_1a
    elif [[ $FWVER == "4.4" ]]; then
        echo "Found OTA KT phone!"
        echo "Pushing KT ytiruces_1a ..."
        $ADB push ytiruces_1a_kk /mnt/shell/emulated/0/ytiruces_1a
    else
        echo
        echo
        echo "We don't have an unlock for this OTA version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
    fi
elif [[ "$Model" == "LG-D803" ]]; then
    echo "Found LG-D803!"
    echo
    echo "Checking firmware version..."
    FWVER=`$ADB shell getprop ro.build.version.release | tr -d '\r'`
    if [[ $FWVER == "4.2.2" ]]; then
        echo "Found 4.2.2"
        echo "Pushing D803 ytiruces_1a ..."
        $ADB push ytiruces_1a_d803 /sdcard/ytiruces_1a
    elif [[ $FWVER == "4.4" ]]; then
        echo "Found 4.4"
        echo "Pushing nothing because it's not out yet..."
        $ADB push
    else
        echo
        echo
        echo "We don't have an unlock for this OTA version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
    fi
elif [[ "$Model" == "LG-VS980" || "$Model" == "VS980" || "$Model" == "VS980 4G" ]]; then
    echo "Found LG-VS980!"
    echo
    echo "Checking firmware version..."
    FWVER=`$ADB shell getprop ro.build.version.release | tr -d '\r'`
    SWVER=`$ADB shell getprop ro.lge.swversion | tr -d '\r'`
    if [[ $SWVER == "VS98010B" ]]; then
        echo "Found VS98010B"
        echo "Pushing VZW g2_security ..."
        $ADB push g2_security_vzw /sdcard/g2_security
    elif [[ $SWVER == "VS98011A" || $SWVER == "VS98012B" ]]; then
        echo "Found 4.2.2 OTA VZW Phone"
        echo "Pushing VRZ ytiruces_1a ..."
        $ADB push ytiruces_1a_vzw /sdcard/ytiruces_1a
    else
        echo
        echo
        echo "We don't have an unlock for this OTA version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
    fi
elif [[ "$Model" == "LG-F340K" ]]; then
    echo "Found LG-F340K!"
    echo
    echo "Checking firmware version..."
    FWVER=`$ADB shell getprop ro.build.version.release | tr -d '\r'`
    if [[ $FWVER == "4.2.2" ]]; then
        echo "Found 4.2.2"
        echo "Pushing F340 JB ytiruces_1a ..."
        $ADB push ytiruces_1a_F340JB /sdcard/ytiruces_1a
    elif [[ $FWVER == "4.4" ]]; then
        echo "Found 4.4"
        echo "Pushing nothing because it's not out yet..."
        $ADB push
    else
        echo
        echo
        echo "We don't have an unlock for this OTA version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
    fi
elif [[ "$Model" == "LG-F340L" ]]; then
    echo "Found LG-F340L!"
    echo
    echo "Checking firmware version..."
    FWVER=`$ADB shell getprop ro.build.version.release | tr -d '\r'`
    if [[ $FWVER == "4.2.2" ]]; then
        echo "Found 4.2.2"
        echo "Pushing F340 JB ytiruces_1a ..."
        $ADB push ytiruces_1a_F340JB /sdcard/ytiruces_1a
    elif [[ $FWVER == "4.4" ]]; then
        echo "Found 4.4"
        echo "Pushing nothing because it's not out yet..."
        $ADB push
    else
        echo
        echo
        echo "We don't have an unlock for this OTA version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
    fi
elif [[ "$Model" == "LG-F340S" ]]; then
    echo "Found LG-F340S!"
    echo
    echo "Checking firmware version..."
    FWVER=`$ADB shell getprop ro.build.version.release | tr -d '\r'`
    if [[ $FWVER == "4.2.2" ]]; then
        echo "Found 4.2.2"
        echo "Pushing F340 JB ytiruces_1a ..."
        $ADB push ytiruces_1a_F340JB /sdcard/ytiruces_1a
    elif [[ $FWVER == "4.4" ]]; then
        echo "Found 4.4"
        echo "Pushing nothing because it's not out yet..."
        $ADB push
    else
        echo
        echo
        echo "We don't have an unlock for this OTA version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
    fi
elif [[ "$Model" == "LG-D958" ]]; then
    echo "Found LG-D958!"
    echo
    echo "Checking firmware version..."
    FWVER=`$ADB shell getprop ro.build.version.release | tr -d '\r'`
    if [[ $FWVER == "4.2.2" ]]; then
        echo "Found 4.2.2"
        echo "Pushing ytiruces_1a ..."
        $ADB push ytiruces_1a_kk /sdcard/ytiruces_1a
    elif [[ $FWVER == "4.4" ]]; then
        echo "Found 4.4"
        echo "Pushing ytiruces_1a ..."
        $ADB push ytiruces_1a_kk /sdcard/ytiruces_1a
    else
        echo
        echo
        echo "We don't have an unlock for this OTA version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
    fi
elif [[ "$Model" == "LG-D959" ]]; then
    echo "Found LG-D959!"
    echo
    echo "Checking firmware version..."
    FWVER=`$ADB shell getprop ro.build.version.release | tr -d '\r'`
    if [[ $FWVER == "4.2.2" ]]; then
        echo "Found 4.2.2"
        echo "Pushing ytiruces_sumtz ..."
        $ADB push ytiruces_sumtz /sdcard/ytiruces_sumtz
    elif [[ $FWVER == "4.4" ]]; then
        echo "Found 4.4"
        echo "Pushing ytiruces_sumtz ..."
        $ADB push ytiruces_sumtz /sdcard/ytiruces_sumtz
    else
        echo
        echo
        echo "We don't have an unlock for this OTA version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
    fi
elif [[ "$Model" == "LG-D950" ]]; then
    echo "Found LG-D950!"
    echo
    echo "Checking firmware version..."
    FWVER=`$ADB shell getprop ro.build.version.release | tr -d '\r'`
    if [[ $FWVER == "4.2.2" ]]; then
        echo "Found 4.2.2"
        echo "Pushing ytiruces_1a ..."
        $ADB push ytiruces_1a_d950 /sdcard/ytiruces_1a
    elif [[ $FWVER == "4.4" ]]; then
        echo "Found 4.4"
        echo "Pushing ytiruces_1a ..."
        $ADB push ytiruces_1a_kk /sdcard/ytiruces_1a
    else
        echo
        echo
        echo "We don't have an unlock for this OTA version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
    fi
elif [[ "$Model" == "LG-D955" ]]; then
    echo "Found LG-D955!"
    echo
    echo "Checking firmware version..."
    FWVER=`$ADB shell getprop ro.build.version.release | tr -d '\r'`
    if [[ $FWVER == "4.2.2" ]]; then
        echo "Found 4.2.2"
        echo "Pushing ytiruces_1a ..."
        $ADB push ytiruces_1a_kk /sdcard/ytiruces_1a
    elif [[ $FWVER == "4.4" ]]; then
        echo "Found 4.4"
        echo "Pushing ytiruces_1a ..."
        $ADB push ytiruces_1a_kk /sdcard/ytiruces_1a
    else
        echo
        echo
        echo "We don't have an unlock for this OTA version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
    fi
elif [[ "$Model" == "LG-LS995" ]]; then
    echo "Found LG-LS995!"
    echo
    echo "Checking firmware version..."
    FWVER=`$ADB shell getprop ro.build.version.release | tr -d '\r'`
    if [[ $FWVER == "4.2.2" ]]; then
        echo "Found 4.2.2"
        echo "Pushing ytiruces_1a ..."
        $ADB push ytiruces_1a_ls995 /sdcard/ytiruces_1a
    elif [[ $FWVER == "4.4" ]]; then
        echo "Found 4.4"
        echo "Pushing ytiruces_1a ..."
        $ADB push ytiruces_1a_kk /sdcard/ytiruces_1a
    else
        echo
        echo
        echo "We don't have an unlock for this OTA version yet."
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        echo "Please try the manual root method or"
        echo "post your full device info in the thread"
        echo "This program will now exit."
    fi
else
    echo "No matching phone found. Full device info below."
    echo "Post device info in IOroot thread."
    $ADB shell "getprop ro.product.model"
    $ADB shell "getprop ro.build.target_operator"
    $ADB shell "getprop ro.lge.swversion"
    $ADB shell "getprop ro.build.fingerprint"
    read -rsp $'Press enter to continue...\r\n'
    exit
fi


#RootStep2
echo
echo
echo "********************************************************"
echo "This next depends on your computer/phone model..."
echo
echo "USB Connection Mode needs to be toggled."
echo "Ways to do this are listed below..."
echo
echo "1. Unplug usb cable from phone then re-plug."
echo "2. Toggle USB mode from Charge to MTP back to Charge"
echo "3. Toggle USB mode from Ethernet to MTP back to Ethernet"
echo
echo
echo "Then press ENTER to confirm ADB root..."
echo "********************************************************"
read -rsp $'\r\n'
$ADB "wait-for-device"
sleep 3
echo
echo
echo
echo
echo
echo
SHELLID=`$ADB shell id | tr -d '\r'`
if [[ $SHELLID == "uid=0(root) gid=0(root)" || $SHELLID == "uid=0(root), gid=0(root)" || $SHELLID == "uid=0(root),gid=0(root)" ]]; then
echo
echo 
echo
echo
echo
echo
echo
echo
echo "*******************************************************"
$ADB shell "getprop ro.product.model"
$ADB root
$ADB shell "id"
echo
echo "Congrats! Rooted ADB is now confirmed." 
echo "You will have a rooted ADB,but no apps on the phone will" 
echo "be able to access root functions."
echo "*PRESS ENTER* to backup EFS and continue with full root."
echo
echo
echo "PLEASE NOTE!"
echo "Continuing with full root can trip LG's rootchecker."
echo "This means your phone will show ROOTED in Download mode."
echo "You can remove root flag by flashing stock firmware..."
echo ".bin .tot or .kdz"
echo
echo "If you do not want to possibly invalidate your warranty"
echo "press CTRL+c to stop this script..."
echo "*******************************************************"
read -rsp $'\r\n'
echo
    Model=`$ADB shell getprop ro.product.model | tr -d '\r'`
    if [[ "$Model" == "LG-LS970" || "$Model" == "LG-E975" || "$Model" == "LG-F180K" || "$Model" == "LG-F180L" || "$Model" == "LG-F180S" || "$Model" == "LG-E971" || "$Model" == "LG-E973" || "$Model" == "LG-E975K" || "$Model" == "LG-E975R" || "$Model" == "LG-E975T" || "$Model" == "LG-E976" || "$Model" == "LG-E977" ]]; then
        echo "Backing up EFS!"
        $ADB shell "dd if=/dev/block/platform/msm_sdcc.1/by-name/m9kefs1 of=/sdcard/m9kefs1.img"
        $ADB shell "dd if=/dev/block/platform/msm_sdcc.1/by-name/m9kefs1 of=/sdcard/m9kefs2.img"
        $ADB shell "dd if=/dev/block/platform/msm_sdcc.1/by-name/m9kefs1 of=/sdcard/m9kefs3.img"
        $ADB pull /sdcard/m9kefs1.img
        $ADB pull /sdcard/m9kefs2.img
        $ADB pull /sdcard/m9kefs3.img
        echo "***************************************************"
        echo "EFS partitions now in ioroot folder on computer..."
        echo "They're named m9kefs1.img, m9kefs2.img and m9kefs3.img"
        echo
        echo "They will come in handy in case of an emergency."
        echo "Store them somewhere you won't lose them."
        echo
        echo "Press ENTER to finish the root process..."
        echo "***************************************************"
        read -rsp $'\r\n'    
        echo
        $ADB push busybox /data/local/tmp/busybox
        $ADB shell "chmod 755 /data/local/tmp/busybox"
        $ADB shell "/data/local/tmp/busybox mount -o remount,rw /system"
        $ADB shell "/data/local/tmp/busybox cp /data/local/tmp/busybox /system/xbin/busybox"
        $ADB push su /system/xbin/su
        #
        $ADB push Superuser.apk /system/app/Superuser.apk
        $ADB shell "chown 0.0 /system/xbin/su && chmod 06755 /system/xbin/su && chmod 655 /system/app/Superuser.apk && chmod 755 /system/xbin/busybox"
        echo "Rebooting device..."
        $ADB reboot
        echo "***************************************************"
        echo "***************************************************"
        echo "You should hopefully now be fully rooted!!"
        echo
        echo "Confirm root with Root Checker app in Play Store" 
        echo "***************************************************"
        echo "***************************************************"
        echo "Waiting for device..."
        $ADB "wait-for-device"
        echo "If still no root try manual method."
        echo "Then post any errors above into the IOroot thread.."
        echo
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        read -rsp $'Press enter to exit...\r\n'
        exit
    else
        echo
        echo "Backing up EFS!"
        $ADB shell "dd if=/dev/block/platform/msm_sdcc.1/by-name/modemst1 of=/sdcard/modemst1.img"
        $ADB shell "dd if=/dev/block/platform/msm_sdcc.1/by-name/modemst2 of=/sdcard/modemst2.img"
        $ADB pull /sdcard/modemst1.img
        $ADB pull /sdcard/modemst2.img
        echo "***************************************************"
        echo "EFS partitions now in ioroot folder on computer..."
        echo "They are named modemst1.img and modemst2.img"
        echo
        echo "They will come in handy in case of an emergency."
        echo "Store them somewhere you won't lose them."
        echo
        echo "Press ENTER to finish the root process..."
        echo "***************************************************"
        read -rsp $'\r\n'
        echo
        $ADB push busybox /data/local/tmp/busybox
        $ADB shell "chmod 755 /data/local/tmp/busybox"
        $ADB shell "/data/local/tmp/busybox mount -o remount,rw /system"
        $ADB shell "/data/local/tmp/busybox cp /data/local/tmp/busybox /system/xbin/busybox"
        $ADB push su /system/xbin/daemonsu
        $ADB shell "/data/local/tmp/busybox cp /system/xbin/daemonsu /system/xbin/su"
        #
        $ADB push install-recovery.sh /system/etc/install-recovery.sh
        $ADB push Superuser.apk /system/app/Superuser.apk
        $ADB shell "chown 0.0 /system/xbin/su && chmod 06755 /system/xbin/su && chown 0.0 /system/xbin/daemonsu && chmod 06755 /system/xbin/daemonsu && chown 0.2000 /system/etc/install-recovery.sh && chmod 755 /system/etc/install-recovery.sh && chmod 655 /system/app/Superuser.apk && chmod 755 /system/xbin/busybox"
        echo "Rebooting device..."
        $ADB reboot
        echo "***************************************************"
        echo "***************************************************"
        echo "You should hopefully now be fully rooted!!"
        echo
        echo "Confirm root with Root Checker app in Play Store"  
        echo "***************************************************"
        echo "***************************************************"
        echo "Waiting for device..."
        $ADB "wait-for-device"
        echo "If still no root try manual method."
        echo "Then post any errors above into the IOroot thread.."
        echo
        $ADB shell "getprop ro.product.model"
        $ADB shell "getprop ro.build.target_operator"
        $ADB shell "getprop ro.lge.swversion"
        $ADB shell "getprop ro.build.fingerprint"
        echo
        read -rsp $'Press enter to exit...\r\n'
        exit
    fi
else
    echo "Something went wrong. There is no rooted ADB."
    echo "Your device may not be supported."
    echo "You could try running the script again."
    echo "Report all device info list below in the IOroot thread."
    $ADB shell "getprop ro.product.model"
    $ADB shell "getprop ro.build.target_operator"
    $ADB shell "getprop ro.lge.swversion"
    $ADB shell "getprop ro.build.fingerprint"
    read -rsp $'Press enter to exit...\r\n'
    exit
fi