public
Last active

A Sublime Text 2 update script for Linux.

  • Download Gist
subl-upd
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
#!/bin/sh
 
file="Sublime Text 2 Build ${1} x64.tar.bz2"
# Uncomment line below for 32 bit.
#file="Sublime Text 2 Build ${1}.tar.bz2"
url="http://www.sublimetext.com/${file}"
first=0
 
if [ $(id -u) -ne 0 ]
then
echo 'ERROR: You need to run this script with sudo or as root.'
exit
fi
 
if [ -z $1 ]
then
echo 'ERROR: Invalid command. Type "subl-upd help" for a list of commands.'
exit
fi
 
echo $1 | grep -q "^[0-9]*$"
 
if [ $? -ne 0 ] && [ $1 != 'remove' ] && [ $1 != 'clean' ] && [ $1 != 'help' ]
then
echo 'ERROR: Invalid command. Type "subl-upd help" for a list of commands.'
exit
fi
 
if [ $1 == 'remove' ]
then
if [ ! -d /opt/subl ]
then
echo 'There is nothing to remove.'
else
rm -Rf /opt/subl/
rm /usr/local/bin/subl
echo 'Sublime successfully removed.'
fi
exit
elif [ $1 == 'clean' ]
then
echo 'Removing archives...'
rm -Rf /opt/subl/src/
mkdir /opt/subl/src/
echo 'Archives successfully removed.'
exit
elif [ $1 == 'help' ]
then
echo -e 'List of commands:\n <ver#> - Update to the supplied version.\n example -> subl-upd 2053\n clean - Removes all downloaded archives.\n remove - Removes Sublime completely.\n help - This output.'
exit
else
echo 'Starting update...'
fi
 
if [ ! -d /opt/subl ]
then
mkdir -p /opt/subl/src/
first=1
fi
 
if [ ! -f "/opt/subl/src/${file}" ]
then
echo 'Downloading...'
wget -P /opt/subl/src/ --accept "${file}" -q "${url}"
else
echo 'File already downloaded.'
fi
 
if [ $? -ne 0 ]
then
echo 'ERROR: Version not found.'
exit
fi
 
if [ $first -eq 1 ]
then
mkdir /opt/subl/pkg/
else
rm -Rf /opt/subl/pkg/
mkdir /opt/subl/pkg/
fi
 
echo 'Extracting...'
 
tar --strip-components=1 -C '/opt/subl/pkg/' -xjf "/opt/subl/src/${file}"
 
if [ ! -e /usr/local/bin/subl ]
then
echo 'Installing binary at /usr/local/bin/subl...'
ln -s /opt/subl/pkg/sublime_text /usr/local/bin/subl
fi
 
echo "Update to version ${1} successful!"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.