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

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

First release to xenial

  • Property svn:executable set to *
File size: 10.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# Must be modified for each release
27JAVA_VERSION=7u80
28J_DIR=jdk1.7.0_80
29
30
31# Filenames and checksums
32case $(dpkg --print-architecture) in
33'i386'|'i586'|'i686')
34        arch=i386; dld=i586
35        # Must be modified for each release
36        SHA256SUM_TGZ="b6231064ad2c9fbbcb099dba17b1dcf12033e922b9c24e4348b9a01e9ebaa85c"
37        ;;
38'amd64')
39        arch=amd64; dld=x64
40        # Must be modified for each release
41        SHA256SUM_TGZ="54dd1e13edf18c64941a55da9c91210b53dc5cf48f1a8f4538c863049e346335"
42        ;;
43*)
44        echo "Please report to author unsupported platform '`uname -m`'.";
45        echo "Proceeding without web browser plugin support";
46        arch='';
47esac
48FILENAME=jdk-${JAVA_VERSION}-linux-${dld}.tar.gz
49for JAVA_VERSION_OLD in `seq 1 50`; do #must be modified for each release ("1 3" for 7u4; "1 4" for 7u5, etc)
50        FILENAMES_OLD="jdk-7u${JAVA_VERSION_OLD}-linux-${dld}.tar.gz $FILENAMES_OLD"
51done
52
53# Must be modified for each release!!!
54PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/7u76-b13/$FILENAME
55
56### Functions
57fp_exit_with_error() {
58        echo $1
59        echo "Oracle JDK 7 is NOT installed."
60        db_fset oracle-java7-installer/local seen false
61        exit 1
62}
63
64fp_download_and_unpack() {
65        cd /var/cache/oracle-jdk7-installer
66
67        db_get oracle-java7-installer/local
68        if [ -d "$RET" -a -f "$RET"/$FILENAME ]; then
69                echo "Installing from local file $RET/$FILENAME"
70                cp -f -p "$RET"/$FILENAME ${FILENAME}_TEMP
71                mv -f ${FILENAME}_TEMP $FILENAME
72        else # no local file
73                # use apt proxy
74                APT_PROXIES=$(apt-config shell \
75                http_proxy Acquire::http::Proxy \
76                https_proxy Acquire::https::Proxy \
77                ftp_proxy Acquire::ftp::Proxy \
78                dl_direct Acquire::http::Proxy::download.oracle.com \
79                )
80
81                [ -n "$APT_PROXIES" ] && eval export $APT_PROXIES
82
83                if [ "$dl_direct" = "DIRECT" ]; then
84                        unset http_proxy
85                        unset https_proxy
86                        unset ftp_proxy
87                fi
88
89                # setting wget options
90                :> wgetrc
91                echo "noclobber = off" >> wgetrc
92                echo "dir_prefix = ." >> wgetrc
93                echo "dirstruct = off" >> wgetrc
94                echo "verbose = on" >> wgetrc
95                echo "progress = dot:mega" >> wgetrc
96                echo "tries = 2" >> wgetrc
97
98                # downloading jdk7
99                echo "Downloading Oracle Java 7..."
100                WGETRC=wgetrc wget --continue --no-check-certificate -O $FILENAME --header "Cookie: gpw_e24=h" $PARTNER_URL \
101                        || fp_exit_with_error "download failed"
102                echo "Download done."
103        fi # end if local file
104
105        # Removing outdated cached downloads
106        echo "Removing outdated cached downloads..."
107        rm -vf $FILENAMES_OLD
108
109        # Verify SHA256 checksum of (copied or downloaded) tarball
110        rm -rf jdk*/
111        echo "$SHA256SUM_TGZ  $FILENAME" | sha256sum -c > /dev/null 2>&1 \
112                || fp_exit_with_error "sha256sum mismatch $FILENAME"
113
114        # Unpacking and checking the plugin
115        tar xzf $FILENAME || fp_exit_with_error "cannot unpack jdk7"
116}
117
118safe_move() {
119        [ ! -f $OLDDIR/$1 ] || [ -f $NEWDIR/$1 ] || mv $OLDDIR/$1 $NEWDIR/$1 2> /dev/null || true
120        [ ! -f $OLDDIR/$1 ] || [ ! -f $NEWDIR/$1 ] || rm -f $OLDDIR/$1 2> /dev/null || true
121}
122
123### Main
124
125# Create dirs
126mkdir -p /var/cache/oracle-jdk7-installer /usr/lib/jvm /usr/lib/oracle-jdk7-installer-unpackdir
127# Without this, an error is displayed if the folder doesn't exist:
128mkdir -p /usr/lib/mozilla/plugins/
129
130# Lliurex -----------------------------------05/11/2013
131#Comentar descarga y copiar desde directorio
132#fp_download_and_unpack
133ORACLE_DIR=/var/cache/oracle-jdk7-installer
134echo "Installing from local file $ORACLE_DIR/$FILENAME"
135#cp -f -p "$ORACLE_DIR"/$FILENAME ${FILENAME}_TEMP
136#mv -f ${FILENAME}_TEMP $FILENAME
137rm -f ${FILENAME}
138cd $ORACLE_DIR
139tar xzf $FILENAME || fp_exit_with_error "cannot unpack jdk7"
140# FIN Lliurex -------------------------------05/11/2013
141
142
143# Copy JDK to the right dir
144mv $J_DIR java-7-oracle
145rm -rf /usr/lib/jvm/java-7-oracle
146cp -rf java-7-oracle /usr/lib/jvm/
147
148# There's no javaws on arm
149
150# Install javaws-wrapper.sh
151mv $J_INSTALL_DIR/jre/bin/javaws $J_INSTALL_DIR/jre/bin/javaws.real
152install -m 755 javaws-wrapper.sh $J_INSTALL_DIR/jre/bin/javaws
153
154
155# Install jar.binfmt
156install -m 755 jar.binfmt $J_INSTALL_DIR/jre/lib/jar.binfmt
157
158# Clean up
159rm -rf java-7-oracle
160
161# To add when an older version exists:
162# safe_move jdk-7u2-linux-x64.tar.gz #must be modified for each release
163# safe_move jdk-7u2-linux-i586.tar.gz #must be modified for each release
164# Remove previous versions, if they exist
165rmdir $OLDDIR 2> /dev/null || true
166
167db_fset oracle-java7-installer/local seen false
168
169# This step is optional, recommended, and affects code below.
170ls $J_INSTALL_DIR/man/man1/*.1 >/dev/null 2>&1 && \
171  gzip -9 $J_INSTALL_DIR/man/man1/*.1 >/dev/null 2>&1
172
173# Increment highest version by 1.
174# Also assumes all Java helper programs (javaws, jcontrol, etc) at same version as java.
175# These helpers should be slaves, or in the same path as java; thus, a reasonable assumption.
176LATEST=1
177# Lliurex -----------------------------------16/01/2014
178LATEST=$((`LANG=C update-alternatives --display java | grep ^/ | sed -e 's/.* //g' | sort -n | tail -1`+1))
179# FIN Lliurex -------------------------------16/01/2014
180
181# Create .java-7-oracle.jinfo file header:
182[ -e /usr/lib/jvm/.java-7-oracle.jinfo ] && rm -f /usr/lib/jvm/.java-7-oracle.jinfo
183echo "name=java-7-oracle
184alias=java-7-oracle
185priority=$LATEST
186section=non-free
187" > /usr/lib/jvm/.java-7-oracle.jinfo
188
189# Link JRE files
190for f in $J_INSTALL_DIR/jre/bin/*; do
191        name=`basename $f`;
192        if [ ! -f "/usr/bin/$name" -o -L "/usr/bin/$name" ]; then
193                # Some files, like jvisualvm might not be links
194                if [ -f "$J_INSTALL_DIR/man/man1/$name.1.gz" ]; then
195                        if [ ! $arch = "arm" ]; then
196                                update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/jre/bin/$name $LATEST \
197                                        --slave /usr/share/man/man1/$name.1.gz $name.1.gz $J_INSTALL_DIR/man/man1/$name.1.gz
198                                echo "jre $name $J_INSTALL_DIR/jre/bin/$name" >> /usr/lib/jvm/.java-7-oracle.jinfo
199                        else
200                                # There's no jmc, javaws or jvisualvm on arm
201                                [ ! $name = "jmc" ] && [ ! $name = "javaws" ] && [ ! $name = "jvisualvm" ] && update-alternatives --install /usr/bin/$name \
202                                        $name $J_INSTALL_DIR/jre/bin/$name $LATEST --slave /usr/share/man/man1/$name.1.gz $name.1.gz \
203                                        $J_INSTALL_DIR/man/man1/$name.1.gz
204                                [ ! $name = "jmc" ] && [ ! $name = "javaws" ] && [ ! $name = "jvisualvm" ] && echo \
205                                        "jre $name $J_INSTALL_DIR/jre/bin/$name" >> /usr/lib/jvm/.java-7-oracle.jinfo
206                        fi
207                else
208                        # No man pages available
209                        #[ ! $name = "javaws.real" ] = skip javaws.real
210                                [ ! $name = "javaws.real" ] && update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/jre/bin/$name $LATEST
211                                [ ! $name = "javaws.real" ] && echo "jre $name $J_INSTALL_DIR/jre/bin/$name" >> /usr/lib/jvm/.java-7-oracle.jinfo
212                fi
213        fi
214done
215
216# Link JRE not in jre/bin
217[ -f $J_INSTALL_DIR/jre/lib/jexec ] && \
218        update-alternatives --install /usr/bin/jexec jexec $J_INSTALL_DIR/jre/lib/jexec $LATEST \
219                --slave /usr/share/binfmts/jar jexec-binfmt $J_INSTALL_DIR/jre/lib/jar.binfmt && \
220                echo "jre jexec $J_INSTALL_DIR/jre/lib/jexec" >> /usr/lib/jvm/.java-7-oracle.jinfo
221
222# This will issue ignorable warnings for alternatives that are not part of a group
223# Link JDK files with/without man pages
224if [ -d "$J_INSTALL_DIR/man/man1" ]; then
225        for f in $J_INSTALL_DIR/man/man1/*; do
226                name=`basename $f .1.gz`
227                # Some files, like jvisualvm might not be links.
228                # Further assume this for corresponding man page
229                if [ ! -f "/usr/bin/$name" -o -L "/usr/bin/$name" ]; then
230                        if [ ! -f "$J_INSTALL_DIR/man/man1/$name.1.gz" ]; then
231                                # Handle any legacy uncompressed pages
232                                name=`basename $f .1`
233                        fi
234                        if [ ! -e $J_INSTALL_DIR/jre/bin/$name ]; then
235                                # Don't link already linked JRE files
236                                if [ ! $arch = "arm" ]; then
237                                        update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/bin/$name $LATEST \
238                                                --slave /usr/share/man/man1/$name.1.gz $name.1.gz $J_INSTALL_DIR/man/man1/$name.1.gz
239                                        echo "jdk $name $J_INSTALL_DIR/bin/$name" >> /usr/lib/jvm/.java-7-oracle.jinfo
240                                else
241                                        # There's no jmc, javaws or jvisualvm on arm
242                                        [ ! $name = "jmc" ] && [ ! $name = "javaws" ] && [ ! $name = "jvisualvm" ] && update-alternatives --install \
243                                                /usr/bin/$name $name $J_INSTALL_DIR/bin/$name $LATEST --slave /usr/share/man/man1/$name.1.gz \
244                                                $name.1.gz $J_INSTALL_DIR/man/man1/$name.1.gz
245                                        [ ! $name = "jmc" ] && [ ! $name = "javaws" ] && [ ! $name = "jvisualvm" ] && \
246                                                echo "jdk $name $J_INSTALL_DIR/bin/$name" >> /usr/lib/jvm/.java-7-oracle.jinfo
247                                fi
248                        fi
249                fi
250        done
251else  #no man pages available
252        for f in $J_INSTALL_DIR/bin/*; do
253                name=`basename $f`;
254                if [ ! -f "/usr/bin/$name" -o -L "/usr/bin/$name" ]; then
255                        # Some files, like jvisualvm might not be links
256                        if [ ! -e $J_INSTALL_DIR/jre/bin/$name ]; then
257                                # Don't link already linked JRE files
258                                        update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/bin/$name $LATEST
259                                        echo "jdk $name $J_INSTALL_DIR/bin/$name" >> /usr/lib/jvm/.java-7-oracle.jinfo
260                        fi
261                fi
262        done
263fi
264
265# Register binfmt; ignore errors, the alternative may already be registered by another JRE.
266which update-binfmts >/dev/null && [ -r /usr/share/binfmts/jar ] && \
267        update-binfmts --package oracle-java7 --import jar || true
268echo "Oracle JDK 7 installed"
269
270# Install Firefox (and compatible) plugin. $arch will be empty for unknown platform
271# No plugin for arm architecture yet
272# Lliurex ------------------------------- ---16/01/2014
273[ -f $J_INSTALL_DIR/jre/lib/$arch/libnpjp2.so ] && \
274        update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so $J_INSTALL_DIR/jre/lib/$arch/libnpjp2.so 10 && \
275        echo "plugin mozilla-javaplugin.so $J_INSTALL_DIR/jre/lib/$arch/libnpjp2.so" >> /usr/lib/jvm/.java-7-oracle.jinfo && \
276echo "Oracle JRE 7 browser plugin installed"
277
278for numero in `seq 1 50`; do #must be modified for each release ("1 3" for 7u4; "1 4" for 7u5, etc)
279        FILENAME_OLD="/jdk-7u"${numero}"-linux-"${dld}".tar.gz"
280        [ ! -e $FILENAME_OLD ] ||       rm -f $FILENAME_OLD
281done
282
283# FIN Lliurex ------------------------------- ---16/01/2014
284#DEBHELPER#
285
286exit 0
287
288# vim: ts=2 sw=2
Note: See TracBrowser for help on using the repository browser.