-
Notifications
You must be signed in to change notification settings - Fork 207
/
create_generic_symlinks.sh
executable file
·62 lines (51 loc) · 1.13 KB
/
create_generic_symlinks.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
#!/usr/bin/env bash
usage() {
echo "Usage: $0 -D <dir_with_sdks>"
}
info() {
echo "$0: $1"
}
# Accept 'D' flag
while getopts ":D:" flag; do
case "$flag" in
# Assign the arg associated with -D to $sdk_dir
D) sdk_dir="$OPTARG" ;;
*) usage
exit 1
;;
esac
done
# No args passed
if [[ $OPTIND -eq 1 ]]; then
usage
exit 1
fi
# Get sdks in provided dir
IFS=$'\n'
sdks=($(find "$sdk_dir" -type d -name \*.sdk | sort -uV))
unset IFS
# Get unique prefixes
prefixes=()
for i in "${sdks[@]}"; do
name="$(basename "$i")"
prefix="${name%%[0-9]*}"
# Check if prefixes array contains the prefix or not
if ! [[ ${prefixes[*]} =~ $prefix ]]; then
prefixes+=("$prefix")
fi
done
# Get sdks for each prefix
for prefix in "${prefixes[@]}"; do
relevant_sdks=()
for sdk in "${sdks[@]}"; do
if [[ $sdk =~ $prefix ]]; then
relevant_sdks+=("$sdk")
fi
done
# Latest sdk (e.g., iPhoneOS14.5.sdk)
latest=${relevant_sdks[${#relevant_sdks[@]}-1]}
# Generic platform sdk (e.g., iPhoneOS.sdk)
platform="$sdk_dir/$prefix.sdk"
ln -sfn "$latest" "$platform"
info "The '$platform' symlink has been created and it points to '$latest'."
done