-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathst3installdev
executable file
·156 lines (132 loc) · 6.77 KB
/
st3installdev
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
149
150
151
152
153
154
155
156
#!/bin/bash
#Sublime Text 3 DEV Linux Bash Installer
#Created by [email protected]
#Licensed under The MIT License (MIT)
# The MIT License (MIT)
# Copyright (c) 2014 Esteban Cuevas ([email protected])
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#Usage:
# chmod +x ./st3installdev && sudo ./st3installdev
#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="https://download.sublimetext.com/sublime_text_3_build_"
#Busquemos la ultima version de Sublime Text 3 en la web directamente
STURLTOCHECK="`wget -qO- http://www.sublimetext.com/3dev`"
#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 3 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_text_3_build_3018_x32.tar.bz2
echo -e "\e[7m*** System x86 detected.\e[0m"
#URLS="`grep -Po '(?<=href=").*?(?=">)' <<<"$STURLTOCHECK"`"
URL="`grep -Po '(?<=href="https://download.sublimetext.com/sublime_text_3_build_)(.*?)(\w+x32.tar.bz2)(?=">)' <<<"$STURLTOCHECK"`"
elif [ "x86_64" = `uname -m` ]; then
#http://c758482.r82.cf2.rackcdn.com/sublime_text_3_build_3018_x64.tar.bz2
echo -e "\e[7m*** System x86_64 detected.\e[0m"
URL="`grep -Po '(?<=href="https://download.sublimetext.com/sublime_text_3_build_)(.*?)(\w+x64.tar.bz2)(?=">)' <<<"$STURLTOCHECK"`"
fi
#El nombre del archivo y la URL completa, la necesitamos para despues
THEFILE="sublime_text_3_build_$URL"
THEDOWNLOADURL="$STDOWNLOADURLLIKE$URL"
echo -e "\e[7m*** I will download and install $THEDOWNLOADURL for you :)\e[0m"
#Instalamos Sublime Text 3
echo -e "\e[7m*** Creating temp location on /var/cache/...\e[0m"
mkdir -p /var/cache/sublime-text-3
cd /var/cache/sublime-text-3
#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 3 into /opt/sublime_text_3/\e[0m"
mkdir -p /opt/sublime_text_3/
cp -rf "/var/cache/sublime-text-3/sublime_text_3/"* /opt/sublime_text_3/
echo -e "\e[7m*** Creating symlinks to /usr/bin/sublime_text\e[0m"
ln -sf /opt/sublime_text_3/sublime_text /usr/bin/sublime_text
ln -sf /opt/sublime_text_3/sublime_text /usr/bin/sublime-text-3
ln -sf /opt/sublime_text_3/sublime_text /usr/bin/st3
ln -sf /opt/sublime_text_3/sublime_text /usr/bin/subl
ln -sf /opt/sublime_text_3/sublime_text /usr/bin/sublime
echo -e "\e[7m*** Creating symlinks for icons on /usr/share/icons/hicolor/...\e[0m"
ln -sf /opt/sublime_text_3/Icon/128x128/sublime-text.png /usr/share/icons/hicolor/128x128/apps/sublime-text-3.png
ln -sf /opt/sublime_text_3/Icon/256x256/sublime-text.png /usr/share/icons/hicolor/256x256/apps/sublime-text-3.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-3/sublime_text_3/"
rm -rf "/var/cache/sublime-text-3/"*.bz2
#Creando archivo .desktop
echo -e "\e[7m*** Creating .desktop file (for easy launch and associate to Sublime Text 3)...\e[0m"
echo "[Desktop Entry]
Version=1.0
Type=Application
Name=Sublime Text 3 DEV
GenericName=Text Editor
Comment=Sophisticated text editor for code, markup and prose
#Exec=/opt/sublime_text_3/sublime_text %F
Exec=sublime-text-3 %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-3
Categories=TextEditor;Development;
StartupNotify=true
Actions=Window;Document;
[Desktop Action Window]
Name=New Window
Exec=/opt/sublime_text_3/sublime_text -n
OnlyShowIn=Unity;
[Desktop Action Document]
Name=New File
Exec=/opt/sublime_text_3/sublime_text --command new_file
OnlyShowIn=Unity;" > /usr/share/applications/"Sublime Text 3.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://packagecontrol.io/installation
echo -e "\e[7m*** Installing Package Control (check https://packagecontrol.io/ for more awesomeness)...\e[0m"
sudo -u $SUDO_USER mkdir -p "$USER_HOME/.config/sublime-text-3/Installed Packages"
sudo -u $SUDO_USER wget -O "$USER_HOME/.config/sublime-text-3/Installed Packages/Package Control.sublime-package" "https://packagecontrol.io/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