#!/usr/bin/env bash # Usage: {script} [ OPTIONS ] TARGET VERSION # # TARGET Default target is "/usr/local". # VERSION If not defined tries to get the build into the Sublime Text 2 website. # # OPTIONS # # -h, --help Displays this help message. # # Report bugs to Henrique Moody # set -e if [[ "${1}" = '-h' ]] || [[ "${1}" = '--help' ]]; then sed -E 's/^#\s?(.*)/\1/g' "${0}" | sed -nE '/^Usage/,/^Report/p' | sed "s/{script}/$(basename "${0}")/g" exit fi declare URL declare URL_FORMAT="http://c758482.r82.cf2.rackcdn.com/%s.tar.bz2" declare PACKAGE="Sublime Text" declare TARGET="${1:-/usr/local}" declare VERSION="${2}" declare BITS=$(uname -m) if [[ -z "${VERSION}" ]]; then VERSION=$( curl -Ls http://www.sublimetext.com/2 | grep '

Version' | head -n1 | sed -E 's#

Version ([0-9.]+)

#\1#g' ) fi PACKAGE+=" ${VERSION}" if [[ "${BITS}" = "x86_64" ]]; then PACKAGE+=" x64" fi URL=$(printf "${URL_FORMAT}" "${PACKAGE}" | sed 's/ /%20/g') read -p "Do you really want to install \"${PACKAGE}\" on \"${TARGET}\"? [Y/n]: " CONFIRM CONFIRM=$(echo "${CONFIRM}" | tr [a-z] [A-Z]) if [[ "${CONFIRM}" = 'N' ]] || [[ "${CONFIRM}" = 'NO' ]]; then echo "Aborted!" exit fi echo "Downloading ${PACKAGE}" curl -L "${URL}" | tar -xjC ${TARGET} echo "Creating binary file" cat > ${TARGET}/bin/subl <