-
Notifications
You must be signed in to change notification settings - Fork 20
/
build-package
executable file
·350 lines (303 loc) · 8.59 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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/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
if [[ $uname_s == "SunOS" ]]
then
echo "solaris"
return
fi
echo "Could not detect platform, use -p to specify." >&2
}
find_latest() {
if [ "$IDEA_URL" = "" ]
then
# IDEA_URL="http://confluence.jetbrains.net/display/IDEADEV/IDEA+X+EAP"
# IDEA_URL="http://confluence.jetbrains.net/display/IDEADEV/IDEA+10.5+EAP"
# IDEA_URL="http://confluence.jetbrains.net/display/IDEADEV/IDEA+11.1+EAP"
# IDEA_URL="http://confluence.jetbrains.net/display/IDEADEV/IDEA+12+EAP"
# IDEA_URL="http://confluence.jetbrains.net/display/IDEADEV/IDEA+12.1+EAP"
# IDEA_URL="http://confluence.jetbrains.net/display/IDEADEV/IDEA+13+EAP"
# IDEA_URL="http://confluence.jetbrains.net/display/IDEADEV/IDEA+13.1+EAP"
# IDEA_URL="http://confluence.jetbrains.net/display/IDEADEV/IDEA+14+EAP"
# IDEA_URL="http://confluence.jetbrains.net/display/IDEADEV/IDEA+14.1+EAP"
# IDEA_URL="http://confluence.jetbrains.net/display/IDEADEV/IDEA+15+EAP"
# IDEA_URL="http://confluence.jetbrains.net/display/IDEADEV/IDEA+16+EAP"
# IDEA_URL="https://confluence.jetbrains.com/display/IDEADEV/IDEA+2016.1+EAP"
# IDEA_URL="https://confluence.jetbrains.com/display/IDEADEV/IDEA+2016.2+EAP"
# IDEA_URL="https://confluence.jetbrains.com/display/IDEADEV/IDEA+2016.3+EAP"
# IDEA_URL="https://confluence.jetbrains.com/display/IDEADEV/IDEA+2017.1+EAP"
IDEA_URL="https://confluence.jetbrains.com/display/IDEADEV/IDEA+2017.2+EAP"
fi
export LC_ALL=C
echo "Finding latest version from $IDEA_URL ..."
read url filename version skip_the_rest < <(wget --max-redirect 5 -O - -q $IDEA_URL | \
sed -n -e 's,\(href=.[^ "]\),\n\1,gp' | \
sed -n -e 's,^href.*\(http[^ "]*\).*,\1,p' | sed -n "/tar.gz$/ {
s,\(http.*:\/\/.*\/idea$flavor-.*tar.gz\),\1,p
s,.*\(ideaI.-[.0-9].*.tar.gz\).*,\1,p
s,.*-\([.0-9].*\).tar.gz,\1,p
}" | xargs)
if [ -z "$url" -o -z "$filename" -o -z "$version" ]
then
echo "Unable to find the latest version." >&2
exit 1
fi
}
build_common() {
rm -rf root
if [ ! -z "$src_dir" ]
then
echo "Copying IDEA from $src_dir"
mkdir -p root/usr/share/jetbrains
cp -r "$src_dir" root/usr/share/jetbrains/intellij-idea
else
echo "Unpacking tarball"
mkdir -p root/usr/share/jetbrains/intellij-idea
$tar --strip-components 1 -C root/usr/share/jetbrains/intellij-idea -zxf download/$filename
fi
mkdir -p root/usr/bin
cp idea.in root/usr/bin/idea
chmod +rx root/usr/bin/idea
mkdir -p root/usr/share/applications
if [ "$FLAVOR_LOWER" == "ic" ]
then
# IC version has different icon name
sed 's|/idea128\.png$|/idea_CE128.png|' intellij-idea.desktop > root/usr/share/applications/intellij-idea.desktop
else
cp intellij-idea.desktop root/usr/share/applications/intellij-idea.desktop
fi
mkdir -p root/etc/intellij-idea
cp idea.vmoptions.README root/etc/intellij-idea/
echo "
Original idea.vmoptions:
" >> root/etc/intellij-idea/idea.vmoptions.README
cat root/usr/share/jetbrains/intellij-idea/bin/idea.vmoptions >> root/etc/intellij-idea/idea.vmoptions.README
fn=/tmp/idea.vmoptions.$$
cp root/usr/share/jetbrains/intellij-idea/bin/idea.vmoptions $fn
cat $fn | grep -v yjpagent > root/usr/share/jetbrains/intellij-idea/bin/idea.vmoptions
rm $fn
# If idea.license is provided in the bin directory of intellij-idea, this
# license is applied to the genereated package. This allows to generate a
# certified package for the Ultimate edition of the IDE.
if [ -f "idea.license" ]
then
bin_dir="root/usr/share/jetbrains/intellij-idea/bin"
echo "Copy licence file to $bin_dir"
cp idea.license $bin_dir
fi
}
calculate_package_filename() {
case "$platform" in
solaris)
repo=`pwd`/repository/solaris/`uname -p`/`uname -r`
mkdir -p $repo
package_filename=$repo/intellij-idea-$version-`uname -s``uname -r`-`uname -p`.pkg
;;
debian)
# TODO: Add arch to the filename (i386, amd64)
repo=repository/debian
mkdir -p $repo
package_filename=$repo/intellij-idea-$FLAVOR_LOWER-$version.deb
;;
esac
}
build_solaris() {
build_common
rm -rf solaris
mkdir -p solaris
sed -e "s,@VERSION@,$version," pkginfo.in > solaris/pkginfo
cp prototype.in solaris/prototype
pkgproto root=/ | awk '
{$5="root"}
$3 ~ /^\/$/ {getline}
$3 ~ /^\/usr$/ {getline}
$3 ~ /^\/usr\/bin$/ {getline}
$3 ~ /^\/usr\/share$/ {getline}
$3 ~ /^\/usr\/share\/applications$/ {getline}
{printf $1 " " $2 " " $3 " " $4 " " $5 " " $6 " \n"}' >> solaris/prototype
pkgmk -o -d solaris -f solaris/prototype -r .
pkgtrans -s solaris $package_filename intellij-idea
echo "The package was successfully build in solaris/"
echo "To install run: pfexec pkgadd -d $package_filename"
if [ "$update_repository" = 1 ]
then
bldcat -b $repo
fi
}
build_debian() {
build_common
mkdir -p root/etc/sysctl.d
cp debian/sysctl-99-intellij.conf root/etc/sysctl.d/99-intellij.conf
chmod +rx root/usr/bin/idea
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:Fp:s:v:u?" flag
do
case "$flag" in
s)
src_dir=$OPTARG
;;
f)
flavor=$OPTARG
if [ "$flavor" != "IU" -a "$flavor" != "IC" ]
then
usage
fi
;;
p)
platform=$OPTARG
if [ "$platform" != "solaris" -a "$platform" != "debian" ]
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/.intellij-idea-dpkg ]]
then
flavor=$(sed -n "s,^flavor=\(.*\),\1,p" "$HOME/.intellij-idea-dpkg")
else
echo "Defaulting to the 'IU' flavor, use -f to override."
flavor=IU
fi
if [ -z "$flavor" ]
then
usage
fi
else
echo "Saving the flavor so you don't have to specify it again."
echo flavor=$flavor > "$HOME/.intellij-idea-dpkg"
fi
if [ $flavor = "IC" ]
then
OTHER_FLAVOR_LOWER=iu
OTHER_FLAVOR=IU
FLAVOR_LOWER=ic
else
OTHER_FLAVOR_LOWER=ic
OTHER_FLAVOR=IC
FLAVOR_LOWER=iu
fi
if [ -z "$src_dir" ]
then
if [ -z "$version" ]
then
find_latest
echo "The latest version is $version"
else
url=http://download.jetbrains.com/idea/idea$flavor-$version.tar.gz
filename=idea$flavor-$version.tar.gz
fi
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
solaris)
build_solaris;;
debian)
build_debian;;
esac