Mustang deb file for Ubuntu (Dapper)


I’m in mid process of creating a “.deb” file containing Java 6. Why am I’m blogging about it? Well because it’s been next to impossible to do. I started trying to install Mustang about a month or two ago and I cuoldn’t get it. I posted on Kubuntu forums and got nowhere. The problem is that Java has always been a pain to install on Linux. Why somebody doesn’t rectify that longstanding issues puzzles me to this very day. To start you have to figure out which version of the JDK/JRE you want. (Windows, Linux, Solaris, SPARC, what the hell is a SPARC anyway?) That’s not too bad then you download the package. Debian/Ubuntu purists like myself hate the thought of installing software without a .deb file yet Sun offers no .deb distribution for Java. (They’re very friendly towards Windows and RedHat based distros.) So now you have this dumb self extracting file sitting on your hard drive that your afraid to touch until you can find the magic wand that turns it into that precious .deb you’ve been dreaming about. If you’ve read my blog before you may have seen an old article explaining the proper way to install Java on Debian/Ubuntu systems. That only half applies to the latest release of Java. According to my research (and prior efforts) the make-jpkg scripts will not work with Mustang leaving Debian-based distro users to further stare holes into the section of the screen higlighting a useless bin file. If your smart enough you’ll type make-jpkg mustang into Google and feel rejoiced at the link near the top of the page. (Currently I’m getting connection refused on the link but Google’s cached copy didn’t let me down!) Before you break out the fine wine let me pop your balloon and tell you that the new make-jpkg-mustang script doesn’t work. That’s where I started from this afternoon. Since nobody has been able to help me with an alternate reccomendation I’ve taken matters into my own hands. I rolled up my sleeves, dug into the broken script and patched it as best as I can. After a few iterations of “read script, run, cuss, edit, repeat” I was finally able to generate the “.deb” file I so longed to have stuffed into my distro. I installed my beauty and ran “sudo update alternatives –config java” to adjust my system to the latest and greatest from Sun only to find out in horror that I had in fact installed a JRE not a JDK. As a Java developer a JRE is next to useless to me so again I glared holes into the center of my Konqueror window frame. I was confused! I confirmed that I did in fact download a JDK yet what I had created and installed with the make-jpkg-mustang script was only a JRE!

I’m no Debian developer…
But I have read up on the .deb file format in the past, so I know a little about how it works. After reading the script, shedding a few more random swear words and a few more iterations of the earlier cycle I mustered a deb archive that included the entire JDK. I was happy as … until I re-ran update alternatives. Where the heck was my new JDK? Four more iterations of the cycle that would make Eddie Murphy cover his ears and I think I finally have something. I’m no Debian guru like I said before so my revisions to the script may be flawed or horribly incorrect but now Mustang shows up in update-alternatives as well as in Synaptic. Also, all of the JDK is in there instead of just the JVM. I’m placing my revisions below so you all can cheer, laugh, poke fun at, or rip apart. Hit me up, people…

/usr/bin/make-jpkg-mustang

#!/bin/bash
# make-jpkg-mustang v0.7.5
# Java 1.6 (mustang) JRE binary releases debian package creator
#
# (c)-left by Trevi� - <http://italy.copybase.ch/blog/>
# Released under FSF GPL v2 terms

