Skip to content

Commit 7c442e7

Browse files
authored
Update install_device_support.sh
Fixed & final version of the script.
1 parent 7c74486 commit 7c442e7

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

scripts/install_device_support.sh

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,71 @@ TEMP_DIR=$(mktemp -d)
3636
echo "Checking availability for iOS Device Support files for version $FALLBACK_VERSION..."
3737
if ! curl --head --silent --fail "$DOWNLOAD_URL" > /dev/null; then
3838
echo "Error: Device Support files for iOS version $FALLBACK_VERSION do not exist."
39-
echo "Please check the available versions and try again."
4039
rm -rf "$TEMP_DIR"
4140
exit 1
4241
fi
4342

4443
# Download the zip file
4544
echo "Downloading iOS Device Support files for version $FALLBACK_VERSION..."
4645
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
4751

4852
# Unzip the downloaded file
4953
echo "Unzipping the downloaded file..."
5054
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
5160

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."
5564
rm -rf "$TEMP_DIR"
5665
exit 1
5766
fi
5867

5968
# Copy the files to the DeviceSupport directory
6069
echo "Installing to $DEVICE_SUPPORT_DIR..."
6170
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
6294

6395
# Rename if using a fallback
6496
if [[ "$IOS_VERSION" != "$FALLBACK_VERSION" ]]; then
6597
echo "Renaming the installed folder to match version $IOS_VERSION..."
6698
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
67104
echo "Note: Files were downloaded for $FALLBACK_VERSION but renamed to $IOS_VERSION for compatibility."
68105
fi
69106

0 commit comments

Comments
 (0)