Created
September 7, 2018 13:39
-
-
Save juev/e479fbb55ea77df8d6eea789615d1e78 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Usage: {script} [ OPTIONS ] TARGET BUILD | |
# | |
# TARGET Default target is "/usr/local". | |
# BUILD If not defined tries to get the build into the Sublime Text 3 website. | |
# | |
# OPTIONS | |
# | |
# -h, --help Displays this help message. | |
# | |
# Report bugs to Evsyukov Denis <denis@evsyukov.org> | |
# | |
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="https://download.sublimetext.com/sublime_text_3_build_%d_x%d.tar.bz2" | |
declare TARGET="${1:-/opt}" | |
declare BUILD="${2}" | |
declare BITS | |
if [[ -z "${BUILD}" ]]; then | |
BUILD=$( | |
curl -Ls http://www.sublimetext.com/3 | | |
grep 'latest' | | |
head -n1 | | |
sed -E 's#<p class="latest"><i>Version:</i> Build ([0-9]+)</p>#\1#g' | | |
xargs | |
) | |
fi | |
if [[ "$(uname -m)" = "x86_64" ]]; then | |
BITS=64 | |
else | |
BITS=32 | |
fi | |
URL=$(printf "${URL_FORMAT}" "${BUILD}" "${BITS}") | |
read -p "Do you really want to install Sublime Text 3 (Build ${BUILD}, x${BITS}) 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 Sublime Text 3" | |
curl -L "${URL}" | sudo tar -xjC ${TARGET} | |
echo "Creating shortcut file" | |
cat ${TARGET}/sublime_text_3/sublime_text.desktop | | |
sed "s#/opt#${TARGET}#g" | | |
sudo tee "/usr/share/applications/sublime_text.desktop" > /dev/null | |
echo "Creating binary file" | |
sudo ln -sf ${TARGET}/sublime_text_3/sublime_text /usr/local/bin/subl | |
echo "Finish!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment