-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiosctl.sh
803 lines (691 loc) · 29.5 KB
/
iosctl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
#!/bin/sh
# iosctl.sh - A Linux-based command-line utility for managing iOS devices.
#
# Copyright (C) 2025 Davide Celentano
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
CURRENT_DIR=$(pwd)
VENV_DIR="./resources/python/pymobiledevice3"
BACKUP_BASE_DIR="$CURRENT_DIR/resources/backups"
# Function: Display header
display_header() {
clear
printf "\n"
printf " _ ___ __ ___ _ _ \n"
printf "(_) /___\\/ _\\ / __\\___ _ __ | |_ _ __ ___ | |\n"
printf "| |// //\\ \\ / / / _ \\| '_ \\| __| '__/ _ \\| |\n"
printf "| / \\_// _\\ \\ / /__| (_) | | | | |_| | | (_) | |\n"
printf "|_\\___/ \\__/ \\____/\\___/|_| |_|\\__|_| \\___/|_|\n"
printf " \n"
}
# Function: Initialize Usbmuxd service
init_usbmuxd() {
echo '[+] Starting Usbmuxd service ...'
if ! systemctl is-active --quiet usbmuxd; then
systemctl start usbmuxd || {
printf "[-] ERROR: Failed to start usbmuxd service. Please check the service status.\n" >&2
exit 1
}
fi
}
# Function: Initialize resources
init_resources() {
echo '[+] Loading resources ...'
if ! jq --version >/dev/null 2>&1; then
printf " [-] ERROR: jq is not installed on the system.\n" >&2
exit 1
fi
if ! python --version >/dev/null 2>&1; then
printf " [-] ERROR: Python is not installed on the system.\n" >&2
exit 1
fi
# Define the required directory structure
local resources_dir="./resources"
local backups_dir="$resources_dir/backups"
local python_dir="$resources_dir/python"
# Check if the resources folder exists, if not, create it
if [ ! -d "$resources_dir" ]; then
mkdir -p "$resources_dir" || {
printf " [-] ERROR: Failed to create the '.resources/' folder.\n" >&2
exit 1
}
fi
# Check if the backups folder exists, if not, create it
if [ ! -d "$backups_dir" ]; then
mkdir -p "$backups_dir" || {
printf " [-] ERROR: Failed to create the './resources/backups/' folder.\n" >&2
exit 1
}
fi
# Check if the python folder exists, if not, create it
if [ ! -d "$python_dir" ]; then
mkdir -p "$python_dir" || {
printf " [-] ERROR: Failed to create the './resources/python' folder.\n" >&2
exit 1
}
fi
}
# Function: Activate Python virtual environment
init_python_venv() {
echo '[+] Setting up Python venv ...'
# Check if the virtual environment exists
if [ ! -d "$VENV_DIR" ]; then
python -m venv "$VENV_DIR" || {
printf " [-] ERROR: Failed to create Python virtual environment.\n" >&2
exit 1
}
fi
# Activate the virtual environment
source "$VENV_DIR/bin/activate"
if [ -z "$VIRTUAL_ENV" ]; then
printf " [-] ERROR: Failed to activate Python virtual environment.\n" >&2
exit 1
fi
# Update pymobiledevice3
echo " [+] Updating pymobiledevice3 ..."
if ! python3 -m pip install -U pymobiledevice3 >/dev/null 2>&1; then
printf " [-] WARNING: Failed to update pymobiledevice3. Please check your network connection and ensure you have installed 'python3-devel' package.\n" >&2
fi
}
# Function: Initialize device info
init_device_info() {
echo "[+] Retrieving device info ..."
echo " [!] IMPORTANT : Device must be unlocked"
pymobiledevice3 lockdown pair >/dev/null 2>&1
DEVICE_NAME=$(pymobiledevice3 lockdown device-name 2>&1)
if printf "%s" "$DEVICE_NAME" | grep -q "pymobiledevice3."; then
echo "[-] ERROR: Device not detected. Is the device in Recovery or DFU mode?"
echo "1. Yes"
echo "2. No"
echo "3. Exit"
printf "Enter your choice: "
read -r recovery_choice
case $recovery_choice in
1)
while true; do
display_header
echo "[+] Device is in Recovery/DFU mode."
echo "[!] IMPORTANT: Ensure that 'libusb' package is installed on your system."
echo "[+] Choose one of the following actions:"
echo "1. Exit from Recovery"
echo "2. Software Update"
echo "3. Restore Device"
echo "0. Exit"
printf "Enter your choice: "
read -r mode_choice
case $mode_choice in
1)
echo "[+] Exiting Recovery mode ..."
# Deactivate the virtual environment
deactivate 2>/dev/null || true
# Run the recovery exit command as sudo
if sudo bash -c "
source \"$VENV_DIR/bin/activate\" &&
pymobiledevice3 restore exit
"; then
echo "[+] Device successfully exited Recovery mode."
exit 1
else
echo "[-] ERROR: Failed to exit Recovery mode. Please check the device connection." >&2
exit 1
fi
;;
2)
software_update_menu # Reuse the software_update_menu function
return
;;
3)
restore_device_menu # Call the existing restore device menu function
return
;;
0)
exit 1 # Go back to the main menu
;;
*)
echo "[-] ERROR: Invalid choice. Please try again." >&2
;;
esac
done
;;
2)
display_header
init_usbmuxd
init_resources
init_python_venv
init_device_info
;;
3)
echo "[+] Exiting." >&2
exit 1
;;
*)
echo "[-] ERROR: Invalid choice. Exiting." >&2
exit 1
;;
esac
fi
# Retrieve device diagnostics
DEVICE_INFO=$(pymobiledevice3 lockdown info 2>&1)
if printf "%s" "$DEVICE_INFO" | grep -q "pymobiledevice3."; then
printf "[-] ERROR: %s\n" "$DEVICE_INFO" >&2
exit 1
fi
# Parse device info
PRODUCT_TYPE=$(printf "%s" "$DEVICE_INFO" | jq -r '.ProductType // "N/A"')
PRODUCT_VERSION=$(printf "%s" "$DEVICE_INFO" | jq -r '.ProductVersion // "N/A"')
HARDWARE_MODEL=$(printf "%s" "$DEVICE_INFO" | jq -r '.HardwareModel // "N/A"')
PHONE_NUMBER=$(printf "%s" "$DEVICE_INFO" | jq -r '.PhoneNumber // "N/A"')
SERIAL_NUMBER=$(printf "%s" "$DEVICE_INFO" | jq -r '.SerialNumber // "N/A"')
UNIQUE_DEVICE_ID=$(printf "%s" "$DEVICE_INFO" | jq -r '.UniqueDeviceID // "N/A"')
# Parse ModelNumber and RegionInfo to form MODEL_NUMBER
MODEL_NUMBER=$(printf "%s" "$DEVICE_INFO" | jq -r '.ModelNumber // empty')
REGION_INFO=$(printf "%s" "$DEVICE_INFO" | jq -r '.RegionInfo // empty')
if [[ -n "$MODEL_NUMBER" && -n "$REGION_INFO" ]]; then
MODEL_NUMBER="${MODEL_NUMBER}${REGION_INFO}"
else
MODEL_NUMBER="N/A"
fi
# Retrieve additional information
find_latest_backup
check_encryption_status
}
# Function: Find latest backup
find_latest_backup() {
LAST_BACKUP_FILE=""
LAST_BACKUP_TIME=0
# Define the path to search for Status.plist specific to the UNIQUE_DEVICE_ID
DEVICE_BACKUP_DIR="$BACKUP_BASE_DIR/$UNIQUE_DEVICE_ID"
# Check if the directory for the specific device exists
if [[ -d "$DEVICE_BACKUP_DIR" ]]; then
# Search for the most recent Status.plist file
while IFS= read -r -d '' status_plist_file; do
# Get the modification time of the Status.plist file
plist_file_date=$(stat -c %Y "$status_plist_file")
if [[ $plist_file_date -gt $LAST_BACKUP_TIME ]]; then
LAST_BACKUP_FILE="$status_plist_file"
LAST_BACKUP_TIME=$plist_file_date
fi
done < <(find "$DEVICE_BACKUP_DIR" -type f -name "Status.plist" -print0)
# If no Status.plist file is found, show the default message
if [[ -z "$LAST_BACKUP_FILE" ]]; then
LAST_BACKUP_TIME="Your device has never been backed up to this computer."
else
# If a Status.plist file is found, format the date
LAST_BACKUP_TIME=$(date -d "@$LAST_BACKUP_TIME" "+%Y-%m-%d %H:%M:%S")
LAST_BACKUP_TIME=$(printf "%s to this computer." "$LAST_BACKUP_TIME")
fi
else
# If the backup directory does not exist, show the default message
LAST_BACKUP_TIME="Your device has never been backed up to this computer."
fi
}
# Function: Check encryption status
check_encryption_status() {
ENCRY_STAT_OUTPUT=$(pymobiledevice3 backup2 change-password EncryptionChecker999! EncryptionChecker999! 2>&1)
if printf "%s" "$ENCRY_STAT_OUTPUT" | grep -q "Encryption is not turned on!"; then
ENCRY_STAT="OFF"
else
ENCRY_STAT="ON"
fi
}
# Function: Display device info
display_device_info() {
printf "\n"
printf "############################################\n"
printf "%s\n" "$DEVICE_NAME"
printf "%s\n" "$PRODUCT_TYPE"
printf "iOS %s\n" "$PRODUCT_VERSION"
printf "\n"
printf "Hardware Model: %s\n" "$HARDWARE_MODEL"
printf "Phone Number: %s\n" "$PHONE_NUMBER"
printf "Model Number: %s\n" "$MODEL_NUMBER"
printf "Serial Number: %s\n" "$SERIAL_NUMBER"
printf "Unique Device ID: %s\n" "$UNIQUE_DEVICE_ID"
printf "\n"
printf "Latest Backup: %s\n" "$LAST_BACKUP_TIME"
printf "Encrypt local backup: %s\n" "$ENCRY_STAT"
printf "############################################\n"
printf "\n"
}
# Function: Software Update menu
software_update_menu() {
while true; do
display_header
echo "[+] Chosen Software Update ..."
echo "[!] IMPORTANT: It is HIGHLY recommended to perform this operation while the device is in Recovery Mode."
echo "1. Perform Software Update"
echo "2. Enter in Recovery"
echo "0. Go Back to Main Menu"
printf "Enter your choice: "
read -r update_choice
case $update_choice in
1)
display_header
echo "[+] Starting Software Update ..."
printf "[+] Download signed iOS firmware for your device from https://ipsw.me (https://ipsw.dev for Beta Releases), then paste here the full path to file:\n"
# Prompt for firmware file path
read -r fw_update_path
# Ensure the path is not empty
if [[ -z "$fw_update_path" ]]; then
echo "[-] ERROR: Firmware path cannot be empty. Please try again."
continue
fi
# Exit from the virtual environment
deactivate 2>/dev/null || true
# Run the command as sudo with the virtual environment reloaded
sudo bash -c "
source \"$VENV_DIR/bin/activate\" &&
pymobiledevice3 restore update --ipsw \"$fw_update_path\"
"
# Notify user that the update process has completed
echo "[+] Software update process has finished. Please check the above output for any errors."
# Exit the script
exit 1
;;
2)
display_header
echo "[+] Booting into Recovery mode ..."
# Exit from the virtual environment
deactivate 2>/dev/null || true
# Run the recovery enter command as sudo
if sudo bash -c "
source \"$VENV_DIR/bin/activate\" &&
pymobiledevice3 restore enter
"; then
echo "[+] Device successfully booted into Recovery mode."
exit 1
else
echo "[-] ERROR: Failed to boot into Recovery mode. Please check the device connection." >&2
exit 1
fi
;;
0)
return # Go back to main menu
;;
*)
echo "[-] ERROR: Invalid choice. Please try again." >&2
;;
esac
done
}
# Function: Restore Device menu
restore_device_menu() {
while true; do
display_header
echo "[+] Chosen Restore Device ..."
echo "[!] IMPORTANT 1: Find My iPhone must be disabled before restoring."
echo "[!] IMPORTANT 2: Your device will be FACTORY-RESET."
echo "[!] IMPORTANT 3: It is HIGHLY recommended to perform this operation while the device is in Recovery Mode."
echo "1. Perform Restore"
echo "2. Enter in Recovery"
echo "0. Go Back to Main Menu"
printf "Enter your choice: "
read -r restore_choice
case $restore_choice in
1)
display_header
echo "[+] Starting Restore Process ..."
printf "[+] Download signed iOS firmware for your device from https://ipsw.me (https://ipsw.dev for Beta Releases), then paste here the full path to file:\n"
# Prompt for firmware file path
read -r firmware_path
# Ensure the path is not empty
if [[ -z "$firmware_path" ]]; then
echo "[-] ERROR: Firmware path cannot be empty. Please try again."
continue
fi
# Deactivate virtual environment
deactivate 2>/dev/null || true
# Run the restore command as sudo
sudo bash -c "
source \"$VENV_DIR/bin/activate\" &&
pymobiledevice3 restore update --ipsw \"$firmware_path\" --erase
"
# Notify user of completion and exit the script
echo "[+] Restore process has finished. Please check the above output for any errors."
exit 1
;;
2)
display_header
echo "[+] Booting into Recovery mode ..."
# Deactivate virtual environment
deactivate 2>/dev/null || true
# Run the recovery enter command as sudo
if sudo bash -c "
source \"$VENV_DIR/bin/activate\" &&
pymobiledevice3 restore enter
"; then
echo "[+] Device successfully booted into Recovery mode."
exit 1
else
echo "[-] ERROR: Failed to boot into Recovery mode. Please check the device connection." >&2
exit 1
fi
;;
0)
return # Go back to the main menu
;;
*)
echo "[-] ERROR: Invalid choice. Please try again." >&2
;;
esac
done
}
# Function: Encryption settings menu
encryption_settings_menu() {
display_header
echo "[+] Chosen Encryption Settings ..."
printf "[+] This will allow account passwords, Health, and HomeKit data to be backed up.\n\n"
if [[ "$ENCRY_STAT" == "OFF" ]]; then
echo "Encryption is currently OFF. Please choose an option:"
echo "1. Enable Encryption"
echo "0. Go Back to Main Menu"
printf "Enter your choice: "
read -r enc_choice
case $enc_choice in
1)
display_header
echo "[+] Enabling Encryption..."
printf "Please enter a password for encryption: "
read -rs enc_password
echo
if output=$(pymobiledevice3 backup2 encryption on "$enc_password" 2>&1); then
if [[ -z "$output" ]]; then
echo "[+] Encryption has been enabled successfully."
else
echo "[-] ERROR: $output" >&2
fi
else
echo "[-] ERROR: An unexpected error occurred while enabling encryption." >&2
fi
;;
0) return ;; # Return to main menu
*)
echo "[-] ERROR: Invalid choice. Please try again." >&2
;;
esac
else
echo "Encryption is currently ON. Please choose an option:"
echo "1. Disable Encryption"
echo "2. Change Encryption Password"
echo "0. Go Back to Main Menu"
printf "Enter your choice: "
read -r enc_choice
case $enc_choice in
1)
display_header
echo "[+] Disabling Encryption..."
printf "Please enter the current encryption password: "
read -rs enc_password
echo
if output=$(pymobiledevice3 backup2 encryption off "$enc_password" 2>&1); then
if [[ -z "$output" ]]; then
echo "[+] Encryption has been disabled successfully."
else
echo "[-] ERROR: $output" >&2
fi
else
echo "[-] ERROR: An unexpected error occurred while disabling encryption." >&2
fi
;;
2)
display_header
echo "[+] Changing Encryption Password..."
printf "Please enter the current encryption password: "
read -rs current_password
echo
printf "Please enter a new encryption password: "
read -rs new_password
echo
if output=$(pymobiledevice3 backup2 change-password "$current_password" "$new_password" 2>&1); then
if [[ -z "$output" ]]; then
echo "[+] Encryption password has been updated successfully."
else
echo "[-] ERROR: $output" >&2
fi
else
echo "[-] ERROR: An unexpected error occurred while changing encryption password." >&2
fi
;;
0) return ;; # Return to main menu
*)
echo "[-] ERROR: Invalid choice. Please try again." >&2
;;
esac
fi
printf "\nPress any key to go back to Main Menu."
read -rn1
return # Redirect to main menu
}
# Function: Backup Now menu
backup_now_menu() {
while true; do
display_header
echo "[+] Chosen Backup Now ..."
echo "[+] Latest Backup: $LAST_BACKUP_TIME"
BACKUP_DIR="$BACKUP_BASE_DIR/"
if [[ "$LAST_BACKUP_TIME" == *"never"* ]]; then
# Only full backup is allowed if there's no previous backup
echo "1. Start Full Backup"
echo "0. Go Back to Main Menu"
printf "Enter your choice: "
read -r backup_choice
case $backup_choice in
1)
display_header
echo "[+] Starting Full Backup ..."
# Run the full backup command
pymobiledevice3 backup2 backup "$BACKUP_DIR" --full
# Notify user that the backup has finished
echo "[+] Full backup process has finished."
echo "[+] Ignore any backup_manifest.db related error: https://github.com/doronz88/pymobiledevice3/issues/755"
printf "\nPress any key to go back to Main Menu."
read -rn1
return # Return to main menu
;;
0) return ;; # Go back to main menu
*)
echo "[-] ERROR: Invalid choice. Please try again." >&2
;;
esac
else
# Both full and delta backups are available
echo "1. Start Full Backup"
echo "2. Sync Now (Delta)"
echo "0. Go Back to Main Menu"
printf "Enter your choice: "
read -r backup_choice
case $backup_choice in
1)
display_header
echo "[+] Starting Full Backup ..."
# Run the full backup command
pymobiledevice3 backup2 backup "$BACKUP_DIR" --full --udid $UNIQUE_DEVICE_ID
# Notify user that the backup has finished
echo "[+] Full backup process has finished."
echo "[+] Ignore any backup_manifest.db related error: https://github.com/doronz88/pymobiledevice3/issues/755"
printf "\nPress any key to go back to Main Menu."
read -rn1
return # Return to main menu
;;
2)
display_header
echo "[+] Starting Delta Sync ..."
# Run the delta backup command
pymobiledevice3 backup2 backup "$BACKUP_DIR" --udid $UNIQUE_DEVICE_ID
# Notify user that the sync has finished
echo "[+] Delta sync process has finished."
echo "[+] Ignore any backup_manifest.db related error: https://github.com/doronz88/pymobiledevice3/issues/755"
printf "\nPress any key to go back to Main Menu."
read -rn1
return # Return to main menu
;;
0) return ;; # Go back to main menu
*)
echo "[-] ERROR: Invalid choice. Please try again." >&2
;;
esac
fi
done
}
# Function: Restore Backup menu
restore_backup_menu() {
while true; do
display_header
echo "[+] Chosen Restore Backup ..."
echo "[!] IMPORTANT: Find My iPhone must be disabled before restoring."
echo "1. Restore Backup"
echo "2. Restore Encrypted Backup"
echo "3. Restore Backup from Other Device"
echo "4. Restore Encrypted Backup from Other Device"
echo "0. Go Back to Main Menu"
printf "Enter your choice: "
read -r restore_choice
case $restore_choice in
1)
display_header
echo "[+] Starting Restore Process ..."
# Define the backup directory
BACKUP_DIR="$BACKUP_BASE_DIR/"
echo "[+] Restoring backup from $BACKUP_DIR ..."
# Run the restore command and display output
pymobiledevice3 backup2 restore "$BACKUP_DIR" --system --settings --source "$UNIQUE_DEVICE_ID"
# Notify user that the restore process has completed
echo "[+] Restore process has finished. Please check the above output for any errors."
printf "\nPress any key to go back to Main Menu."
read -rn1
return # Return to main menu
;;
2)
display_header
echo "[+] Starting Restore Process (Encrypted Backup) ..."
# Define the backup directory
BACKUP_DIR="$BACKUP_BASE_DIR/"
echo "[+] Restoring encrypted backup from $BACKUP_DIR ..."
# Prompt the user for the encryption password
printf "Please enter the encryption password: "
read -rs enc_password
echo
# Run the restore command with the password and display output
pymobiledevice3 backup2 restore "$BACKUP_DIR" --system --settings --password "$enc_password" --source "$UNIQUE_DEVICE_ID"
# Notify user that the restore process has completed
echo "[+] Encrypted restore process has finished. Please check the above output for any errors."
printf "\nPress any key to go back to Main Menu."
read -rn1
return # Return to main menu
;;
3)
display_header
echo "[+] Starting Restore Process (Backup from Other Device) ..."
# Prompt the user for the original device UDID
echo "[+] The available backups are stored in the following directory: $BACKUP_BASE_DIR"
echo "[+] Each folder is named with the device's UDID."
printf "Please paste the UDID of the original device backup to restore from: "
read -r source_udid
# Ensure the source UDID is not empty
if [[ -z "$source_udid" ]]; then
echo "[-] ERROR: UDID cannot be empty. Please try again."
continue
fi
# Define the backup directory
BACKUP_DIR="$BACKUP_BASE_DIR"
echo "[+] Restoring backup from $BACKUP_DIR (source: $source_udid) ..."
# Run the restore command and display output
pymobiledevice3 backup2 restore --system --settings --source "$source_udid" "$BACKUP_DIR"
# Notify user that the restore process has completed
echo "[+] Restore process has finished. Please check the above output for any errors."
printf "\nPress any key to go back to Main Menu."
read -rn1
return # Return to main menu
;;
4)
display_header
echo "[+] Starting Restore Process (Encrypted Backup from Other Device) ..."
# Prompt the user for the original device UDID
echo "[+] The available backups are stored in the following directory: $BACKUP_BASE_DIR"
echo "[+] Each folder is named with the device's UDID."
printf "Please paste the UDID of the original device backup to restore from: "
read -r source_udid
# Ensure the source UDID is not empty
if [[ -z "$source_udid" ]]; then
echo "[-] ERROR: UDID cannot be empty. Please try again."
continue
fi
# Prompt the user for the encryption password
printf "Please enter the encryption password: "
read -rs enc_password
echo
# Define the backup directory
BACKUP_DIR="$BACKUP_BASE_DIR"
echo "[+] Restoring encrypted backup from $BACKUP_DIR (source: $source_udid) ..."
# Run the restore command with the password and display output
pymobiledevice3 backup2 restore --system --settings --source "$source_udid" --password "$enc_password" "$BACKUP_DIR"
# Notify user that the restore process has completed
echo "[+] Encrypted restore process has finished. Please check the above output for any errors."
printf "\nPress any key to go back to Main Menu."
read -rn1
return # Return to main menu
;;
0)
return # Go back to main menu
;;
*)
echo "[-] ERROR: Invalid choice. Please try again." >&2
;;
esac
done
}
# Function: Enable Developer Mode
enable_developer_mode() {
display_header
echo "[+] Chosen Enable Developer Mode ..."
echo "[!] IMPORTANT: iPhone passcode must be disabled before enabling Developer Mode."
pymobiledevice3 amfi enable-developer-mode
echo "[+] Enable Developer Mode command has been executed. Please check the above output for any errors."
printf "\nPress any key to go back to Main Menu."
read -rn1
return
}
# Main menu
main_menu() {
while true; do
display_header
display_device_info
printf "Select an option from the following functionalities:\n"
printf "1. Software Update\n"
printf "2. Restore Device\n"
printf "3. Encryption Settings\n"
printf "4. Backup Now\n"
printf "5. Restore Backup\n"
printf "6. Enable Developer Mode\n"
printf "0. Exit\n\n"
printf "Enter your choice: "
read -r choice
case $choice in
1) software_update_menu ;;
2) restore_device_menu ;;
3) encryption_settings_menu ;;
4) backup_now_menu ;;
5) restore_backup_menu ;;
6) enable_developer_mode ;;
0) echo "[+] Exiting. Goodbye!"; break ;;
*) printf "[-] ERROR: Invalid choice. Try again.\n" >&2 ;;
esac
# Reload device info after each operation
init_device_info
done
}
# Main execution flow
display_header
init_usbmuxd
init_resources
init_python_venv
init_device_info
main_menu