-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtc-latest
More file actions
executable file
·37 lines (28 loc) · 914 Bytes
/
Copy pathtc-latest
File metadata and controls
executable file
·37 lines (28 loc) · 914 Bytes
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
#!/bin/bash
set -e
branch=$1
if [ -z "$branch" ]; then
branch="main"
urlPrefix="https://download.swift.org/development/xcode"
else
urlPrefix="https://download.swift.org/swift-${branch}-branch/xcode"
fi
latest=$(curl -s https://www.swift.org/api/v1/install/dev/${branch}/macos.json | jq '.universal | max_by(.date)')
dir=$(echo ${latest} | jq -r '.dir')
tcDir=~/Library/Developer/Toolchains
latestDir=${tcDir}/${dir}.xctoolchain
if [ -d ${latestDir} ]; then
echo ${dir} already installed
exit 0
else
echo installing ${dir}
fi
pkg=$(echo ${latest} | jq -r '.download')
pkgtmp=${pkg}.tmp
mkdir -p ${tcDir}
curl -L ${urlPrefix}/${dir}/${pkg} > ${tcDir}/${pkg}
pkgutil --expand ${tcDir}/${pkg} ${tcDir}/${pkgtmp}
mkdir -p ${latestDir}
tar xf ${tcDir}/${pkgtmp}/${dir}-osx-package.pkg/Payload -C ${latestDir}
rm -fr ${tcDir}/${pkg} ${tcDir}/${pkgtmp}
ln -sf ${latestDir} ${tcDir}/latest