Skip to content

Instantly share code, notes, and snippets.

@andelf
Created April 28, 2016 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andelf/9ece0ddb8a20be538fd919ddba7b9d86 to your computer and use it in GitHub Desktop.
Save andelf/9ece0ddb8a20be538fd919ddba7b9d86 to your computer and use it in GitHub Desktop.
Swift Development Snapshot Install Script
#!/bin/sh
# FileName : install_swift_to.sh
# Author : ShuYu Wang <andelf@gmail.com>
# Created : Thu Apr 28 12:21:46 2016 by ShuYu Wang
# Copyright : Feather Workshop (c) 2016
# Description : Swift Snapshot Installing Script
# Time-stamp: <2016-04-28 12:22:51 andelf>
OLDPWD=$(pwd)
SWIFT_URL_BASE="https://swift.org"
DOWNLOAD_PAGE_URL="${SWIFT_URL_BASE}/download/"
# Customize this!
INSTALL_DIR="${HOME}/opt/swift"
mkdir -p ${INSTALL_DIR}
echo Installing to ${INSTALL_DIR}
echo Fetching Version ...
CURRENT_SWIFT_PKG_URL="${SWIFT_URL_BASE}$(curl -s https://swift.org/download/ | egrep '/builds/development/xcode/swift-DEVELOPMENT-SNAPSHOT.*?osx\.pkg' -o | head -n1)"
CURRENT_SWIFT_PKG_FILE=$(basename ${CURRENT_SWIFT_PKG_URL})
CURRENT_SWIFT_VERSION=$(echo ${CURRENT_SWIFT_PKG_FILE} | egrep '\d+\-\d+\-\d+' -o | head -n1)
TEMP_DIR=$(mktemp -d)
mkdir -p ${TEMP_DIR} && cd ${TEMP_DIR}
echo Using Temp Dir ${TEMP_DIR}
echo Downloading Swift ${CURRENT_SWIFT_VERSION} ...
curl ${CURRENT_SWIFT_PKG_URL} -o ${CURRENT_SWIFT_PKG_FILE}
echo Extracting Package ...
tar xf ${CURRENT_SWIFT_PKG_FILE}
tar xf */Payload
mv ./usr/bin ${INSTALL_DIR}
mv ./usr/lib ${INSTALL_DIR}
mv ./System/Library/PrivateFrameworks/LLDB.framework "${INSTALL_DIR}/lib"
install_name_tool -change "@rpath/LLDB.framework/LLDB" "@rpath/../lib/LLDB.framework/LLDB" "${INSTALL_DIR}/bin/lldb"
install_name_tool -change "@rpath/LLDB.framework/LLDB" "@rpath/../lib/LLDB.framework/LLDB" "${INSTALL_DIR}/bin/lldb-mi"
echo Cleaning Up ...
cd ${OLDPWD}
rm -rf ${TEMP_DIR}
echo Now Run Swift With "${INSTALL_DIR}/bin/swift"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment