@ -26,10 +26,14 @@ xcrun simctl delete unavailable
# Extract all UUIDs from the device_set
# Extract all UUIDs from the device_set
uuids = $( grep -Eo '[A-F0-9]{8}-([A-F0-9]{4}-){3}[A-F0-9]{12}' " $plist " )
uuids = $( grep -Eo '[A-F0-9]{8}-([A-F0-9]{4}-){3}[A-F0-9]{12}' " $plist " )
running_uuids = $( xcrun simctl list devices | grep -Eo '[A-F0-9]{8}-([A-F0-9]{4}-){3}[A-F0-9]{12}' | grep -v 'Shutdown' )
# Get the current time in minutes since 1970-01-01 00:00:00 UTC
current_time = $( date +%s)
current_time = $(( current_time / 60 ))
# Create empty arrays to store the outputs
# Create empty arrays to store the outputs
uuids_to_leave = ( )
uuids_to_keep = ( )
uuids_to_ignore = ( )
uuids_to_remove = ( )
uuids_to_remove = ( )
# Find directories older than an hour
# Find directories older than an hour
@ -37,13 +41,24 @@ while read -r dir; do
# Get the last component of the directory path
# Get the last component of the directory path
dir_name = $( basename " $dir " )
dir_name = $( basename " $dir " )
# Check if the directory name is in the list of UUIDs
# Get the modification time of the folder in minutes since 1970-01-01 00:00:00 UTC
folder_time = $( stat -f "%m" " $dir " )
folder_time = $(( folder_time / 60 ))
# Check if the folder is in the uuids array
if ! echo " $uuids " | grep -q " $dir_name " ; then
if ! echo " $uuids " | grep -q " $dir_name " ; then
uuids_to_remove += ( " $dir_name " )
if ( ( current_time - folder_time <= 60) ) ; then
# If the folder was created within the past 60 minutes, add it to uuids_to_keep
uuids_to_keep += ( " $dir_name " )
else
# If the folder was created longer than 60 minutes ago, add it to uuids_to_remove
uuids_to_remove += ( " $dir_name " )
fi
else
else
uuids_to_leave += ( " $dir_name " )
# If the folder is in the uuids array, add it to uuids_to_ignore
uuids_to_ignore += ( " $dir_name " )
fi
fi
done < <( find " $dir " -maxdepth 1 -type d -not -path " $dir " -mmin +60)
done < <( find " $dir " -maxdepth 1 -type d -not -path " $dir " )
# Delete the simulators
# Delete the simulators
if [ ${# uuids_to_remove [@] } -eq 0 ] ; then
if [ ${# uuids_to_remove [@] } -eq 0 ] ; then
@ -57,7 +72,6 @@ else
fi
fi
# Output the pipeline simulators we are leaving
# Output the pipeline simulators we are leaving
uuids_to_keep = $( echo " $uuids " | grep -v " ${ uuids_to_leave [*] } " | grep -v " ${ uuids_to_remove [*] } " )
if [ ${# uuids_to_keep [@] } -gt 0 ] ; then
if [ ${# uuids_to_keep [@] } -gt 0 ] ; then
echo -e " \e[33m\nIgnoring ${# uuids_to_keep [@] } test simulators (might be in use):\e[0m "
echo -e " \e[33m\nIgnoring ${# uuids_to_keep [@] } test simulators (might be in use):\e[0m "
for uuid in " ${ uuids_to_keep [@] } " ; do
for uuid in " ${ uuids_to_keep [@] } " ; do
@ -66,7 +80,7 @@ if [ ${#uuids_to_keep[@]} -gt 0 ]; then
fi
fi
# Output the remaining Xcode Simulators
# Output the remaining Xcode Simulators
echo -e " \e[32m\nIgnoring ${# uuids_to_ leav e[@] } Xcode simulators:\e[0m "
echo -e " \e[32m\nIgnoring ${# uuids_to_ ignor e[@] } Xcode simulators:\e[0m "
for uuid in " ${ uuids_to_ leav e[@] } " ; do
for uuid in " ${ uuids_to_ ignor e[@] } " ; do
echo -e " \e[32m $uuid \e[0m "
echo -e " \e[32m $uuid \e[0m "
done
done