#!/bin/bash

if [[ $EUID -ne 0 ]]; then 
   echo "Neonra1n must be run as the root user!"
   exit 1
fi

echo 

echo Welcome to Neonra1n v5.0, the on device iOS 8.4.1 downgrader!

echo

echo DISCLAIMER!

echo 

echo The downgrade process requires you to reset your device, erasing all data. The method used to downgrade will sometimes fails at random. A DFU restore will fix any issues you may have, and overall Neonra1n works well to downgrade almost all supported devices. Neonra1n only supports semi-untethered jailbreaks. Remove your untether package if you have one, or restore your device and jailbreak with a semi-untethered jailbreak before continuing. 

echo

PS3='Select your device: '
options=("iPhone 4S" "iPhone 5" "iPod Touch 5" "iPad 2" "iPad 3" "iPad 4 WiFi" "iPad Mini WiFi" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "iPhone 4S")
            echo 

echo iPhone 4S

echo

echo Preparing your device for downgrade

echo

plutil -setvalue 6.0 -key ProductVersion /System/Library/CoreServices/SystemVersion.plist

plutil -setvalue 10A403 -key ProductBuildVersion /System/Library/CoreServices/SystemVersion.plist

echo

echo Next, you need to reboot your device. After reboot, complete the slide to upgrade screen. Once on the home screen, open the Settings app. Tap General, Software Update. Download and install the iOS 8.4.1 software update. If the update is successfull, your device will boot into iOS 8.4.1. If you can successfully activate, open the Settings app. Tap General, Reset, and Erase all Content and Settings. After reset, you will be on stock iOS 8.4.1.

echo 

read -p "Press the enter key to continue" 

reboot

break
            ;;
        "iPhone 5")
            echo iPhone 5

echo

echo Preparing your device for downgrade

echo

plutil -setvalue 6.0 -key ProductVersion /System/Library/CoreServices/SystemVersion.plist

plutil -setvalue 10A405 -key ProductBuildVersion /System/Library/CoreServices/SystemVersion.plist

echo

echo Next, you need to reboot your device. After reboot, complete the slide to upgrade screen. Once on the home screen, open the Settings app. Tap General, Software Update. Download and install the iOS 8.4.1 software update. If the update is successfull, your device will boot into iOS 8.4.1. If you can successfully activate, open the Settings app. Tap General, Reset, and Erase all Content and Settings. After reset, you will be on stock iOS 8.4.1.

echo 

read -p "Press the enter key to continue" 

reboot

break
            ;;
        "iPod Touch 5")
            echo iPod Touch 5

echo

echo Preparing your device for downgrade

echo

plutil -setvalue 6.0 -key ProductVersion /System/Library/CoreServices/SystemVersion.plist

plutil -setvalue 10A406 -key ProductBuildVersion /System/Library/CoreServices/SystemVersion.plist

echo

echo Next, you need to reboot your device. After reboot, complete the slide to upgrade screen. Once on the home screen, open the Settings app. Tap General, Software Update. Download and install the iOS 8.4.1 software update. If the update is successfull, your device will boot into iOS 8.4.1. If you can successfully activate, open the Settings app. Tap General, Reset, and Erase all Content and Settings. After reset, you will be on stock iOS 8.4.1.

echo

read -p "Press the enter key to continue" 

reboot

break
            ;;
        "iPad 2")
            echo iPad 2

echo

echo Preparing your device for downgrade

echo

plutil -setvalue 6.0 -key ProductVersion /System/Library/CoreServices/SystemVersion.plist

plutil -setvalue 10A403 -key ProductBuildVersion /System/Library/CoreServices/SystemVersion.plist

echo

echo Next, you need to reboot your device. After reboot, complete the slide to upgrade screen. Once on the home screen, open the Settings app. Tap General, Software Update. Download and install the iOS 8.4.1 software update. If the update is successfull, your device will boot into iOS 8.4.1. If you can successfully activate, open the Settings app. Tap General, Reset, and Erase all Content and Settings. After reset, you will be on stock iOS 8.4.1.

echo

read -p "Press the enter key to continue" 

reboot

break
            ;;
        "iPad 3")
            echo iPad 3

echo

echo Preparing your device for downgrade

echo

plutil -setvalue 6.0 -key ProductVersion /System/Library/CoreServices/SystemVersion.plist

plutil -setvalue 10A403 -key ProductBuildVersion /System/Library/CoreServices/SystemVersion.plist

echo

echo Next, you need to reboot your device. After reboot, complete the slide to upgrade screen. Once on the home screen, open the Settings app. Tap General, Software Update. Download and install the iOS 8.4.1 software update. If the update is successfull, your device will boot into iOS 8.4.1. If you can successfully activate, open the Settings app. Tap General, Reset, and Erase all Content and Settings. After reset, you will be on stock iOS 8.4.1. 

echo

read -p "Press the enter key to continue" 

reboot

break
            ;;
        "iPad 4 WiFi")
            echo iPad 4 WiFi

echo 

echo Preparing your device for downgrade

echo

plutil -setvalue 6.0 -key ProductVersion /System/Library/CoreServices/SystemVersion.plist

plutil -setvalue 10A407 -key ProductBuildVersion /System/Library/CoreServices/SystemVersion.plist

echo

echo Next, you need to reboot your device. After reboot, complete the slide to upgrade screen. Once on the home screen, open the Settings app. Tap General, Software Update. Download and install the iOS 8.4.1 software update. If the update is successfull, your device will boot into iOS 8.4.1. If you can successfully activate, open the Settings app. Tap General, Reset, and Erase all Content and Settings. After reset, you will be on stock iOS 8.4.1.

echo 

read -p "Press the enter key to continue" 

reboot

break
            ;;
        "iPad Mini WiFi")
            echo iPad Mini WiFi

echo

echo Preparing your device for downgrade

echo

plutil -setvalue 6.0 -key ProductVersion /System/Library/CoreServices/SystemVersion.plist

plutil -setvalue 10A406 -key ProductBuildVersion /System/Library/CoreServices/SystemVersion.plist

echo

echo Next, you need to reboot your device. After reboot, complete the slide to upgrade screen. Once on the home screen, open the Settings app. Tap General, Software Update. Download and install the iOS 8.4.1 software update. If the update is successfull, your device will boot into iOS 8.4.1. If you can successfully activate, open the Settings app. Tap General, Reset, and Erase all Content and Settings. After reset, you will be on stock iOS 8.4.1.

echo

read -p "Press the enter key to continue" 

reboot

break
            ;;                        
        "Quit")
            break
            ;;
        *) echo invalid option;;
    esac
done
