forked from EstebanForge/sublime-text-linux-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathst2install
executable file
·148 lines (124 loc) · 6.1 KB
/
st2install
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
#Sublime Text 2 Linux Bash Installer
#Created by [email protected]
#Licensed under WTFPL (Do What The Fuck You Want To Public License)
#http://en.wikipedia.org/wiki/WTFPL
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
#Copyright (C) 2004 Sam Hocevar <[email protected]>
#
#Everyone is permitted to copy and distribute verbatim or modified
#copies of this license document, and changing it is allowed as long
#as the name is changed.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
# 0. You just DO WHAT THE FUCK YOU WANT TO.
#Usage:
# chmod +x ./st2install && sudo ./st2install
#You can upgrade an installation made by this same script, using this
#very same script too ;)
#Esta es la URL que buscaremos en la pagina de descarga
STDOWNLOADURLLIKE="http://c758482.r82.cf2.rackcdn.com/Sublime Text "
#Busquemos la ultima version de Sublime Text 2 en la web directamente
STURLTOCHECK="`wget -qO- http://www.sublimetext.com/2`"
#Home del usuario (http://stackoverflow.com/questions/7358611/bash-get-users-home-directory-when-they-run-a-script-as-root)
USER_HOME=$(getent passwd $SUDO_USER | cut -d: -f6)
echo -e "\e[7m*** Sublime Text 2 Batch Installer/Upgrader ([email protected])\e[0m"
#URL distinta segun sistema 64 o 32 bits
if [ "i686" = `uname -m` ]; then
#http://c758482.r82.cf2.rackcdn.com/Sublime%20Text%202.0.1.tar.bz2
echo -e "\e[7m*** System x86 detected.\e[0m"
#URLS="`grep -Po '(?<=href=").*?(?=">)' <<<"$STURLTOCHECK"`"
URL="`grep -Po '(?<=href="http://c758482.r82.cf2.rackcdn.com/Sublime Text )(.*?)([^x64].tar.bz2)(?=">)' <<<"$STURLTOCHECK"`"
elif [ "x86_64" = `uname -m` ]; then
#http://c758482.r82.cf2.rackcdn.com/Sublime%20Text%202.0.1%20x64.tar.bz2
echo -e "\e[7m*** System x86_64 detected.\e[0m"
URL="`grep -Po '(?<=href="http://c758482.r82.cf2.rackcdn.com/Sublime Text )(.*?)(\w+ x64.tar.bz2)(?=">)' <<<"$STURLTOCHECK"`"
fi
#El nombre del archivo y la URL completa, la necesitamos para despues
THEFILE="Sublime Text $URL"
THEDOWNLOADURL="$STDOWNLOADURLLIKE$URL"
echo -e "\e[7m*** I will download and install $THEDOWNLOADURL for you :)\e[0m"
#Instalamos Sublime Text 2
echo -e "\e[7m*** Creating temp location on /var/cache/...\e[0m"
mkdir -p /var/cache/sublime-text-2
cd /var/cache/sublime-text-2
#A la flash-installer
APT_PROXIES=$(apt-config shell http_proxy Acquire::http::Proxy https_proxy Acquire::https::Proxy ftp_proxy Acquire::ftp::Proxy)
if [ -n "$APT_PROXIES" ]; then
eval export $APT_PROXIES
fi
#Descargamos
echo -e "\e[7m*** Downloading file to temp location...\e[0m"
#http://unix.stackexchange.com/questions/37507/what-does-do-here
:> wgetrc
echo "noclobber = off" >> wgetrc
echo "dir_prefix = ." >> wgetrc
echo "dirstruct = off" >> wgetrc
echo "verbose = on" >> wgetrc
echo "progress = bar:default" >> wgetrc
echo "tries = 3" >> wgetrc
WGETRC=wgetrc wget --continue -O "$THEFILE" "$THEDOWNLOADURL" \
|| echo -e "\e[7m***Download failed.\e[0m"
rm -f wgetrc
echo -e "\e[7m*** Download completed.\e[0m"
echo -e "\e[7m*** Unpacking files on temp location...\e[0m"
tar xvf "$THEFILE" || echo -e "\e[7m*** Cannot unpack downloaded file.\e[0m"
echo -e "\e[7m*** Installing Sublime Text 2 into /opt/sublime_text_2/\e[0m"
mkdir -p /opt/sublime_text_2/
cp -rf "/var/cache/sublime-text-2/Sublime Text 2/"* /opt/sublime_text_2/ #Carpeta diferente de ST3
echo -e "\e[7m*** Creating symlinks to /usr/bin/sublime_text\e[0m"
#ln -sf /opt/sublime_text_2/sublime_text /usr/bin/sublime_text #Usado en ST3
ln -sf /opt/sublime_text_2/sublime_text /usr/bin/sublime-text-2
ln -sf /opt/sublime_text_2/sublime_text /usr/bin/st2
echo -e "\e[7m*** Creating symlinks for icons on /usr/share/icons/hicolor/...\e[0m"
ln -sf /opt/sublime_text_2/Icon/128x128/sublime_text.png /usr/share/icons/hicolor/128x128/apps/sublime-text-2.png
ln -sf /opt/sublime_text_2/Icon/256x256/sublime_text.png /usr/share/icons/hicolor/256x256/apps/sublime-text-2.png
gtk-update-icon-cache /usr/share/icons/hicolor
echo -e "\e[7m*** Cleaning up temp unpacked files...\e[0m"
rm -rf "/var/cache/sublime-text-2/Sublime Text 2/" #Carpeta diferente de ST3
rm -rf "/var/cache/sublime-text-2/"*.bz2
#Creando archivo .desktop
echo -e "\e[7m*** Creating .desktop file (for easy launch and associate to Sublime Text 2)...\e[0m"
echo "[Desktop Entry]
Version=1.0
Type=Application
Name=Sublime Text 2
GenericName=Text Editor
Comment=Sophisticated text editor for code, markup and prose
#Exec=/opt/sublime_text_2/sublime_text %F
Exec=sublime-text-2 %F
Terminal=false
MimeType=text/plain;text/x-chdr;text/x-csrc;text/x-c++hdr;text/x-c++src;text/x-java;text/x-dsrc;text/x-pascal;text/x-perl;text/x-python;application/x-php;application/x-httpd-php3;application/x-httpd-php4;application/x-httpd-php5;application/xml;text/html;text/css;text/x-sql;text/x-diff;x-directory/normal;inode/directory;
Icon=sublime-text-2
Categories=TextEditor;Development;
StartupNotify=true
Actions=Window;Document;
[Desktop Action Window]
Name=New Window
Exec=/opt/sublime_text_2/sublime_text -n
OnlyShowIn=Unity;
[Desktop Action Document]
Name=New File
Exec=/opt/sublime_text_2/sublime_text --command new_file
OnlyShowIn=Unity;" > /usr/share/applications/"Sublime Text 2.desktop"
#Porque necesitamos correr el comando como el usuario y no como root, usaremos:
#http://superuser.com/questions/93385/run-part-of-a-bash-script-as-a-different-user
#http://superuser.com/questions/195781/sudo-is-there-a-command-to-check-if-i-have-sudo-and-or-how-much-time-is-left
CAN_I_RUN_SUDO=$(sudo -n uptime 2>&1|grep "load"|wc -l)
if [ ${CAN_I_RUN_SUDO} -gt 0 ]; then
#Podemos correr sudo
#Instalar Package Control https://sublime.wbond.net/installation
echo -e "\e[7m*** Installing Package Control (check https://sublime.wbond.net/ for more awesomeness)...\e[0m"
sudo -u $SUDO_USER mkdir -p "$USER_HOME/.config/sublime-text-2/Installed Packages"
sudo -u $SUDO_USER wget -O "$USER_HOME/.config/sublime-text-2/Installed Packages/Package Control.sublime-package" "https://sublime.wbond.net/Package%20Control.sublime-package"
else
#No podemos correr sudo
echo ''
fi
echo -e "\e[7m*** That's all. Have fun Sublime Texting ;)\e[0m"
exit 0
EOF