-
Notifications
You must be signed in to change notification settings - Fork 5
/
install-swift.sh
executable file
Β·202 lines (165 loc) Β· 6.77 KB
/
install-swift.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
# Expects environment variable `SWIFT_VERSION`
# Example values: 5.5 or swift-DEVELOPMENT-SNAPSHOT-2022-01-09-a
# System library dependencies: wget
install_swift () {
determine_os
if [[ -d $(toolchain_path) ]]; then
echo "Toolchain already exists, skipping download β
"
else
download_toolchain
if_linux_verify_signature
if_macos_run_installer
fi
if_linux_install_system_dependencies
install_toolchain
echo "Successfully installed Swift toolchain π"
}
#-=============================================================================-
# Steps
#-=============================================================================-
determine_os () {
KERNEL=$(uname)
if [[ $KERNEL == "Darwin" ]]; then
IS_MACOS=true
elif [[ $KERNEL == "Linux" ]]; then
IS_LINUX=true
UBUNTU_VERSION=$(lsb_release -rs)
else
echo "Unsupported kernel '$KERNEL' β οΈ"
exit 1;
fi
}
download_toolchain () {
echo "Downloading Swift toolchain βοΈ"
if [ $IS_MACOS ]; then
TOOLCHAIN_URL=$(download_url pkg)
elif [ $IS_LINUX ]; then
TOOLCHAIN_URL=$(download_url tar.gz)
fi
wget $TOOLCHAIN_URL
}
if_linux_install_system_dependencies () {
if ! [[ $IS_LINUX ]]; then
return 0;
fi
echo "Installing system dependencies for '$UBUNTU_VERSION' π¦"
sudo apt-get update
if [ $UBUNTU_VERSION == "18.04" ]; then
sudo apt-get install \
binutils git libc6-dev libcurl4 libedit2 libgcc-5-dev libpython2.7 libsqlite3-0 libstdc++-5-dev libxml2 \
pkg-config tzdata zlib1g-dev
elif [ $UBUNTU_VERSION == "20.04" ]; then
sudo apt-get install \
binutils git gnupg2 libc6-dev libcurl4 libedit2 libgcc-9-dev libpython2.7 libsqlite3-0 libstdc++-9-dev libxml2 \
libz3-dev pkg-config tzdata uuid-dev zlib1g-dev
elif [ $UBUNTU_VERSION == "22.04" ]; then
sudo apt-get install \
binutils git gnupg2 libc6-dev libcurl4-openssl-dev libedit2 libgcc-9-dev libpython3.8 libsqlite3-0 \
libstdc++-9-dev libxml2-dev libz3-dev pkg-config tzdata unzip zlib1g-dev
else
echo "No Swift Toolchain available for Ubuntu version '$UBUNTU_VERSION'."
echo "Visit https://swift.org/download for more information."
exit 1
fi
}
if_linux_verify_signature () {
if ! [[ $IS_LINUX ]]; then
return 0;
fi
echo "Verifying Swift toolchain π"
wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -
wget $(download_url tar.gz.sig)
gpg --verify $(download_file tar.gz.sig)
}
if_macos_run_installer () {
if ! [[ $IS_MACOS ]]; then
return 0;
fi
echo "Running installer π»"
TOOLCHAIN=$(release_name).xctoolchain
xattr -dr com.apple.quarantine $(download_file pkg)
installer -pkg $(download_file pkg) -target CurrentUserHomeDirectory
}
install_toolchain () {
echo "Installing Swift toolchain π»"
if [ $IS_LINUX ]; then
tar xzf $(download_file tar.gz)
mkdir $(toolchains_path)
mv $(download_file) $(toolchain_path)
fi
PATH=$(toolchain_path)/usr/bin:${PATH}
echo "PATH=$PATH" >> $GITHUB_ENV
}
#-=============================================================================-
# Helpers
#-=============================================================================-
# Example release URLs
# https://download.swift.org/swift-5.5.2-release/xcode/swift-5.5.2-RELEASE/swift-5.5.2-RELEASE-osx.pkg
# https://download.swift.org/swift-5.5.2-release/ubuntu1804/swift-5.5.2-RELEASE/swift-5.5.2-RELEASE-ubuntu18.04.tar.gz
# https://download.swift.org/swift-5.5.2-release/ubuntu2004/swift-5.5.2-RELEASE/swift-5.5.2-RELEASE-ubuntu20.04.tar.gz
# Example trunk development snapshot URLs
# https://download.swift.org/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2022-01-09-a/swift-DEVELOPMENT-SNAPSHOT-2022-01-09-a-osx.pkg
# https://download.swift.org/development/ubuntu1804/swift-DEVELOPMENT-SNAPSHOT-2022-01-09-a/swift-DEVELOPMENT-SNAPSHOT-2022-01-09-a-ubuntu18.04.tar.gz
# https://download.swift.org/development/ubuntu1804/swift-DEVELOPMENT-SNAPSHOT-2022-01-09-a/swift-DEVELOPMENT-SNAPSHOT-2022-01-09-a-ubuntu18.04.tar.gz.sig
# https://download.swift.org/development/ubuntu2004/swift-DEVELOPMENT-SNAPSHOT-2022-01-09-a/swift-DEVELOPMENT-SNAPSHOT-2022-01-09-a-ubuntu20.04.tar.gz
# https://download.swift.org/development/ubuntu2004/swift-DEVELOPMENT-SNAPSHOT-2022-01-09-a/swift-DEVELOPMENT-SNAPSHOT-2022-01-09-a-ubuntu20.04.tar.gz.sig
# Example version-specific development snapshot URLs
# https://download.swift.org/swift-5.6-branch/xcode/swift-5.6-DEVELOPMENT-SNAPSHOT-2022-01-11-a/swift-5.6-DEVELOPMENT-SNAPSHOT-2022-01-11-a-osx.pkg
# https://download.swift.org/swift-5.6-branch/ubuntu1804/swift-5.6-DEVELOPMENT-SNAPSHOT-2022-01-11-a/swift-5.6-DEVELOPMENT-SNAPSHOT-2022-01-11-a-ubuntu18.04.tar.gz
# https://download.swift.org/swift-5.6-branch/ubuntu1804/swift-5.6-DEVELOPMENT-SNAPSHOT-2022-01-11-a/swift-5.6-DEVELOPMENT-SNAPSHOT-2022-01-11-a-ubuntu18.04.tar.gz.sig
# https://download.swift.org/swift-5.6-branch/ubuntu2004/swift-5.6-DEVELOPMENT-SNAPSHOT-2022-01-11-a/swift-5.6-DEVELOPMENT-SNAPSHOT-2022-01-11-a-ubuntu20.04.tar.gz
# https://download.swift.org/swift-5.6-branch/ubuntu2004/swift-5.6-DEVELOPMENT-SNAPSHOT-2022-01-11-a/swift-5.6-DEVELOPMENT-SNAPSHOT-2022-01-11-a-ubuntu20.04.tar.gz.sig
toolchain_path () {
if [ $IS_LINUX ]; then
echo $(toolchains_path)/$(release_name)
elif [ $IS_MACOS ]; then
echo $(toolchains_path)/$(release_name).xctoolchain
fi
}
toolchains_path () {
if [ $IS_LINUX ]; then
echo /opt/swift-toolchains
elif [ $IS_MACOS ]; then
echo ${HOME}/Library/Developer/Toolchains
fi
}
release_name () {
if [[ $SWIFT_VERSION == *DEVELOPMENT-SNAPSHOT* ]]; then
RELEASE_NAME=$SWIFT_VERSION
else
RELEASE_NAME=swift-$SWIFT_VERSION-RELEASE
fi
echo $RELEASE_NAME
}
download_file () {
FILETYPE=$1
if [ $IS_MACOS ]; then
ALT_PLATFORM=osx
elif [ $IS_LINUX ]; then
ALT_PLATFORM=ubuntu$UBUNTU_VERSION
fi
RETURN_VALUE=$(release_name)-$ALT_PLATFORM
if [ $FILETYPE ]; then
RETURN_VALUE=$RETURN_VALUE.$FILETYPE
fi
echo $RETURN_VALUE
}
download_url () {
DOWNLOAD_BASE_URL=https://download.swift.org
FILETYPE=$1
if [[ $SWIFT_VERSION == swift-DEVELOPMENT-SNAPSHOT* ]]; then
FOLDER=development
elif [[ $SWIFT_VERSION =~ swift-(.*)-DEVELOPMENT-SNAPSHOT-.* ]]; then
FOLDER=swift-${BASH_REMATCH[1]}-branch
else
FOLDER=swift-$SWIFT_VERSION-release
fi
if [ $IS_MACOS ]; then
PLATFORM=xcode
elif [ $IS_LINUX ]; then
PLATFORM=ubuntu${UBUNTU_VERSION//[.]/}
fi
echo $DOWNLOAD_BASE_URL/$FOLDER/$PLATFORM/$(release_name)/$(download_file $FILETYPE)
}
install_swift