This repository was archived by the owner on Sep 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjetbrains-get.sh
executable file
·226 lines (187 loc) · 5.03 KB
/
jetbrains-get.sh
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
temp="/tmp/jetbrains-install"
installDest='/opt'
codes=()
names=()
installDir='/opt'
removeDownloads=0
forceDownload=0
noLaunch=0
function askSudo {
if [ $(id -u) -ne 0 ]; then
SUDO='sudo'
sudo echo 'Root access acquired'
fi
}
function helpcmd {
echo "Usage:
jetbrains-get install [packages] [options] Installs/upgrades packages
jetbrains-get upgrade [packages] [options] Installs/upgrades packages
jetbrains-get remove [packages] Uninstalls packages
jetbrains-get clean Removes all downloaded files
jetbrains-get --help Prints this help message and quits
Packages:
clion, phpstorm, idea, idea-community, datagrip, pycharm, pycharm-community, rubymine
Options:
--no-launch Will not launch the program after installation
--remove-downloads Will remove all downloaded files after installation
--force-download Will force redownload even if file exists on disk"
exit 1
}
for var in "$@"; do
#'names' array contains the names of the .sh files
if [ "$var" = "clion" ]; then
codes+=('CL')
names+=('clion')
elif [ "$var" = "phpstorm" ]; then
codes+=('PS')
names+=('phpstorm')
elif [ "$var" = "idea" ]; then
codes+=('IIU')
names+=('idea')
elif [ "$var" = "idea-community" ]; then
codes+=('IIC')
names+=('idea')
elif [ "$var" = "datagrip" ]; then
codes+=('DG')
names+=('datagrip')
elif [ "$var" = "pycharm" ]; then
codes+=('PCP')
names+=('pycharm')
elif [ "$var" = "pycharm-community" ]; then
codes+=('PCC')
names+=('pycharm')
elif [ "$var" = "rubymine" ]; then
codes+=('RM')
names+=('rubymine')
elif [ "$var" = "webstorm" ]; then
codes+=('WS')
names+=('webstorm')
elif [ "$var" = "--remove-downloads" ]; then
removeDownloads=1
elif [ "$var" = "--force-download" ]; then
forceDownload=1
elif [ "$var" = "--no-launch" ]; then
noLaunch=1
fi
done
function checkPackages {
if [ ${#codes[@]} -eq 0 ]; then
echo "No packages specified. See --help for more"
exit 2
fi
}
function download {
dest=$1
source=$2
name=$3
cd $temp
if [ ! -f $dest ] || [ $forceDownload -eq 1 ]; then
echo "$name: Removing old downloads..."
find . -iname "$name*" -exec rm -rf "{}" 2> /dev/null +
echo "$name: Downloading $source ..."
wget -O $dest $source -q --show-progress
else
echo "$name: File $source already downloaded"
fi
echo "$name: Extracting..."
rm -rf $name 2> /dev/null
mkdir -p $name
if ! $(tar -xf $dest --strip=1 -C $name 2> /dev/null); then
echo "$name: Extraction failed!"
echo "$name: Forcing download..."
forceDownload=1
download $dest $source $name
fi
}
function installcmd {
checkPackages
askSudo
mkdir -p $temp
cd $temp
for i in $(seq 1 ${#codes[@]}); do
code=${codes[$(($i-1))]};
name=${names[$(($i-1))]};
echo "$name: Getting metadata..."
json="$code.json"
wget -O "$json" "https://data.services.jetbrains.com/products/releases?code=$code&latest=true&type=release" -q
prefix='"linux":[{]"link":"'
regex='.*?[^\\]'
suffix='",'
result=$(cat "$json" | grep -Po "$prefix$regex$suffix")
result=${result#$prefix}
result=${result%$suffix}
dfile=$(basename $result)
download $dfile $result $name
echo "$name: Removing leftovers..."
rm -rf $json 2> /dev/null
echo "$name: Installing..."
$($SUDO rm -rf $installDest/$name 2> /dev/null)
$($SUDO mv $name $installDest)
$($SUDO chmod -R o+rw $installDest/$name)
$($SUDO chown -R root:root $installDest/$name)
echo "$name: Package installed."
if [ $removeDownloads -eq 0 ]; then
echo "$name: Download is preserved at $temp/$dfile"
fi
done
for i in $(seq 1 ${#codes[@]}); do
name=${names[$(($i-1))]};
if [ $noLaunch -eq 0 ]; then
echo "$name: Launching..."
echo "$name: Don't forget to create a desktop entry in 'Configure' -> 'Create Desktop Entry'!"
logFile=$temp/$name'Install.log'
rm -rf $logFile 2> /dev/null
$($installDest/$name/bin/$name.sh > $logFile 2>&1)
if [ -s $logFile ]; then
echo "$name: The launch outputted some errors/warnings! Find them in $logFile"
fi
else
echo "$name: Launch the program with $installDest/$name/bin/$name.sh";
echo "$name: Don't forget to create a desktop entry in 'Configure' -> 'Create Desktop Entry'!"
fi
done
}
function removecmd {
checkPackages
askSudo
if [ ! -d $installDest ]; then
echo "No packages installed."
echo "Done!"
exit 1
fi
cd $installDest
for i in $(seq 1 ${#codes[@]}); do
name=${names[$(($i-1))]};
if [ -d "$name" ]; then
echo "$name: Removing..."
$($SUDO rm -rf $name 2> /dev/null)
else
echo "$name: Package is not installed."
fi
done
echo "Done!"
}
if [ "$1" = "install" ] || [ "$1" = "upgrade" ]; then
installcmd
elif [ "$1" = "remove" ]; then
removecmd
exit 1
elif [ "$1" = "clean" ]; then
removeDownloads=1
elif [ "$1" = "--help" ]; then
helpcmd
exit 1
elif [ ${#@} -eq 0 ]; then
echo "No command specified. See --help for more"
exit 2
else
echo "Wrong command specified. See --help for more"
exit 2
fi
if [ $removeDownloads -eq 1 ]; then
rm -rf $temp 2> /dev/null #always
echo "All downloads removed."
else
rmdir $temp 2> /dev/null #only if empty
fi