Skip to content

Commit 78a403c

Browse files
committed
fix sudo usbmuxd issue on distros that use sudo-rs
by using sudo.ws fixes issues like #919
1 parent d17b73f commit 78a403c

File tree

1 file changed

+49
-44
lines changed

1 file changed

+49
-44
lines changed

restore.sh

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,25 @@ clean() {
6262

6363
clean_sudo() {
6464
clean
65-
sudo rm -rf /tmp/futurerestore /tmp/*.json "$(dirname "$0")/tmp$$/"* "$(dirname "$0")/iP"*/ "$(dirname "$0")/tmp$$/"
66-
sudo kill $sudoloop_pid 2>/dev/null
65+
$sudo rm -rf /tmp/futurerestore /tmp/*.json "$(dirname "$0")/tmp$$/"* "$(dirname "$0")/iP"*/ "$(dirname "$0")/tmp$$/"
66+
$sudo kill $sudoloop_pid 2>/dev/null
6767
}
6868

6969
clean_usbmuxd() {
7070
clean_sudo
7171
if [[ $(ls "$(dirname "$0")" | grep -v tmp$$ | grep -c tmp) != 0 ]]; then
7272
return
7373
fi
74-
sudo killall -9 usbmuxd usbmuxd2 2>/dev/null
74+
$sudo killall -9 usbmuxd usbmuxd2 2>/dev/null
7575
sleep 1
7676
if [[ $(command -v restorecon) ]]; then
77-
sudo restorecon /var/run/usbmuxd
78-
sudo systemctl restart usbmuxd
77+
$sudo restorecon /var/run/usbmuxd
78+
$sudo systemctl restart usbmuxd
7979
fi
8080
if [[ $(command -v systemctl) ]]; then
81-
sudo systemctl restart usbmuxd
81+
$sudo systemctl restart usbmuxd
8282
elif [[ $(command -v rc-service) ]]; then
83-
sudo rc-service usbmuxd start
83+
$sudo rc-service usbmuxd start
8484
fi
8585
}
8686

@@ -436,20 +436,25 @@ set_tool_paths() {
436436
trap "clean_sudo" EXIT
437437
fi
438438
if [[ $(uname -m) == "a"* || $device_sudoloop == 1 || $live_cdusb == 1 ]]; then
439+
sudo="/usr/bin/sudo"
440+
if [[ $($sudo -V 2>&1) == "sudo-rs"* ]]; then
441+
log "sudo-rs detected. Switching to sudo.ws"
442+
sudo+=".ws"
443+
fi
439444
if [[ $live_cdusb != 1 ]]; then
440445
print "* Enter your user password when prompted"
441446
fi
442-
sudo -v
443-
(while true; do sudo -v; sleep 60; done) &
447+
$sudo -v
448+
(while true; do $sudo -v; sleep 60; done) &
444449
sudoloop_pid=$!
445-
futurerestore="sudo "
446-
gaster="sudo "
447-
idevicerestore="sudo LD_LIBRARY_PATH=$dir/lib "
448-
ipwnder="sudo "
449-
irecovery="sudo "
450-
irecovery2="sudo "
451-
irecovery3="sudo "
452-
primepwn="sudo "
450+
futurerestore="$sudo "
451+
gaster="$sudo "
452+
idevicerestore="$sudo LD_LIBRARY_PATH=$dir/lib "
453+
ipwnder="$sudo "
454+
irecovery="$sudo "
455+
irecovery2="$sudo "
456+
irecovery3="$sudo "
457+
primepwn="$sudo "
453458
if [[ ! -d $dir && $(ls ../bin/linux) ]]; then
454459
log "Running on platform: $platform ($platform_ver - $platform_arch)"
455460
error "Failed to find bin directory for $platform_arch, found $(ls -x ../bin/linux) instead." \
@@ -463,20 +468,20 @@ set_tool_paths() {
463468
fi
464469
if [[ $othertmp == 0 ]]; then
465470
if [[ $(command -v systemctl) ]]; then
466-
sudo systemctl stop usbmuxd
471+
$sudo systemctl stop usbmuxd
467472
elif [[ $(command -v rc-service) ]]; then
468-
sudo rc-service usbmuxd zap
473+
$sudo rc-service usbmuxd zap
469474
else
470-
sudo killall -9 usbmuxd usbmuxd2 2>/dev/null
475+
$sudo killall -9 usbmuxd usbmuxd2 2>/dev/null
471476
fi
472-
#sudo killall usbmuxd 2>/dev/null
477+
#$sudo killall usbmuxd 2>/dev/null
473478
#sleep 1
474479
if [[ $use_usbmuxd2 == 1 ]]; then
475480
log "Running usbmuxd2"
476-
sudo -b $dir/usbmuxd2 &>../saved/usbmuxd2.log
481+
$sudo -b $dir/usbmuxd2 &>../saved/usbmuxd2.log
477482
else
478483
log "Running usbmuxd"
479-
sudo -b $dir/usbmuxd -pf &>../saved/usbmuxd.log
484+
$sudo -b $dir/usbmuxd -pf &>../saved/usbmuxd.log
480485
fi
481486
else
482487
warn "Detected existing tmp folder(s), there might be other Legacy iOS Kit instance(s) running"
@@ -563,7 +568,7 @@ set_tool_paths() {
563568
"* Re-download Legacy iOS Kit from releases (or do a git clone/reset)"
564569
fi
565570
if [[ $device_sudoloop == 1 ]]; then
566-
sudo chmod +x $dir/*
571+
$sudo chmod +x $dir/*
567572
if [[ $? != 0 ]]; then
568573
error "Failed to set up execute permissions of binaries, cannot continue. Try to move Legacy iOS Kit somewhere else."
569574
fi
@@ -624,22 +629,22 @@ install_depends() {
624629

625630
log "Installing dependencies..."
626631
if [[ $distro == "arch" ]]; then
627-
sudo pacman -Sy --noconfirm --needed aria2 base-devel ca-certificates ca-certificates-mozilla curl git libimobiledevice openssh python sshfs udev unzip usbmuxd usbutils vim zenity zip zstd
632+
$sudo pacman -Sy --noconfirm --needed aria2 base-devel ca-certificates ca-certificates-mozilla curl git libimobiledevice openssh python sshfs udev unzip usbmuxd usbutils vim zenity zip zstd
628633
prepare_udev_rules root storage
629634

630635
elif [[ $distro == "debian" ]]; then
631636
if [[ -n $ubuntu_ver ]]; then
632-
sudo add-apt-repository -y universe
637+
$sudo add-apt-repository -y universe
633638
fi
634-
sudo apt update
635-
sudo apt install -m -y aria2 ca-certificates curl git libssl3 libzstd1 openssh-client patch python3 sshfs unzip usbmuxd usbutils xxd zenity zip zlib1g
639+
$sudo apt update
640+
$sudo apt install -m -y aria2 ca-certificates curl git libssl3 libzstd1 openssh-client patch python3 sshfs unzip usbmuxd usbutils xxd zenity zip zlib1g
636641
if [[ $(command -v systemctl 2>/dev/null) ]]; then
637-
sudo systemctl enable --now udev systemd-udevd usbmuxd 2>/dev/null
642+
$sudo systemctl enable --now udev systemd-udevd usbmuxd 2>/dev/null
638643
fi
639644

640645
elif [[ $distro == "fedora" ]]; then
641-
sudo dnf install -y aria2 ca-certificates git libimobiledevice libzstd openssl patch python3 sshfs systemd udev usbmuxd vim-common zenity zip
642-
sudo ln -sf /etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/ca-certificates.crt
646+
$sudo dnf install -y aria2 ca-certificates git libimobiledevice libzstd openssl patch python3 sshfs systemd udev usbmuxd vim-common zenity zip
647+
$sudo ln -sf /etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/ca-certificates.crt
643648
prepare_udev_rules root usbmuxd
644649

645650
elif [[ $distro == "fedora-atomic" ]]; then
@@ -650,27 +655,27 @@ install_depends() {
650655
print "* You may need to reboot to apply changes with rpm-ostree. Perform a reboot after this before running the script again."
651656

652657
elif [[ $distro == "opensuse" ]]; then
653-
sudo zypper -n install aria2 ca-certificates curl git libimobiledevice-1_0-6 libzstd1 openssl-3 patch python3 sshfs usbmuxd unzip vim zenity zip
658+
$sudo zypper -n install aria2 ca-certificates curl git libimobiledevice-1_0-6 libzstd1 openssl-3 patch python3 sshfs usbmuxd unzip vim zenity zip
654659
prepare_udev_rules usbmux usbmux # idk if this is right
655660

656661
elif [[ $distro == "gentoo" ]]; then
657-
sudo emerge -av --noreplace app-arch/zstd app-misc/ca-certificates libimobiledevice net-fs/sshfs net-misc/aria2 net-misc/curl openssh python udev unzip usbmuxd usbutils vim zenity zip
662+
$sudo emerge -av --noreplace app-arch/zstd app-misc/ca-certificates libimobiledevice net-fs/sshfs net-misc/aria2 net-misc/curl openssh python udev unzip usbmuxd usbutils vim zenity zip
658663

659664
elif [[ $distro == "void" ]]; then
660-
sudo xbps-install aria2 curl git patch openssh python3 unzip xxd zenity zip
665+
$sudo xbps-install aria2 curl git patch openssh python3 unzip xxd zenity zip
661666
fi
662667

663668
echo "$platform_ver" > "../resources/firstrun"
664669
if [[ $platform == "linux" && $distro != "fedora-atomic" ]]; then
665670
# from linux_fix and libirecovery-rules by Cryptiiiic
666671
if [[ $(command -v systemctl) ]]; then
667-
sudo systemctl enable --now systemd-udevd usbmuxd 2>/dev/null
672+
$sudo systemctl enable --now systemd-udevd usbmuxd 2>/dev/null
668673
fi
669-
sudo cp 39-libirecovery.rules /etc/udev/rules.d/39-libirecovery.rules
670-
sudo chown root:root /etc/udev/rules.d/39-libirecovery.rules
671-
sudo chmod 0644 /etc/udev/rules.d/39-libirecovery.rules
672-
sudo udevadm control --reload-rules
673-
sudo udevadm trigger -s usb
674+
$sudo cp 39-libirecovery.rules /etc/udev/rules.d/39-libirecovery.rules
675+
$sudo chown root:root /etc/udev/rules.d/39-libirecovery.rules
676+
$sudo chmod 0644 /etc/udev/rules.d/39-libirecovery.rules
677+
$sudo udevadm control --reload-rules
678+
$sudo udevadm trigger -s usb
674679
fi
675680

676681
log "Install script done! Please run the script again to proceed"
@@ -747,7 +752,7 @@ version_update() {
747752
cp resources/firstrun tmp$$ 2>/dev/null
748753
rm -r bin/ LICENSE README.md restore.sh
749754
if [[ $device_sudoloop == 1 ]]; then
750-
sudo rm -rf resources/
755+
$sudo rm -rf resources/
751756
fi
752757
rm -r resources/ 2>/dev/null
753758
mv tmp$$/Legacy-iOS-Kit/* tmp$$/Legacy-iOS-Kit/.git .
@@ -2330,7 +2335,7 @@ ipwndfu_init() {
23302335
local ipwndfu_sha1="7eb59cc50d31078fa7bbc2fddb1e76f74e43c040"
23312336
ipwndfu="ipwndfu_python3"
23322337
if [[ $device_sudoloop == 1 ]]; then
2333-
psudo="sudo"
2338+
psudo="$sudo"
23342339
fi
23352340
if [[ $platform == "macos" ]] && (( mac_majver <= 11 )); then
23362341
ipwndfu="ipwndfu"
@@ -2368,7 +2373,7 @@ device_alloc8() {
23682373
$psudo ./ipwndfu -x
23692374
tool_pwned=$?
23702375
if [[ $device_sudoloop == 1 ]]; then
2371-
sudo rm -rf __pycache__/ *.pyc libusbfinder/*.pyc usb/*.pyc usb/backend/*.pyc
2376+
$sudo rm -rf __pycache__/ *.pyc libusbfinder/*.pyc usb/*.pyc usb/backend/*.pyc
23722377
fi
23732378
popd >/dev/null
23742379

@@ -2390,7 +2395,7 @@ device_ipwndfu() {
23902395
$psudo ./ipwndfu -p
23912396
tool_pwned=$?
23922397
if [[ $device_sudoloop == 1 ]]; then
2393-
sudo rm -rf __pycache__/ *.pyc libusbfinder/*.pyc usb/*.pyc usb/backend/*.pyc
2398+
$sudo rm -rf __pycache__/ *.pyc libusbfinder/*.pyc usb/*.pyc usb/backend/*.pyc
23942399
fi
23952400
popd >/dev/null
23962401

0 commit comments

Comments
 (0)