@@ -36,34 +36,71 @@ TEMP_DIR=$(mktemp -d)
36
36
echo " Checking availability for iOS Device Support files for version $FALLBACK_VERSION ..."
37
37
if ! curl --head --silent --fail " $DOWNLOAD_URL " > /dev/null; then
38
38
echo " Error: Device Support files for iOS version $FALLBACK_VERSION do not exist."
39
- echo " Please check the available versions and try again."
40
39
rm -rf " $TEMP_DIR "
41
40
exit 1
42
41
fi
43
42
44
43
# Download the zip file
45
44
echo " Downloading iOS Device Support files for version $FALLBACK_VERSION ..."
46
45
curl -L " $DOWNLOAD_URL " -o " $TEMP_DIR /$FALLBACK_VERSION .zip"
46
+ if [[ $? -ne 0 ]]; then
47
+ echo " Error: Failed to download the file from $DOWNLOAD_URL ."
48
+ rm -rf " $TEMP_DIR "
49
+ exit 1
50
+ fi
47
51
48
52
# Unzip the downloaded file
49
53
echo " Unzipping the downloaded file..."
50
54
unzip -q " $TEMP_DIR /$FALLBACK_VERSION .zip" -d " $TEMP_DIR "
55
+ if [[ $? -ne 0 ]]; then
56
+ echo " Error: Failed to unzip the file. The downloaded file might be corrupted."
57
+ rm -rf " $TEMP_DIR "
58
+ exit 1
59
+ fi
51
60
52
- # Verify the unzipped folder exists
53
- if [ ! -d " $TEMP_DIR /$FALLBACK_VERSION " ]; then
54
- echo " Error: The unzipped folder does not match the expected structure."
61
+ # Verify the unzipped folder exists and is not empty
62
+ if [[ ! -d " $TEMP_DIR /$FALLBACK_VERSION " || -z " $( ls -A $TEMP_DIR / $FALLBACK_VERSION ) " ] ]; then
63
+ echo " Error: The unzipped folder is empty or does not match the expected structure."
55
64
rm -rf " $TEMP_DIR "
56
65
exit 1
57
66
fi
58
67
59
68
# Copy the files to the DeviceSupport directory
60
69
echo " Installing to $DEVICE_SUPPORT_DIR ..."
61
70
sudo cp -R " $TEMP_DIR /$FALLBACK_VERSION " " $DEVICE_SUPPORT_DIR /"
71
+ if [[ $? -ne 0 ]]; then
72
+ echo " Error: Failed to copy files to $DEVICE_SUPPORT_DIR . Ensure you have sudo access."
73
+ rm -rf " $TEMP_DIR "
74
+ exit 1
75
+ fi
76
+
77
+ # Adjust permissions to make the folder accessible
78
+ sudo chmod -R 755 " $DEVICE_SUPPORT_DIR /$FALLBACK_VERSION "
79
+ sudo chown -R $( whoami) " $DEVICE_SUPPORT_DIR /$FALLBACK_VERSION "
80
+
81
+ # Rename if using a fallback
82
+ if [[ " $IOS_VERSION " != " $FALLBACK_VERSION " ]]; then
83
+ echo " Renaming the installed folder to match version $IOS_VERSION ..."
84
+ sudo mv " $DEVICE_SUPPORT_DIR /$FALLBACK_VERSION " " $DEVICE_SUPPORT_DIR /$IOS_VERSION "
85
+ sudo chmod -R 755 " $DEVICE_SUPPORT_DIR /$IOS_VERSION "
86
+ sudo chown -R $( whoami) " $DEVICE_SUPPORT_DIR /$IOS_VERSION "
87
+ if [[ $? -ne 0 ]]; then
88
+ echo " Error: Failed to rename the folder to $IOS_VERSION ."
89
+ rm -rf " $TEMP_DIR "
90
+ exit 1
91
+ fi
92
+ echo " Note: Files were downloaded for $FALLBACK_VERSION but renamed to $IOS_VERSION for compatibility."
93
+ fi
62
94
63
95
# Rename if using a fallback
64
96
if [[ " $IOS_VERSION " != " $FALLBACK_VERSION " ]]; then
65
97
echo " Renaming the installed folder to match version $IOS_VERSION ..."
66
98
sudo mv " $DEVICE_SUPPORT_DIR /$FALLBACK_VERSION " " $DEVICE_SUPPORT_DIR /$IOS_VERSION "
99
+ if [[ $? -ne 0 ]]; then
100
+ echo " Error: Failed to rename the folder to $IOS_VERSION ."
101
+ rm -rf " $TEMP_DIR "
102
+ exit 1
103
+ fi
67
104
echo " Note: Files were downloaded for $FALLBACK_VERSION but renamed to $IOS_VERSION for compatibility."
68
105
fi
69
106
0 commit comments