echo ''
arch="$(dpkg --print-architecture)"
if ( [ -n "$1" ] && [ -f "$1" ] && [ -n "$(file -i "$1" | grep  "application/x-shellscript")" ] ); then    javafile="$(basename "$1")";    javadir="$(dirname "$1")";    if( [ "$javadir" = "." ] ); then       javadir="$PWD"    fi fi
if [ "$arch" = "amd64" ]; then    typestring=" AMD64 " elif [ "$arch" = "i386" ]; then    typestring=" "; else    echo -e "No available Sun's Java package for your arch.\nExiting..."    exit; fi
olddir="$PWD" workingdir="/tmp" cd "$workingdir"
if ( [ ! -d "$workingdir" ] || [ ! -w "$workingdir" ] ); then    echo -n "The standard script working directory ($workingdir) isn't writable, please select another"    if ( [ -w "$HOME" ] ); then       echo " leave this field empty to use your home directory ($HOME)"    fi    read -p "Temporary directory: " newworkingdir    if ( [ "$newworkingdir" = "" ] && [ -w "$HOME" ] ); then       workingdir="$HOME"    elif ( [ -d "$newworkingdir" ] && [ -w "$newworkingdir" ] ); then       workingdir="$newworkingdir"    else       echo -e "You've selected a bad directory!\nExiting...";       exit    fi fi
if [ -z "$javafile" ]; then    downlink=$(wget -q -O - "http://download.java.net/jdk6/binaries/" | grep "Linux${typestring}self-extracting JDK file" -1 | grep "http:\/\/.*jdk-6.*bin.*linux-.*\.bin" | cut -d'"' -f2)        javafile="$(basename "$downlink")"        if [ -n "$downlink" ]; then       echo -e "\nDownloading $javafile in $workingdir...\n"       sleep 3       wget -c "$downlink" -O "$javafile";    else       echo -e "\nJava download link not found; please notify the author at <trevi55@gmail.com>"       cd "$olddir"       exit;    fi    wait    echo -e "\nDownload Complete!" else    echo "Copying $javadir/$javafile to $workingdir"    cp -fu "$javadir/$javafile" $workingdir    wait    echo -e "\nCopy Complete!" fi
echo -e "\nNow will be run '$javafile', you must accept the Sun's Java license to generate your debian package\n\nPress any key to continue"
read -n1
jdkdir="$workingdir/jdk1.6.0"
rm -rf "$jdkdir"
chmod +x "$javafile"; "./$javafile" > /dev/stdout 2>&1 | grep -E -v ' jdk1\.6\.0\/|UnZipSFX'
wait
if [ ! -d "$jdkdir" ]; then    echo -e "The package you've choosen isn't a good Java binary self-extracting JDK package.\nExiting..."    cd "$olddir"    exit; fi
echo -e "\nCreating the debian package directory tree..." pkgdir="$workingdir/sun-java6" exdir="/usr/share/make-jpkg-mustang"
rm -fr "$pkgdir" mkdir -p "$pkgdir/DEBIAN" mkdir -p "$pkgdir/usr/lib/jvm/java-1.6.0-sun" mkdir -p "$pkgdir/usr/share/applications" mkdir -p "$pkgdir/usr/share/pixmaps" mv -f "$jdkdir" "./sun-jdk-1.6.0" mv -f "./sun-jdk-1.6.0" "$pkgdir/usr/lib/" rm -fr "$pkgdir/usr/lib/sun-jdk-1.6.0/jre/.systemPrefs" ln -sf "/usr/lib/sun-jdk-1.6.0/jre/plugin/desktop/sun_java.png" "$pkgdir/usr/share/pixmaps" mv -f "$pkgdir/usr/lib/sun-jdk-1.6.0/jre/bin/java" "$pkgdir/usr/lib/sun-jdk-1.6.0/jre/bin/java-bin" cp -f "$exdir/java.ex" "$pkgdir/usr/lib/sun-jdk-1.6.0/jre/bin/java"
for manfile in $(find "$pkgdir/usr/lib/sun-jdk-1.6.0/jre/man/" -type f); do    if [ ! -f "$pkgdir/usr/lib/sun-jdk-1.6.0/jre/bin/$(basename "$manfile" | cut -d'.' -f1)" ]; then       rm -f "$manfile";    else       gzip "$manfile";    fi done
for item in $(find "$pkgdir/usr/lib/sun-jdk-1.6.0/jre/lib/desktop/" -type d ! -regex '.*Contrast.*'); do    mkdir -p ${item//\/lib\/sun-jdk-1.6.0\/jre\/lib\/desktop//share}; done
for item in $(find "$pkgdir/usr/lib/sun-jdk-1.6.0/jre/lib/desktop/" -type f ! -regex '.*Contrast.*'); do    ln -sf ${item//$pkgdir/} ${item//\/lib\/sun-jdk-1.6.0\/jre\/lib\/desktop//share}; done
echo "Generating debian package control file..." cp -f "$exdir/postinst.ex" "$pkgdir/DEBIAN/postinst" cp -f "$exdir/postrm.ex" "$pkgdir/DEBIAN/postrm"
jreversion="$("$pkgdir/usr/lib/sun-jdk-1.6.0/jre/bin/java" -version > /dev/stdout 2>&1 | grep "build 1.6.0" --max-count=1 | cut -d' ' -f6 | cut -d')' -f1)" packager="$(whoami)" size=$(du -s "$pkgdir/usr" | cut -f1)
cat "$exdir/control.ex" | sed "s/{version}/$(echo "$jreversion")/g" | sed "s/{size}/$size/g" | sed "s/{user}/$packager/g" | sed "s/{arch}/$arch/g"  > "$pkgdir/DEBIAN/control"
# TODO search for new bin to add to postinst/postrm
echo "Calculating md5 sum..." (cd "$pkgdir" >/dev/null ; find . -type f ! -regex '.*/DEBIAN/.*' -printf '%P' | xargs -r0 md5sum > "DEBIAN/md5sums"; cd "$workingdir" > /dev/null) > /dev/null wait
package=$(cat "$pkgdir/DEBIAN/control" | grep "Package:" --max-count=1 |cut -d' ' -f2)   
if [ -w "$olddir" ]; then    debdir="$olddir"; else    debdir="$HOME" fi
debpkg="${package}_$(echo "$jreversion")_${arch}.deb"; echo -e "Building debian package in $debdir/$debpkg..."
fakeroot dpkg-deb --build "$pkgdir" "$debdir/$debpkg" > /dev/null 2>&1 wait
echo "Removing jdk and debian package temporary directory trees..." rm -fr "$pkgdir" "$jdkdir" wait
echo -e "\nDo you want remove temporary binary file \"$workingdir/$javafile\"?" read -p " [Y/n]: " -n1 removefile; if [ "$removefile" = "$(echo Y | tr [:upper:] [:lower:])" ]; then    rm -r "$workingdir/$javafile" fi
echo -e "\n\nPackage done!"
echo -e "\nDo you want to install the $debpkg now?" read -p " [Y/n]: " -n1 installdeb; if [ "$installdeb" = "$(echo Y | tr [:upper:] [:lower:])" ]; then    if [ $(whoami) = "root" ]; then       dpkg -i "$debdir/$debpkg";    else       echo ''       sudo dpkg -i "$debdir/$debpkg";    fi else    echo -e "\n\nYou must install manually the package $debdir/$debpkg" fi
echo -e "\nYou can always check your java version using \"update-alternatives\" and \"java -version\"\n\nScript made by Trevi� <http://italy.copybase.ch/blog>\nSuggestions, bugs and so on... trevi55@gmail.com";
cd "$olddir"

/usr/share/make-jpkg-mustang/postinst.ex

#!/bin/bash

j2se_base="/usr/lib/sun-jdk-1.6.0/jre" priority=3050
# alternative <program> function program_alternative() {     local program="$1"     update-alternatives \    --install "/usr/bin/$program" "$program" \    "$j2se_base/bin/$program" "$priority" \    --slave "/usr/share/man/man1/$program.1.gz" "$program.1.gz" \    "$j2se_base/man/man1/$program.1.gz" }
function select_alternative() {     local program="$1"     update-alternatives --config "$program" }
program_alternative java program_alternative java_vm program_alternative javaws program_alternative jcontrol program_alternative keytool program_alternative orbd program_alternative pack200 program_alternative policytool program_alternative rmid program_alternative rmiregistry program_alternative servertool program_alternative tnameserv program_alternative unpack200
# derive the architecture-specific  # directory for the plugin arch_dir="$(dpkg --print-architecture)"
# assemble the plugin path plugin_dir="$j2se_base/plugin/$arch_dir"
# netscape netscape_dir="/usr/lib/netscape/plugins-libc6" [ -d "$netscape_dir" ] || install -d -m 755 "$netscape_dir" update-alternatives \     --install "$netscape_dir/libjavaplugin.so" \    "netscape-javaplugin.so" \        "$plugin_dir/ns7-gcc29/libjavaplugin.so" "$priority"
# mozilla mozilla_dir="/usr/lib/mozilla/plugins" [ -d "$mozilla_dir" ] || install -d -m 755 "$mozilla_dir" update-alternatives \     --install "$mozilla_dir/libjavaplugin.so" \    "mozilla-javaplugin.so" \        "$plugin_dir/ns7/libjavaplugin_oji.so" "$priority"
# old firefox / swiftfox mozillafirefox_dir="/usr/lib/mozilla-firefox/plugins" [ -d "$mozillafirefox_dir" ] || install -d -m 755 "$mozillafirefox_dir" update-alternatives \     --install "$mozillafirefox_dir/libjavaplugin.so" \    "mozilla-firefox-javaplugin.so" \        "$plugin_dir/ns7/libjavaplugin_oji.so" "$priority"
# firefox firefox_dir="/usr/lib/firefox/plugins" [ -d "$firefox_dir" ] || install -d -m 755 "$firefox_dir" update-alternatives \     --install "$firefox_dir/libjavaplugin.so" \    "firefox-javaplugin.so" \        "$plugin_dir/ns7/libjavaplugin_oji.so" "$priority"
# Remove obsolete javaplugin from users' homes for user in $(ls /home); do     if [ -d "/home/$user/.mozilla/plugins" ]; then       rm -f "/home/$user/.mozilla/plugins/libjavaplugin_oji.so"    fi; done
if [ -d "/root/.mozilla/plugins" ]; then    rm -f "/root/.mozilla/plugins/libjavaplugin_oji.so" fi
# menus if [ -n "$(which update-menus)" ]; then    update-menus; fi
# mime if [ -n "$(which update-mime)" ]; then    update-mime; fi

/usr/share/make-jpkg-mustang/postrm.ex

#!/bin/bash

j2se_base="/usr/lib/sun-jdk-1.6.0/jre"
# alternative <program> function program_alternative() {     local program="$1"     update-alternatives \    --remove "$program" "$j2se_base/bin/$program" }
program_alternative java program_alternative java_vm program_alternative javaws program_alternative jcontrol program_alternative keytool program_alternative orbd program_alternative pack200 program_alternative policytool program_alternative rmid program_alternative rmiregistry program_alternative servertool program_alternative tnameserv program_alternative unpack200
# derive the architecture-specific  # directory for the plugin arch_dir="$(dpkg --print-architecture)"
# assemble the plugin path plugin_dir="$j2se_base/plugin/$arch_dir"
# netscape update-alternatives \     --remove "netscape-javaplugin.so" "$plugin_dir/ns7-gcc29/libjavaplugin.so"
# mozilla update-alternatives \     --remove "mozilla-javaplugin.so" "$plugin_dir/ns7/libjavaplugin_oji.so"
# old firefox / swiftfox update-alternatives \     --remove "mozilla-firefox-javaplugin.so" "$plugin_dir/ns7/libjavaplugin_oji.so"
# firefox update-alternatives \     --remove "firefox-javaplugin.so" "$plugin_dir/ns7/libjavaplugin_oji.so"
# menus #update-menus
# mime update-mime

/usr/share/make-jpkg-mustang/control.ex

Package: sun-java6
Priority: optional
Section: libs
Installed-Size: {size}
Maintainer: {user}
Architecture: {arch}
Version: {version}
Provides: java-virtual-machine, java2-runtime
Depends: libasound2 (>> 1.0.10), libc6 (>= 2.3.4-1), libgcc1 (>= 1:4.0.2), libstdc++5 (>= 1:3.3.4-1), libx11-6, libxext6, libxi6, libxp6, libxtst6
Recommends: gsfonts-x11, make-jpkg-mustang
Suggests: ttf-baekmuk, ttf-kochi-gothic | ttf-kochi-gothic-naga10, ttf-kochi-mincho | ttf-kochi-mincho-naga10, ttf-arphic-bsmi00lp
Description: Sun Java(TM) Runtime Environment (JRE) 1.6.0
 The Sun Java Platform Standard Edition Runtime Environment (JRE) 1.6.0
 contains the Java virtual machine, runtime class libraries, and
 Java application launcher that are necessary to run programs written
 in the Java progamming language. It is not a development environment and
 doesn't contain development tools such as compilers or debuggers.
 .
 Package made using make-jpkg-mustang by Trevi�

7 thoughts on “Mustang deb file for Ubuntu (Dapper)

  1. Yes I did. As a matter of fact that was my first course of action when originally attempting to install JDK-1.5. The RPM created a structure that was unfamiliar to my Debian distro. It also left out the update-alternatives stuff. Maybe I missed something but I don’t think using Alien on the Sun RPM version is an acceptable solution. What has your experience been?

  2. Very interesting, though not so helpful… Copying the script from your webpage is very error-prone because of character conversion. In the time I used to edit and fix your script I could have created my own…
    Why didn’t you provide a gzipped downlaod or a link to a text file?

    Hmm, I still have to check to postinst and postrm scripts😦

  3. D’oh! I initially tried to include the source as an attachment but the restrictions on wordpress appear to limit you to txt files. I’ll take the time to do a repost of this topic as it seems to have a lot of interest. Thanx for the feedback ttodorov!

  4. Hi,
    I found your blog via google by accident and have to admit that youve a really interesting blog🙂
    Just saved your feed in my reader, have a nice day🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s