Created
September 6, 2011 15:27
-
-
Save naholyr/1197854 to your computer and use it in GitHub Desktop.
Install or update Sublime Text from web site
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 | |
# Requirements: sed, grep, curl, pkill | |
# User configuration | |
LOCAL_INSTALL="/usr/lib/sublime-text-2" # Must be user-writable | |
REPO="dev" # "dev" for dev releases, or "2" for beta releases | |
TARGET_BUILD="Linux 32 bit" # can be one of "Windows", "Windows 64 bit", "OS X", "Linux 32 bit", "Linux 64 bit" | |
# Check if sublime text is running | |
if ( pkill -0 -f "$LOCAL_INSTALL/sublime_text" ); then | |
echo "Sublime Text 2 is running!" > /dev/stderr | |
exit 1 | |
fi | |
# Check if local install is available | |
if [ ! -d "$LOCAL_INSTALL" ]; then | |
echo "Local install folder does not exist, you should create $LOCAL_INSTALL" > /dev/stderr | |
exit 1 | |
fi | |
# Standard configuration | |
REMOTE_SITE="http://www.sublimetext.com" | |
# Generated configuration | |
CURR_VERSION="$( "$LOCAL_INSTALL/sublime_text" -v | sed 's/^.*Build \([0-9]\+\).*$/\1/' )" | |
HTML_FILE="$( tempfile )" | |
curl "$REMOTE_SITE/$REPO" > "$HTML_FILE" | |
LATEST_TBZ="$( cat "$HTML_FILE" | grep "$TARGET_BUILD" | sed 's/^.*<a href="\(.*\)".*$/\1/' )" | |
LATEST_VERSION="$( echo "$LATEST_TBZ" | sed 's/^.*Build \([0-9]\+\).*$/\1/' )" | |
LATEST_TBZ_URL="$( ( ( echo "$LATEST_TBZ" | grep -F '://' ) && echo "$LATEST_TBZ" || echo "$REMOTE_SITE$LATEST_TBZ" ) | sed 's/ /%20/g' )" | |
if [ $LATEST_VERSION -gt $CURR_VERSION ]; then | |
echo "Updating from $CURR_VERSION to $LATEST_VERSION..." | |
[ -d "/tmp/sublime-text-2-$LATEST_VERSION" ] && rm -rf "/tmp/sublime-text-2-$LATEST_VERSION" | |
mkdir "/tmp/sublime-text-2-$LATEST_VERSION" | |
echo "Downloading and extracting $LATEST_TBZ_URL..." | |
if ( curl "$LATEST_TBZ_URL" | tar jx -C "/tmp/sublime-text-2-$LATEST_VERSION" ); then | |
if ( cp -rfv "/tmp/sublime-text-2-$LATEST_VERSION/Sublime Text 2"/* "$LOCAL_INSTALL/" ); then | |
echo "Successfully updated from $CURR_VERSION to $LATEST_VERSION" | |
else | |
echo "Failed copying extracted files" > /dev/stderr | |
fi | |
else | |
echo "Failed downloading or extracting latest version! URL = $LATEST_TBZ_URL" > /dev/stderr | |
fi | |
rm -rf "/tmp/sublime-text-2-$LATEST_VERSION" | |
# Generate changelog | |
LATEST_BUILD_LINE=$( grep -n -m1 '<h2>Build' "$HTML_FILE" | sed 's/^\([0-9]*\):.*$/\1/' ) | |
CURR_BUILD_LINE="$( grep -n '<h2>Build' "$HTML_FILE" | tail -n +2 | while read match; do CURR_BUILD_NUM=$( echo $match | sed 's/^.*<h2>Build \([0-9]*\).*$/\1/' ); if [ $CURR_BUILD_NUM -ge $CURR_VERSION ]; then echo $match | sed 's/:.*$//'; fi; done | tail -n 1 )" | |
echo "Changelog:" | |
tail -n +$LATEST_BUILD_LINE $HTML_FILE | head -n +$(( $CURR_BUILD_LINE - $LATEST_BUILD_LINE )) | html2text | |
else | |
echo "Already up-to-date ($CURR_VERSION)" > /dev/stderr | |
fi | |
rm -f "$HTML_FILE" |
Renamed REPO to CHANNEL (more consistent)
Fixed a bug when the download link is not hosted directly on the sublime text's website
Isn't SublimeText auto updating? My dev build on OS X does, I recall the beta builds did that too.
It does not on my version (Linux, unlicensed) I have a _notification_
telling me there is an update available, and it brings me to the download
page, but that's all :(
It seems to be different, either for licensed users or Mac OS X users, I'm
not sure yet.
On 28 September 2011 14:57, Anthony Ricaud < ***@***.***>wrote:
Isn't SublimeText auto updating? My dev build on OS X does, I recall the
beta builds did that too.
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1197854
##
si ce message est crypt:
- PGP KeyID -> 0x2F080247
- ou http://naholyr.free.fr/naholyr.pubring.gpg
I'm not licensed so I guess it is for OS X.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added a changelog generation at end of process :)