Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 329 lines (283 sloc) 7.53 KB
#!/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"
fi
echo "Finding latest version from $IDEA_URL ..."
read url filename version skip_the_rest < <(wget --max-redirect 5 -O - -q $IDEA_URL | LC_ALL=C sed -n -e "/.*\"\(http:\/\/.*\/idea$flavor-.*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
}
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