source: oracle-java7-installer/trunk/fuentes/debian/oracle-java7-installer.postinst @ 624

Last change on this file since 624 was 624, checked in by jrpelegrina, 4 years ago

First release to xenial

  • Property svn:executable set to *
File size: 11.4 KB
Line 
1#!/bin/sh
2#jinstall - Command line script to easily add new java directories to
3#'alternatives'. This sets the java as default, and you can switch your
4#default java with update-java-alternatives
5#
6#Copyright 2012 Bruce.Ingalls at gmail & Alin Andrei <webupd8@gmail.com>
7#GPL v3 Affero license at http://www.gnu.org/
8#Downloads & discussion at http://www.webupd8.org/
9#Tested on Ubuntu Oneiric; should require few changes for other modern Unix systems
10#Currently tested only with JDK, not JRE.
11# Not fully internationalized, including japanese man pages
12
13set -e
14
15. /usr/share/debconf/confmodule
16
17
18### Variables
19VER='0.7'
20
21# Folders
22J_INSTALL_DIR=/usr/lib/jvm/java-7-oracle
23OLDDIR=/usr/lib/oracle-jdk7-installer-unpackdir
24NEWDIR=/var/cache/oracle-jdk7-installer
25
26# Filenames and checksums
27case $(dpkg --print-architecture) in
28'i386'|'i586'|'i686')
29        arch=i386; dld=i586
30        # Must be modified for each release
31        SHA256SUM_TGZ="9ded1318a7223cf6e09ac4b6ee4db1f4c5d1aef1d3d291f6db8491a32eaa57ba"
32        ;;
33'amd64')
34        arch=amd64; dld=x64
35        # Must be modified for each release
36        SHA256SUM_TGZ="bad9a731639655118740bee119139c1ed019737ec802a630dd7ad7aab4309623"
37        ;;
38arm*)
39        arch=arm
40        if [ `uname -m` = "armv7l" ] || [ `uname -m` = "armv6l" ]; then
41                if [ -x /usr/bin/readelf ] ; then
42                        HARDFLOAT=`readelf -A /proc/self/exe | grep Tag_ABI_VFP_args`
43                        if [ -z "$HARDFLOAT" ]; then
44                                # Softfloat
45                                dld='arm-vfp-sflt'
46                                # Must be modified for each release
47                                SHA256SUM_TGZ="e9586d8605954a10c028a260fddd91e6ec09395cd797d7b0a307d4a668d7b0cf"
48                        else
49                                # Hardfloat
50                                dld='arm-vfp-hflt'
51                                # Must be modified for each release
52                                SHA256SUM_TGZ="71968c9893310a9338f4434257c1a188d41080335105bcb9b64051336d3c5fcd"
53                        fi
54                fi
55        else
56                echo "Oracle JDK 7 only supports ARM v6/v7."
57                arch=''
58        fi
59        ;;
60*)
61        echo "Please report to author unsupported platform '`uname -m`'.";
62        echo "Proceeding without web browser plugin support";
63        arch='';
64esac
65
66if [ ! $arch = "arm" ]; then
67        JAVA_VERSION=7u80 # Must be modified for each release!!!
68        J_DIR=jdk1.7.0_80 # Must be modified for each release!!!
69        FILENAME=jdk-${JAVA_VERSION}-linux-${dld}.tar.gz
70        PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/7u80-b15/$FILENAME # Must be modified for each release!!!
71        for JAVA_VERSION_OLD in `seq 1 79`; do #must be modified for each release ("1 3" for 7u4; "1 4" for 7u5, etc)
72                FILENAMES_OLD="jdk-7u${JAVA_VERSION_OLD}-linux-${dld}.tar.gz $FILENAMES_OLD"
73        done
74else
75# Must be modified for each release!!!
76        JAVA_VERSION=7u60 # Must be modified for each release!!!
77        J_DIR=jdk1.7.0_60 # Must be modified for each release!!!
78        FILENAME=jdk-${JAVA_VERSION}-linux-${dld}.tar.gz
79        PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/7u60-b19/$FILENAME # Must be modified for each release!!!
80        for JAVA_VERSION_OLD in `seq 1 59`; do #must be modified for each release ("1 3" for 7u4; "1 4" for 7u5, etc)
81                FILENAMES_OLD="jdk-7u${JAVA_VERSION_OLD}-linux-${dld}.tar.gz $FILENAMES_OLD"
82        done
83fi
84
85### Functions
86fp_exit_with_error() {
87        echo $1
88        echo "Oracle JDK 7 is NOT installed."
89        db_fset oracle-java7-installer/local seen false
90        exit 1
91}
92
93fp_download_and_unpack() {
94        cd /var/cache/oracle-jdk7-installer
95
96        db_get oracle-java7-installer/local
97        if [ -d "$RET" -a -f "$RET"/$FILENAME ]; then
98                echo "Installing from local file $RET/$FILENAME"
99                cp -f -p "$RET"/$FILENAME ${FILENAME}_TEMP
100                mv -f ${FILENAME}_TEMP $FILENAME
101        else # no local file
102                # use apt proxy
103                APT_PROXIES=$(apt-config shell \
104                http_proxy Acquire::http::Proxy \
105                https_proxy Acquire::https::Proxy \
106                ftp_proxy Acquire::ftp::Proxy \
107                dl_direct Acquire::http::Proxy::download.oracle.com \
108                dl_direct Acquire::http::Proxy::*.java.net \
109                )
110
111                [ -n "$APT_PROXIES" ] && eval export $APT_PROXIES
112
113                if [ "$dl_direct" = "DIRECT" ]; then
114                        unset http_proxy
115                        unset https_proxy
116                        unset ftp_proxy
117                fi
118
119                # setting wget options
120                :> wgetrc
121                echo "noclobber = off" >> wgetrc
122                echo "dir_prefix = ." >> wgetrc
123                echo "dirstruct = off" >> wgetrc
124                echo "verbose = on" >> wgetrc
125                echo "progress = dot:mega" >> wgetrc
126                echo "tries = 2" >> wgetrc
127
128                # downloading jdk7
129                echo "Downloading Oracle Java 7..."
130                WGETRC=wgetrc wget --continue --no-check-certificate -O $FILENAME --header "Cookie: oraclelicense=a" $PARTNER_URL \
131                        || fp_exit_with_error "download failed"
132                echo "Download done."
133        fi # end if local file
134
135        # Removing outdated cached downloads
136        echo "Removing outdated cached downloads..."
137        rm -vf $FILENAMES_OLD
138
139        # Verify SHA256 checksum of (copied or downloaded) tarball
140        rm -rf jdk*/
141        echo "$SHA256SUM_TGZ  $FILENAME" | sha256sum -c > /dev/null 2>&1 \
142                || fp_exit_with_error "sha256sum mismatch $FILENAME"
143
144        # Unpacking and checking the plugin
145        tar xzf $FILENAME || fp_exit_with_error "cannot unpack jdk7"
146}
147
148safe_move() {
149        [ ! -f $OLDDIR/$1 ] || [ -f $NEWDIR/$1 ] || mv $OLDDIR/$1 $NEWDIR/$1 2> /dev/null || true
150        [ ! -f $OLDDIR/$1 ] || [ ! -f $NEWDIR/$1 ] || rm -f $OLDDIR/$1 2> /dev/null || true
151}
152
153### Main
154
155# Create dirs
156mkdir -p /var/cache/oracle-jdk7-installer /usr/lib/jvm /usr/lib/oracle-jdk7-installer-unpackdir
157# Without this, an error is displayed if the folder doesn't exist:
158mkdir -p /usr/lib/mozilla/plugins/
159
160fp_download_and_unpack
161
162# Copy JDK to the right dir
163mv $J_DIR java-7-oracle
164rm -rf /usr/lib/jvm/java-7-oracle
165cp -rf java-7-oracle /usr/lib/jvm/
166
167# There's no javaws on arm
168if [ ! $arch = "arm" ]; then
169# Install javaws-wrapper.sh
170        mv $J_INSTALL_DIR/jre/bin/javaws $J_INSTALL_DIR/jre/bin/javaws.real
171        install -m 755 javaws-wrapper.sh $J_INSTALL_DIR/jre/bin/javaws
172fi
173
174# Install jar.binfmt
175install -m 755 jar.binfmt $J_INSTALL_DIR/jre/lib/jar.binfmt
176
177# Install OpenJDK's font config
178install -m 755 fontconfig.Ubuntu.properties $J_INSTALL_DIR/jre/lib/
179
180# Clean up
181rm -rf java-7-oracle
182
183# To add when an older version exists:
184# safe_move jdk-7u2-linux-x64.tar.gz #must be modified for each release
185# safe_move jdk-7u2-linux-i586.tar.gz #must be modified for each release
186# Remove previous versions, if they exist
187rmdir $OLDDIR 2> /dev/null || true
188
189db_fset oracle-java7-installer/local seen false
190
191# This step is optional, recommended, and affects code below.
192ls $J_INSTALL_DIR/man/man1/*.1 >/dev/null 2>&1 && \
193  gzip -9 $J_INSTALL_DIR/man/man1/*.1 >/dev/null 2>&1
194
195# Increment highest version by 1.
196# Also assumes all Java helper programs (javaws, jcontrol, etc) at same version as java.
197# These helpers should be slaves, or in the same path as java; thus, a reasonable assumption.
198LATEST=1
199LATEST=$((`LANG=C update-alternatives --display java | grep ^/ | sed -e 's/.* //g' | sort -n | tail -1`+1))
200
201# Create .java-7-oracle.jinfo file header:
202[ -e /usr/lib/jvm/.java-7-oracle.jinfo ] && rm -f /usr/lib/jvm/.java-7-oracle.jinfo
203echo "name=java-7-oracle
204alias=java-7-oracle
205priority=$LATEST
206section=non-free
207" > /usr/lib/jvm/.java-7-oracle.jinfo
208
209# Link JRE files
210for f in $J_INSTALL_DIR/jre/bin/*; do
211        name=`basename $f`;
212        if [ ! -f "/usr/bin/$name" -o -L "/usr/bin/$name" ]; then
213                # Some files, like jvisualvm might not be links
214                if [ -f "$J_INSTALL_DIR/man/man1/$name.1.gz" ]; then
215                        if [ ! $arch = "arm" ]; then
216                                update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/jre/bin/$name $LATEST \
217                                        --slave /usr/share/man/man1/$name.1.gz $name.1.gz $J_INSTALL_DIR/man/man1/$name.1.gz
218                                echo "jre $name $J_INSTALL_DIR/jre/bin/$name" >> /usr/lib/jvm/.java-7-oracle.jinfo
219                        else
220                                # There's no jmc, javaws or jvisualvm on arm
221                                [ ! $name = "jmc" ] && [ ! $name = "javaws" ] && [ ! $name = "jvisualvm" ] && update-alternatives --install /usr/bin/$name \
222                                        $name $J_INSTALL_DIR/jre/bin/$name $LATEST --slave /usr/share/man/man1/$name.1.gz $name.1.gz \
223                                        $J_INSTALL_DIR/man/man1/$name.1.gz
224                                [ ! $name = "jmc" ] && [ ! $name = "javaws" ] && [ ! $name = "jvisualvm" ] && echo \
225                                        "jre $name $J_INSTALL_DIR/jre/bin/$name" >> /usr/lib/jvm/.java-7-oracle.jinfo
226                        fi
227                else
228                        # No man pages available
229                        #[ ! $name = "javaws.real" ] = skip javaws.real
230                                [ ! $name = "javaws.real" ] && update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/jre/bin/$name $LATEST
231                                [ ! $name = "javaws.real" ] && echo "jre $name $J_INSTALL_DIR/jre/bin/$name" >> /usr/lib/jvm/.java-7-oracle.jinfo
232                fi
233        fi
234done
235
236# Link JRE not in jre/bin
237[ -f $J_INSTALL_DIR/jre/lib/jexec ] && \
238        update-alternatives --install /usr/bin/jexec jexec $J_INSTALL_DIR/jre/lib/jexec $LATEST \
239                --slave /usr/share/binfmts/jar jexec-binfmt $J_INSTALL_DIR/jre/lib/jar.binfmt && \
240                echo "jre jexec $J_INSTALL_DIR/jre/lib/jexec" >> /usr/lib/jvm/.java-7-oracle.jinfo
241
242# This will issue ignorable warnings for alternatives that are not part of a group
243# Link JDK files with/without man pages
244if [ -d "$J_INSTALL_DIR/man/man1" ]; then
245        for f in $J_INSTALL_DIR/man/man1/*; do
246                name=`basename $f .1.gz`
247                # Some files, like jvisualvm might not be links.
248                # Further assume this for corresponding man page
249                if [ ! -f "/usr/bin/$name" -o -L "/usr/bin/$name" ]; then
250                        if [ ! -f "$J_INSTALL_DIR/man/man1/$name.1.gz" ]; then
251                                # Handle any legacy uncompressed pages
252                                name=`basename $f .1`
253                        fi
254                        if [ ! -e $J_INSTALL_DIR/jre/bin/$name ]; then
255                                # Don't link already linked JRE files
256                                if [ ! $arch = "arm" ]; then
257                                        update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/bin/$name $LATEST \
258                                                --slave /usr/share/man/man1/$name.1.gz $name.1.gz $J_INSTALL_DIR/man/man1/$name.1.gz
259                                        echo "jdk $name $J_INSTALL_DIR/bin/$name" >> /usr/lib/jvm/.java-7-oracle.jinfo
260                                else
261                                        # There's no jmc, javaws or jvisualvm on arm
262                                        [ ! $name = "jmc" ] && [ ! $name = "javaws" ] && [ ! $name = "jvisualvm" ] && update-alternatives --install \
263                                                /usr/bin/$name $name $J_INSTALL_DIR/bin/$name $LATEST --slave /usr/share/man/man1/$name.1.gz \
264                                                $name.1.gz $J_INSTALL_DIR/man/man1/$name.1.gz
265                                        [ ! $name = "jmc" ] && [ ! $name = "javaws" ] && [ ! $name = "jvisualvm" ] && \
266                                                echo "jdk $name $J_INSTALL_DIR/bin/$name" >> /usr/lib/jvm/.java-7-oracle.jinfo
267                                fi
268                        fi
269                fi
270        done
271else  #no man pages available
272        for f in $J_INSTALL_DIR/bin/*; do
273                name=`basename $f`;
274                if [ ! -f "/usr/bin/$name" -o -L "/usr/bin/$name" ]; then
275                        # Some files, like jvisualvm might not be links
276                        if [ ! -e $J_INSTALL_DIR/jre/bin/$name ]; then
277                                # Don't link already linked JRE files
278                                        update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/bin/$name $LATEST
279                                        echo "jdk $name $J_INSTALL_DIR/bin/$name" >> /usr/lib/jvm/.java-7-oracle.jinfo
280                        fi
281                fi
282        done
283fi
284
285# Hide javaws and jvisualvm desktop files on arm since these files don't exist on this architecture
286if [ $arch = "arm" ]; then
287echo "NoDisplay=true" >> /usr/share/applications/JB-javaws.desktop
288echo "NoDisplay=true" >> /usr/share/applications/JB-jvisualvm.desktop
289fi
290
291# Use cacerts form ca-certificates-java if it's installed:
292if [ -e /etc/ssl/certs/java/cacerts ]; then
293  cd /usr/lib/jvm/java-7-oracle/jre/lib/security
294  mv cacerts cacerts.original
295  ln -s /etc/ssl/certs/java/cacerts .
296fi
297
298# Register binfmt; ignore errors, the alternative may already be registered by another JRE.
299which update-binfmts >/dev/null && [ -r /usr/share/binfmts/jar ] && \
300        update-binfmts --package oracle-java7 --import jar || true
301echo "Oracle JDK 7 installed"
302
303# Install Firefox (and compatible) plugin. $arch will be empty for unknown platform
304# No plugin for arm architecture yet
305[ -f $J_INSTALL_DIR/jre/lib/$arch/libnpjp2.so ] && \
306        update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so $J_INSTALL_DIR/jre/lib/$arch/libnpjp2.so $LATEST && \
307        echo "plugin mozilla-javaplugin.so $J_INSTALL_DIR/jre/lib/$arch/libnpjp2.so" >> /usr/lib/jvm/.java-7-oracle.jinfo && \
308echo "Oracle JRE 7 browser plugin installed"
309
310#DEBHELPER#
311
312exit 0
313
314# vim: ts=2 sw=2
Note: See TracBrowser for help on using the repository browser.