Increasing stability (#322)

* Suppressing unneeded cmds

* Parse cmdline and enable debug before downloads

* Check network connection and wait for network

* Rerun entering DFU stage after fail

* Fix tabs

* Creds

* Added DNS check, limited checks count

* ifconfig.co

* static.palera.in
This commit is contained in:
Vadim A. Yegorov authored and GitHub committed 2023-01-21 23:22:18 -05:00
1 parent ee256722d1
commit 6580820616
2 files changed
+173 -112

No files matched your search

+1 -1
View File
@@ -93,7 +93,7 @@ If you want to make a rootless repo, use the official [palera1n repo](https://gi
- Work on jbinit, together with [Nick Chan](https://github.com/asdfugil) - Work on jbinit, together with [Nick Chan](https://github.com/asdfugil)
- [Amy](https://github.com/elihwyma) for the [Pogo](https://github.com/elihwyma/Pogo) app - [Amy](https://github.com/elihwyma) for the [Pogo](https://github.com/elihwyma/Pogo) app
- [checkra1n](https://github.com/checkra1n) for the base of the kpf - [checkra1n](https://github.com/checkra1n) for the base of the kpf
- [nyuszika7h](https://github.com/nyuszika7h) for the script to help get into DFU - [nyuszika7h](https://github.com/nyuszika7h) and [Vadim Yegorov](https://github.com/vadim-a-yegorov) for the script to help get into DFU
- [the Procursus Team](https://github.com/ProcursusTeam) for the amazing [bootstrap](https://github.com/ProcursusTeam/Procursus) - [the Procursus Team](https://github.com/ProcursusTeam) for the amazing [bootstrap](https://github.com/ProcursusTeam/Procursus)
- [F121](https://github.com/F121Live) for helping test - [F121](https://github.com/F121Live) for helping test
- [m1sta](https://github.com/m1stadev) for [pyimg4](https://github.com/m1stadev/PyIMG4) - [m1sta](https://github.com/m1stadev) for [pyimg4](https://github.com/m1stadev/PyIMG4)
+172 -111
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
pushd $(dirname "$0") pushd $(dirname "$0") &> /dev/null
mkdir -p logs mkdir -p logs
set -e set -e
@@ -18,6 +18,7 @@ echo "[*] Command ran:`if [ $EUID = 0 ]; then echo " sudo"; fi` ./palera1n.sh $@
# Variables # Variables
# ========= # =========
ipsw="" # IF YOU WERE TOLD TO PUT A CUSTOM IPSW URL, PUT IT HERE. YOU CAN FIND THEM ON https://appledb.dev ipsw="" # IF YOU WERE TOLD TO PUT A CUSTOM IPSW URL, PUT IT HERE. YOU CAN FIND THEM ON https://appledb.dev
network_timeout=-1 # seconds; -1 - unlimited
version="1.4.1" version="1.4.1"
os=$(uname) os=$(uname)
dir="$(pwd)/binaries/$os" dir="$(pwd)/binaries/$os"
@@ -252,6 +253,7 @@ _wait() {
fi fi
} }
dfuhelper_first_try=true
_dfuhelper() { _dfuhelper() {
local step_one; local step_one;
deviceid=$( [ -z "$deviceid" ] && _info normal ProductType || echo $deviceid ) deviceid=$( [ -z "$deviceid" ] && _info normal ProductType || echo $deviceid )
@@ -260,35 +262,65 @@ _dfuhelper() {
else else
step_one="Hold home + power button" step_one="Hold home + power button"
fi fi
echo "[*] Press any key when ready for DFU mode" if $dfuhelper_first_try; then
read -n 1 -s echo "[*] Press any key when ready for DFU mode"
read -n 1 -s
dfuhelper_first_try=false
fi
step 3 "Get ready" step 3 "Get ready"
step 4 "$step_one" & step 4 "$step_one" &
sleep 3 sleep 3
"$dir"/irecovery -c "reset" & "$dir"/irecovery -c "reset" &
wait wait
if [[ "$1" = 0x801* && "$deviceid" != *"iPad"* ]]; then if [[ "$1" = 0x801* && "$deviceid" != *"iPad"* ]]; then
step 10 'Release side button, but keep holding volume down' step 6 'Release side button, but keep holding volume down'
else else
step 10 'Release power button, but keep holding home button' step 6 'Release power button, but keep holding home button'
fi fi
sleep 1 sleep 1
if [ "$(get_device_mode)" = "dfu" ]; then if [ "$(get_device_mode)" = "dfu" ]; then
echo "[*] Device entered DFU!" echo "[*] Device entered DFU!"
dfuhelper_first_try=true
else else
echo "[-] Device did not enter DFU mode, rerun the script and try again" echo "[-] Device did not enter DFU mode"
return -1 return -1
fi fi
} }
function _wait_for() {
timeout=$1
shift 1
until [ $timeout -eq 0 ] || ("$@" &> /dev/null); do
sleep 1
timeout=$(( timeout - 1 ))
done
if [ $timeout -eq 0 ]; then
return -1
fi
}
function _network() {
ping -q -c 1 -W 1 static.palera.in &>/dev/null
}
function _check_network_connection() {
if ! _network; then
echo "[*] Waiting for network"
if ! _wait_for $network_timeout _network; then
echo "[-] Network is unreachable. Check your connection and try again"
exit 1
fi
fi
}
_kill_if_running() { _kill_if_running() {
if (pgrep -u root -x "$1" &> /dev/null > /dev/null); then if (pgrep -u root -x "$1" &> /dev/null > /dev/null); then
# yes, it's running as root. kill it # yes, it's running as root. kill it
sudo killall $1 sudo killall $1 &> /dev/null
else else
if (pgrep -x "$1" &> /dev/null > /dev/null); then if (pgrep -x "$1" &> /dev/null > /dev/null); then
killall $1 killall $1 &> /dev/null
fi fi
fi fi
} }
@@ -311,6 +343,21 @@ trap _exit_handler EXIT
# Fixes # Fixes
# =========== # ===========
# ============
# Start
# ============
echo "palera1n | Version $version-$branch-$commit"
echo "Written by Nebula and Mineek | Some code and ramdisk from Nathan"
echo ""
version=""
parse_cmdline "$@"
if [ "$debug" = "1" ]; then
set -o xtrace
fi
# ============ # ============
# Dependencies # Dependencies
# ============ # ============
@@ -336,6 +383,9 @@ if [ -e "$dir"/gaster ]; then
fi fi
if [ ! -e "$dir"/gaster ]; then if [ ! -e "$dir"/gaster ]; then
echo '[-] gaster not installed. Press any key to install it, or press ctrl + c to cancel'
read -n 1 -s
_check_network_connection
curl -sLO https://static.palera.in/deps/gaster-"$os".zip curl -sLO https://static.palera.in/deps/gaster-"$os".zip
unzip gaster-"$os".zip unzip gaster-"$os".zip
mv gaster "$dir"/ mv gaster "$dir"/
@@ -346,6 +396,7 @@ fi
if ! python3 -c 'import pkgutil; exit(not pkgutil.find_loader("pyimg4"))'; then if ! python3 -c 'import pkgutil; exit(not pkgutil.find_loader("pyimg4"))'; then
echo '[-] pyimg4 not installed. Press any key to install it, or press ctrl + c to cancel' echo '[-] pyimg4 not installed. Press any key to install it, or press ctrl + c to cancel'
read -n 1 -s read -n 1 -s
_check_network_connection
python3 -m pip install pyimg4 python3 -m pip install pyimg4
fi fi
@@ -369,21 +420,6 @@ chmod +x "$dir"/*
# xattr -d com.apple.quarantine "$dir"/* # xattr -d com.apple.quarantine "$dir"/*
#fi #fi
# ============
# Start
# ============
echo "palera1n | Version $version-$branch-$commit"
echo "Written by Nebula and Mineek | Some code and ramdisk from Nathan"
echo ""
version=""
parse_cmdline "$@"
if [ "$debug" = "1" ]; then
set -o xtrace
fi
if [ "$clean" = "1" ]; then if [ "$clean" = "1" ]; then
rm -rf boot* work .tweaksinstalled rm -rf boot* work .tweaksinstalled
echo "[*] Removed the created boot files" echo "[*] Removed the created boot files"
@@ -423,105 +459,114 @@ if [ "$tweaks" = 1 ] && [ ! -e ".tweaksinstalled" ] && [ ! -e ".disclaimeragree"
fi fi
fi fi
# Get device's iOS version from ideviceinfo if in normal mode function _wait_for_device() {
echo "[*] Waiting for devices" # Get device's iOS version from ideviceinfo if in normal mode
while [ "$(get_device_mode)" = "none" ]; do echo "[*] Waiting for devices"
sleep 1; while [ "$(get_device_mode)" = "none" ]; do
done sleep 1;
echo $(echo "[*] Detected $(get_device_mode) mode device" | sed 's/dfu/DFU/') done
echo $(echo "[*] Detected $(get_device_mode) mode device" | sed 's/dfu/DFU/')
if grep -E 'pongo|checkra1n_stage2|diag' <<< "$(get_device_mode)"; then if grep -E 'pongo|checkra1n_stage2|diag' <<< "$(get_device_mode)"; then
echo "[-] Detected device in unsupported mode '$(get_device_mode)'" echo "[-] Detected device in unsupported mode '$(get_device_mode)'"
exit 1; exit 1;
fi
if [ "$(get_device_mode)" != "normal" ] && [ -z "$version" ] && [ "$dfuhelper" != "1" ]; then
echo "[-] You must pass the version your device is on when not starting from normal mode"
exit
fi
if [ "$(get_device_mode)" = "ramdisk" ]; then
# If a device is in ramdisk mode, perhaps iproxy is still running?
_kill_if_running iproxy
echo "[*] Rebooting device in SSH Ramdisk"
if [ "$os" = 'Linux' ]; then
sudo "$dir"/iproxy 6413 22 &
else
"$dir"/iproxy 6413 22 &
fi fi
sleep 2
remote_cmd "/usr/sbin/nvram auto-boot=false"
remote_cmd "/sbin/reboot"
_kill_if_running iproxy
_wait recovery
fi
if [ "$(get_device_mode)" = "normal" ]; then if [ "$(get_device_mode)" != "normal" ] && [ -z "$version" ] && [ "$dfuhelper" != "1" ]; then
version=${version:-$(_info normal ProductVersion)} echo "[-] You must pass the version your device is on when not starting from normal mode"
arch=$(_info normal CPUArchitecture) exit
if [ "$arch" = "arm64e" ]; then fi
if [ "$(get_device_mode)" = "ramdisk" ]; then
# If a device is in ramdisk mode, perhaps iproxy is still running?
_kill_if_running iproxy
echo "[*] Rebooting device in SSH Ramdisk"
if [ "$os" = 'Linux' ]; then
sudo "$dir"/iproxy 6413 22 &
else
"$dir"/iproxy 6413 22 &
fi
sleep 2
remote_cmd "/usr/sbin/nvram auto-boot=false"
remote_cmd "/sbin/reboot"
_kill_if_running iproxy
_wait recovery
fi
if [ "$(get_device_mode)" = "normal" ]; then
version=${version:-$(_info normal ProductVersion)}
arch=$(_info normal CPUArchitecture)
if [ "$arch" = "arm64e" ]; then
echo "[-] palera1n doesn't, and never will, work on non-checkm8 devices"
exit
fi
echo "Hello, $(_info normal ProductType) on $version!"
echo "[*] Switching device into recovery mode..."
"$dir"/ideviceenterrecovery $(_info normal UniqueDeviceID)
_wait recovery
fi
# Grab more info
echo "[*] Getting device info..."
cpid=$(_info recovery CPID)
model=$(_info recovery MODEL)
deviceid=$(_info recovery PRODUCT)
if (( 0x8020 <= cpid )) && (( cpid < 0x8720 )); then
echo "[-] palera1n doesn't, and never will, work on non-checkm8 devices" echo "[-] palera1n doesn't, and never will, work on non-checkm8 devices"
exit exit
fi fi
echo "Hello, $(_info normal ProductType) on $version!"
echo "[*] Switching device into recovery mode..." if [ "$dfuhelper" = "1" ]; then
"$dir"/ideviceenterrecovery $(_info normal UniqueDeviceID) echo "[*] Running DFU helper"
_wait recovery _dfuhelper "$cpid" || {
fi echo "[-] Failed to enter DFU mode, trying again"
sleep 3
_wait_for_device
}
exit
fi
# Grab more info if [ ! "$ipsw" = "" ]; then
echo "[*] Getting device info..." ipswurl=$ipsw
cpid=$(_info recovery CPID)
model=$(_info recovery MODEL)
deviceid=$(_info recovery PRODUCT)
if (( 0x8020 <= cpid )) && (( cpid < 0x8720 )); then
echo "[-] palera1n doesn't, and never will, work on non-checkm8 devices"
exit
fi
if [ "$dfuhelper" = "1" ]; then
echo "[*] Running DFU helper"
_dfuhelper "$cpid"
exit
fi
if [ ! "$ipsw" = "" ]; then
ipswurl=$ipsw
else
#buildid=$(curl -sL https://api.ipsw.me/v4/ipsw/$version | "$dir"/jq '.[0] | .buildid' --raw-output)
if [[ "$deviceid" == *"iPad"* ]]; then
device_os=iPadOS
device=iPad
elif [[ "$deviceid" == *"iPod"* ]]; then
device_os=iOS
device=iPod
else else
device_os=iOS #buildid=$(curl -sL https://api.ipsw.me/v4/ipsw/$version | "$dir"/jq '.[0] | .buildid' --raw-output)
device=iPhone if [[ "$deviceid" == *"iPad"* ]]; then
device_os=iPadOS
device=iPad
elif [[ "$deviceid" == *"iPod"* ]]; then
device_os=iOS
device=iPod
else
device_os=iOS
device=iPhone
fi
_check_network_connection
buildid=$(curl -sL https://api.ipsw.me/v4/ipsw/$version | "$dir"/jq '[.[] | select(.identifier | startswith("'$device'")) | .buildid][0]' --raw-output)
if [ "$buildid" == "19B75" ]; then
buildid=19B74
fi
ipswurl=$(curl -sL https://api.appledb.dev/ios/$device_os\;$buildid.json | "$dir"/jq -r .devices\[\"$deviceid\"\].ipsw)
fi fi
buildid=$(curl -sL https://api.ipsw.me/v4/ipsw/$version | "$dir"/jq '[.[] | select(.identifier | startswith("'$device'")) | .buildid][0]' --raw-output) if [ "$restorerootfs" = "1" ]; then
if [ "$buildid" == "19B75" ]; then rm -rf "blobs/"$deviceid"-"$version".der" "boot-$deviceid" work .tweaksinstalled ".fs-$deviceid"
buildid=19B74
fi fi
ipswurl=$(curl -sL https://api.appledb.dev/ios/$device_os\;$buildid.json | "$dir"/jq -r .devices\[\"$deviceid\"\].ipsw)
fi
if [ "$restorerootfs" = "1" ]; then # Have the user put the device into DFU
rm -rf "blobs/"$deviceid"-"$version".der" "boot-$deviceid" work .tweaksinstalled ".fs-$deviceid" if [ "$(get_device_mode)" != "dfu" ]; then
fi recovery_fix_auto_boot;
_dfuhelper "$cpid" || {
# Have the user put the device into DFU echo "[-] Failed to enter DFU mode, trying again"
if [ "$(get_device_mode)" != "dfu" ]; then sleep 3
recovery_fix_auto_boot; _wait_for_device
_dfuhelper "$cpid" || { }
echo "[-] failed to enter DFU mode, run palera1n.sh again" fi
exit -1 sleep 2
} }
fi _wait_for_device
sleep 2
# ============ # ============
# Ramdisk # Ramdisk
@@ -677,6 +722,9 @@ if [ ! -f blobs/"$deviceid"-"$version".der ]; then
fi fi
sleep 1 sleep 1
# Checking network connection before downloads
_check_network_connection
# download the kernel # download the kernel
echo "[*] Downloading BuildManifest" echo "[*] Downloading BuildManifest"
"$dir"/pzb -g BuildManifest.plist "$ipswurl" "$dir"/pzb -g BuildManifest.plist "$ipswurl"
@@ -773,9 +821,13 @@ if [ ! -f blobs/"$deviceid"-"$version".der ]; then
remote_cmd "mkdir -p /mnt$di/jbin/binpack /mnt$di/jbin/loader.app" remote_cmd "mkdir -p /mnt$di/jbin/binpack /mnt$di/jbin/loader.app"
sleep 1 sleep 1
# Checking network connection before downloads
_check_network_connection
# download loader # download loader
cd other/rootfs/jbin cd other/rootfs/jbin
rm -rf loader.app rm -rf loader.app
echo "[*] Downloading loader"
curl -LO https://static.palera.in/deps/loader.zip curl -LO https://static.palera.in/deps/loader.zip
unzip loader.zip -d . unzip loader.zip -d .
unzip palera1n.ipa -d . unzip palera1n.ipa -d .
@@ -784,6 +836,7 @@ if [ ! -f blobs/"$deviceid"-"$version".der ]; then
# download jbinit files # download jbinit files
rm -f jb.dylib jbinit jbloader launchd rm -f jb.dylib jbinit jbloader launchd
echo "[*] Downloading jbinit files"
curl -L https://static.palera.in/deps/rootfs.zip -o rfs.zip curl -L https://static.palera.in/deps/rootfs.zip -o rfs.zip
unzip rfs.zip -d . unzip rfs.zip -d .
unzip rootfs.zip -d . unzip rootfs.zip -d .
@@ -792,6 +845,7 @@ if [ ! -f blobs/"$deviceid"-"$version".der ]; then
# download binpack # download binpack
mkdir -p other/rootfs/jbin/binpack mkdir -p other/rootfs/jbin/binpack
echo "[*] Downloading binpack"
curl -L https://static.palera.in/binpack.tar -o other/rootfs/jbin/binpack/binpack.tar curl -L https://static.palera.in/binpack.tar -o other/rootfs/jbin/binpack/binpack.tar
sleep 1 sleep 1
@@ -837,7 +891,11 @@ if [ ! -f blobs/"$deviceid"-"$version".der ]; then
"$dir"/ideviceenterrecovery $(_info normal UniqueDeviceID) "$dir"/ideviceenterrecovery $(_info normal UniqueDeviceID)
fi fi
_wait recovery _wait recovery
_dfuhelper "$cpid" _dfuhelper "$cpid" || {
echo "[-] Failed to enter DFU mode, trying again"
sleep 3
_wait_for_device
}
sleep 2 sleep 2
fi fi
@@ -879,6 +937,9 @@ if [ ! -f boot-"$deviceid"/ibot.img4 ]; then
#"$dir"/img4tool -e -s $(pwd)/blobs/"$deviceid"-"$version".shsh2 -m work/IM4M #"$dir"/img4tool -e -s $(pwd)/blobs/"$deviceid"-"$version".shsh2 -m work/IM4M
cd work cd work
# Checking network connection before downloads
_check_network_connection
# Do payload if on iPhone 7-X # Do payload if on iPhone 7-X
if [[ "$deviceid" == iPhone9,[1-4] ]] || [[ "$deviceid" == "iPhone10,"* ]]; then if [[ "$deviceid" == iPhone9,[1-4] ]] || [[ "$deviceid" == "iPhone10,"* ]]; then
if [[ "$version" == "16.0"* ]] || [[ "$version" == "15"* ]]; then if [[ "$version" == "16.0"* ]] || [[ "$version" == "15"* ]]; then
@@ -1019,4 +1080,4 @@ echo "Enjoy!"
} 2>&1 | tee logs/${log} } 2>&1 | tee logs/${log}
popd popd &> /dev/null