Last active
October 16, 2023 18:51
-
-
Save vzsg/72739d78218c2d4f642e768fbaf8b9ad to your computer and use it in GitHub Desktop.
Bash script to install Swift 5.2 on Ubuntu 18.04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -f "/opt/swift/bin/swift" ]; then | |
echo ====== Swift is already installed at /opt/swift, exiting! | |
exit 1 | |
fi | |
for i in "$@" | |
do | |
case $i in | |
-s|--skip-signature) | |
SKIP_SIGNATURE_CHECK=YES | |
shift | |
;; | |
*) | |
;; | |
esac | |
done | |
echo ====== Installing dependencies... | |
export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true | |
apt-get -qq update | |
apt-get -qq install -y \ | |
curl \ | |
libatomic1 \ | |
libcurl4 \ | |
libxml2 \ | |
libedit2 \ | |
libsqlite3-0 \ | |
libc6-dev \ | |
binutils \ | |
libgcc-5-dev \ | |
libstdc++-5-dev \ | |
zlib1g-dev \ | |
libpython2.7 \ | |
tzdata \ | |
git \ | |
pkg-config \ | |
libssl-dev | |
# pub 4096R/ED3D1561 2019-03-22 [expires: 2021-03-21] | |
# Key fingerprint = A62A E125 BBBF BB96 A6E0 42EC 925C C1CC ED3D 1561 | |
# uid Swift 5.x Release Signing Key <swift-infrastructure@swift.org | |
SWIFT_SIGNING_KEY=A62AE125BBBFBB96A6E042EC925CC1CCED3D1561 | |
SWIFT_PLATFORM=ubuntu18.04 | |
SWIFT_BRANCH=swift-5.2.4-release | |
SWIFT_VERSION=swift-5.2.4-RELEASE | |
SWIFT_WEBROOT=https://swift.org/builds/ | |
set -e | |
SWIFT_WEBDIR="$SWIFT_WEBROOT/$SWIFT_BRANCH/$(echo $SWIFT_PLATFORM | tr -d .)/" | |
SWIFT_BIN_URL="$SWIFT_WEBDIR/$SWIFT_VERSION/$SWIFT_VERSION-$SWIFT_PLATFORM.tar.gz" | |
SWIFT_SIG_URL="$SWIFT_BIN_URL.sig" | |
export GNUPGHOME="$(mktemp -d)" | |
echo ====== Downloading toolchain... | |
curl -#fSL "$SWIFT_BIN_URL" -o swift.tar.gz "$SWIFT_SIG_URL" -o swift.tar.gz.sig | |
if [ -n "$SKIP_SIGNATURE_CHECK" ] | |
then | |
echo ====== Skipped signature check! | |
else | |
echo ====== Verifying signature... | |
gpg --batch --quiet --keyserver ha.pool.sks-keyservers.net --recv-keys "$SWIFT_SIGNING_KEY" | |
gpg --batch --verify swift.tar.gz.sig swift.tar.gz | |
fi | |
echo ====== Unpacking toolchain to /opt/swift... | |
mkdir -p /opt/swift | |
tar -xzf swift.tar.gz --directory /opt/swift --strip-components=2 | |
chmod -R o+r /opt/swift/lib/swift | |
echo ====== Cleaning up... | |
rm -rf "$GNUPGHOME" swift.tar.gz.sig swift.tar.gz | |
/opt/swift/bin/swift -version | |
echo | |
echo ===== $SWIFT_VERSION is now installed. Have a nice day! | |
echo ' PROTIP: you should add /opt/swift/bin to your PATH.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment