-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild-package
executable file
·292 lines (256 loc) · 6.91 KB
/
build-package
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/bin/bash
set -e
#set -x
force=false
umask=022
uname_s=$(uname -s)
usage() {
echo "usage: $0 OPTIONS" >&2
echo "Use $0 -? for usage help" >&2
exit 1
}
detect_platform() {
if [[ -r /etc/debian_version ]]
then
echo "debian"
return
fi
echo "Could not detect platform, use -p to specify." >&2
}
build_common() {
rm -rf root
if [ ! -z "$src_dir" ]
then
echo "Copying PyCharm from $src_dir"
mkdir -p root/usr/share/jetbrains
cp -r "$src_dir" root/usr/share/jetbrains/pycharm
else
echo "Unpacking tarball"
mkdir -p root/usr/share/jetbrains/pycharm
$tar --strip-components 1 -C root/usr/share/jetbrains/pycharm -zxf download/$filename
fi
mkdir -p root/usr/bin
cp pycharm.in root/usr/bin/pycharm
chmod +rx root/usr/bin/pycharm
mkdir -p root/usr/share/applications
cp pycharm.desktop root/usr/share/applications/pycharm.desktop
mkdir -p root/etc/pycharm
cp pycharm.vmoptions.README root/etc/pycharm/
echo "
Original pycharm.vmoptions:
" >> root/etc/pycharm/pycharm.vmoptions.README
cat root/usr/share/jetbrains/pycharm/bin/pycharm.vmoptions >> root/etc/pycharm/pycharm.vmoptions.README
fn=/tmp/pycharm.vmoptions.$$
cp root/usr/share/jetbrains/pycharm/bin/pycharm.vmoptions $fn
cat $fn | grep -v yjpagent > root/usr/share/jetbrains/pycharm/bin/pycharm.vmoptions
rm $fn
}
calculate_package_filename() {
case "$platform" in
debian)
# TODO: Add arch to the filename (i386, amd64)
repo=repository/debian
mkdir -p $repo
package_filename=$repo/pycharm-$FLAVOR_LOWER-$version.deb
;;
esac
}
build_debian() {
build_common
mkdir -p root/etc/sysctl.d
cp debian/sysctl-99-pycharm.conf root/etc/sysctl.d/99-pycharm.conf
chmod +rx root/usr/bin/pycharm
mkdir -p root/DEBIAN
sed \
-e "s,OTHER_FLAVOR_LOWER,$OTHER_FLAVOR_LOWER," \
-e "s,OTHER_FLAVOR,$OTHER_FLAVOR," \
-e "s,FLAVOR_LOWER,$FLAVOR_LOWER," \
-e "s,FLAVOR,$flavor," \
-e "s,VERSION,$version," \
debian/control.in > root/DEBIAN/control
cp debian/postinst root/DEBIAN/postinst
chmod +rx root/DEBIAN/postinst
echo > debian/fakeroot.save
FAKEROOT="fakeroot -i debian/fakeroot.save -s debian/fakeroot.save"
$FAKEROOT -- chown -R root:root root/
$FAKEROOT -- dpkg-deb -b root $package_filename
rm debian/fakeroot.save
if [ "$update_repository" = 1 ]
then
(cd $repo && dpkg-scanpackages -m . /dev/null | tee Packages | gzip > Packages.gz )
fi
}
tar=`which gtar || true`
if [ ! -x "$tar" ]
then
tar=`which tar`
if [ ! -x "$tar" ]
then
echo "Could not find usable tar" >&2
exit 1
fi
fi
while getopts "f:Fs:v:u?" flag
do
case "$flag" in
s)
src_dir=$OPTARG
;;
f)
flavor=$OPTARG
if [ "$flavor" != "professional" -a "$flavor" != "community" ]
then
usage
fi
;;
v)
version=$OPTARG
;;
u)
update_repository=1
;;
F)
force="true"
;;
?)
less README.md
exit 0
;;
esac
done
if [ -z "$platform" ]
then
platform=$(detect_platform)
fi
if [ -z "$flavor" ]
then
if [[ -r $HOME/.pycharm-dpkg ]]
then
flavor=$(sed -n "s,^flavor=\(.*\),\1,p" "$HOME/.pycharm-dpkg")
if [ -z "$flavor" ]
then
echo "Defaulting to the 'community' flavor, use -f to override."
flavor=community
echo "Saving the flavor so you don't have to specify it again."
echo flavor=$flavor >> "$HOME/.pycharm-dpkg"
fi
else
echo "Defaulting to the 'community' flavor, use -f to override."
flavor=community
echo "Saving the flavor so you don't have to specify it again."
echo flavor=$flavor >> "$HOME/.pycharm-dpkg"
fi
if [ -z "$flavor" ]
then
usage
fi
else
echo "Saving the flavor so you don't have to specify it again."
if [[ -r $HOME/.pycharm-dpkg ]]
then
sed -i "s/flavor=.*/flavor=$flavor/g" "$HOME/.pycharm-dpkg"
else
echo flavor=$flavor > "$HOME/.pycharm-dpkg"
fi
fi
if [ $flavor = "community" ]
then
OTHER_FLAVOR_LOWER=professional
OTHER_FLAVOR=professional
FLAVOR_LOWER=community
else
OTHER_FLAVOR_LOWER=community
OTHER_FLAVOR=community
FLAVOR_LOWER=professional
fi
#~ if [ -z "$channel" ]
#~ then
#~ if [[ -r $HOME/.intellij-idea-dpkg ]]
#~ then
#~ channel=$(sed -n "s,^channel=\(.*\),\1,p" "$HOME/.intellij-idea-dpkg")
#~ if [ -z "$channel" ]
#~ then
#~ echo "Defaulting to the 'eap' channel, use -c to override."
#~ channel=eap
#~ echo "Saving the channel so you don't have to specify it again."
#~ echo channel=$channel >> "$HOME/.intellij-idea-dpkg"
#~ fi
#~ else
#~ echo "Defaulting to the 'eap' channel, use -c to override."
#~ channel=eap
#~ echo "Saving the channel so you don't have to specify it again."
#~ echo channel=$channel >> "$HOME/.intellij-idea-dpkg"
#~ fi
#~ if [ -z "$channel" ]
#~ then
#~ usage
#~ fi
#~ else
#~ if [[ -r $HOME/.intellij-idea-dpkg ]]
#~ echo "Saving the channel so you don't have to specify it again."
#~ then
#~ sed -i "s/channel=.*/channel=$channel/g" "$HOME/.intellij-idea-dpkg"
#~ else
#~ echo channel=$channel > "$HOME/.intellij-idea-dpkg"
#~ fi
#~ fi
if [ -z "$src_dir" ]
then
if [ -z "$version" ]
then
versionURL="https://www.jetbrains.com$(wget -q "https://www.jetbrains.com/pycharm/download/" -O - | grep -o -P "<script type=\"text/javascript\" src=\"/js2/version.js\?ver=[0-9]+\"></script>" | grep -o -E "/js2/version.js\?ver=[0-9]+")"
version=$(wget -q "$versionURL" -O - | grep -E "var versionPyCharmLong = \"[0-9]+\.[0-9]+\.[0-9]+\"" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
echo "The latest version is $version"
fi
url=http://download.jetbrains.com/python/pycharm-$flavor-$version.tar.gz
filename=pycharm-$flavor-$version.tar.gz
else
if [ -z "$version" ]
then
echo "When building from a directory, a version has to be specified with -v." >&2
exit 1
fi
if [ ! -d "$src_dir" ]
then
echo "Not a directory: $src_dir" >&2
exit 1
fi
fi
calculate_package_filename
if [ -r "$package_filename" ]
then
if [ $force = "false" ]
then
echo "The requested version ($version) already exist in the repository, add -F to force a re-build of the package" >&2
exit 1
else
echo "WARNING: re-building package for version $version" >&2
fi
fi
if [ -z "$src_dir" ]
then
mkdir -p download
# It would be possible to use the MD5 sum as a check here, then there would be no need to every force a download
#if [ -r "download/$filename" ]
#then
# echo "$filename is already downloaded"
#else
# echo "Downloading $url..."
# wget -O "download/$filename" $url
#fi
echo "Downloading version $version..."
if [ `wget -q -P download -N $url; echo $?` != "0" ]
then
echo "Could not download $url" >&2
exit 1
fi
if [ ! -r download/$filename ]
then
echo "wget didn't place the downloaded file where expected: download/$filename" >&2
exit 1
fi
fi
case "$platform" in
debian)
build_debian;;
esac