source: oracle-java8-installer/trunk/fuentes/debian/oracle-java8-installer.postinst @ 566

Last change on this file since 566 was 566, checked in by jrpelegrina, 3 years ago

First release to xenial

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