Java

This section is designed for your 'porteus build scripts' which create Porteus modules for your favorite applications. Scripts should work like the well-known 'SlackBuilds' with minimum user interaction.
Post Reply
User avatar
Hamza
Warlord
Warlord
Posts: 1847
Joined: 28 Dec 2010, 07:41
Distribution: Porteus
Location: France

Java

Post#1 by Hamza » 09 May 2013, 16:47

Here is a slackbuild improved to downloads latest Java and make a xzm module.

Code: Select all

#!/bin/bash

# Copyright 2008, 2009, 2010, 2011, 2012  Patrick J. Volkerding, Sebeka, MN, USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#  Improvement by Hamza for Porteus:
#   - Downloads the last archive available from Oracle servers


rm -Rf /tmp/java.pbuild
mkdir -p /tmp/java.pbuild/{src,data,build}
if [[ $(uname -m) == "x86_64" ]];then archj="x64"; else archj="i586"; fi


wget -O "/tmp/java.pbuild/data/index.html" "http://www.oracle.com/technetwork/java/javase/downloads/index.html"
dlpage=$(grep -o '/technetwork/java/javase/downloads/jdk[0-9]-[a-zA-Z0-9-]*.html' /tmp/java.pbuild/data/index.html|uniq)
wget -O "/tmp/java.pbuild/data/dl.html" "http://www.oracle.com$dlpage"
version=$(grep "downloads\['jdk-[0-9]u[0-9]*-oth-JPR'\]\['files'\]\['jdk-[0-9a-zA-Z]*-linux-[i586|x64]*" /tmp/java.pbuild/data/dl.html | grep 'tar.gz' | grep $archj)
dl_link=$(echo $version|cut -d: -f5)
dl_link=$(echo $dl_link | cut -d'"' -f1)
wget --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" --no-check-certificate -O "/tmp/java.pbuild/src/$(basename $dl_link)" "http:$dl_link"

CWD=$(pwd)
TMP=${TMP:-/tmp}
PKG=$TMP/package-java
SOURCETGZ="/tmp/java.pbuild/src/$(basename $dl_link)"
rm -rf $PKG
mkdir -p $TMP $PKG


PKGNAM=$(basename $SOURCETGZ | cut -f 1 -d -)
VERSION=$(basename $SOURCETGZ | cut -f 2 -d -)
DVER=$(tar tf $SOURCETGZ | head -n 1 | cut -f 2 -d $(echo $PKGNAM | cut -b 3) | cut -f 1 -d /)
JAVA_ARCH=$(basename $SOURCETGZ | cut -f 4 -d - | cut -f 1 -d .)
if [ "$JAVA_ARCH" = "x64" ]; then
  LIB_ARCH=amd64
  ARCH=x86_64
  LIBDIRSUFFIX="64"
else
  LIB_ARCH=i386
  ARCH=i586
  LIBDIRSUFFIX=""
fi
BUILD=${BUILD:-1}

cd $PKG
mkdir -p usr/lib${LIBDIRSUFFIX}
cd usr/lib${LIBDIRSUFFIX}
tar xf $SOURCETGZ || exit 1
mkdir -p $PKG/etc/profile.d
for file in $(ls $CWD/profile.d/${PKGNAM}*) ; do
  cat $file | sed -e "s#lib/java#lib${LIBDIRSUFFIX}/java#" \
    > $PKG/etc/profile.d/$(basename $file)
done
chown -R root.root $PKG
find $PKG \
  \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \
  -exec chmod 755 {} \; -o \
  \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \
  -exec chmod 644 {} \;
chmod 755 $PKG/etc/profile.d/*
( cd $PKG/usr/lib${LIBDIRSUFFIX}
  mv ${PKGNAM}${DVER} java || exit 1
  ln -sf java ${PKGNAM}${DVER}
) || exit 1
mkdir -p $PKG/usr/lib${LIBDIRSUFFIX}/mozilla/plugins
( cd $PKG/usr/lib${LIBDIRSUFFIX}/mozilla/plugins
  if [ "$PKGNAM" = "jdk" ]; then
    ln -sf /usr/lib${LIBDIRSUFFIX}/java/jre/lib/${LIB_ARCH}/libnpjp2.so libnpjp2.so
  else
    ln -sf /usr/lib${LIBDIRSUFFIX}/java/lib/${LIB_ARCH}/libnpjp2.so libnpjp2.so
  fi
)
( cd $PKG/usr/lib${LIBDIRSUFFIX}
  if [ "$PKGNAM" = "jdk" ]; then
    ln -sf ./java/jre/lib/${LIB_ARCH}/server/libjvm.so .
  else
    ln -sf ./java/lib/${LIB_ARCH}/server/libjvm.so .
  fi
)
mkdir -p $PKG/install
cat $CWD/slack-desc.${PKGNAM} > $PKG/install/slack-desc
cat << EOF > $PKG/install/doinst.sh
# Clean up a potential upgrade mess caused by changing the
# installation directory to /usr/lib${LIBDIRSUFFIX}/java/:
if [ -L usr/lib${LIBDIRSUFFIX}/java ]; then
  rm -rf usr/lib${LIBDIRSUFFIX}/java
  mkdir -p usr/lib${LIBDIRSUFFIX}/java/man
EOF
if [ "$PKGNAM" = "jdk" ]; then
cat << EOF >> $PKG/install/doinst.sh
  mkdir -p usr/lib${LIBDIRSUFFIX}/java/jre/lib/${LIB_ARCH}/server
  mkdir -p usr/lib${LIBDIRSUFFIX}/java/jre/lib/${LIB_ARCH}/client
  mkdir -p usr/lib${LIBDIRSUFFIX}/java/jre/javaws
  mkdir -p usr/lib${LIBDIRSUFFIX}/java/jre/bin
EOF
else
cat << EOF >> $PKG/install/doinst.sh
  mkdir -p usr/lib${LIBDIRSUFFIX}/java/lib/${LIB_ARCH}/server
  mkdir -p usr/lib/java/lib${LIBDIRSUFFIX}/${LIB_ARCH}/client
  mkdir -p usr/lib${LIBDIRSUFFIX}/java/javaws
EOF
fi
cat << EOF >> $PKG/install/doinst.sh
  mkdir -p usr/lib${LIBDIRSUFFIX}/java/bin
  mkdir -p usr/lib${LIBDIRSUFFIX}/mozilla/plugins
fi
if [ -L ControlPanel ]; then
  rm -f ControlPanel
fi
if [ -L ja ]; then
  rm -f ja
fi
if [ -L javaws ]; then
  rm -f javaws
fi
if [ -L libjsig.so ]; then
  rm -f libjsig.so
fi
# End cleanup.

EOF

# Install the desktop/mime files:
mkdir -p $PKG/usr/share/{applications,icons,mime}
if [ "$PKGNAM" = "jdk" ]; then
  cp -a $PKG/usr/lib${LIBDIRSUFFIX}/java/jre/lib/desktop/applications/* \
    $PKG/usr/share/applications/
  cp -a $PKG/usr/lib${LIBDIRSUFFIX}/java/jre/lib/desktop/icons/hicolor \
    $PKG/usr/share/icons/
  cp -a $PKG/usr/lib${LIBDIRSUFFIX}/java/jre/lib/desktop/mime/packages \
    $PKG/usr/share/mime/
else
  cp -a $PKG/usr/lib${LIBDIRSUFFIX}/java/lib/desktop/applications/* \
    $PKG/usr/share/applications/
  cp -a $PKG/usr/lib${LIBDIRSUFFIX}/java/lib/desktop/icons/hicolor \
    $PKG/usr/share/icons/
  cp -a $PKG/usr/lib${LIBDIRSUFFIX}/java/lib/desktop/mime/packages \
    $PKG/usr/share/mime/
fi

# Java may not expect compressed manpages, so don't compress them.

cd $PKG
rm -f $TMP/${PKGNAM}-$(echo $VERSION | tr - _)-$ARCH-$BUILD.txz
/sbin/makepkg -l y -c n $TMP/${PKGNAM}-$(echo $VERSION | tr - _)-$ARCH-$BUILD.txz

# Converting to xzm
if [ -f $TMP/${PKGNAM}-$(echo $VERSION | tr - _)-$ARCH-$BUILD.txz ]; then 
   txz2xzm $TMP/${PKGNAM}-$(echo $VERSION | tr - _)-$ARCH-$BUILD.txz $CWD/${PKGNAM}-$(echo $VERSION | tr - _)-$ARCH-$BUILD.xzm
fi

# Clean the tmp
rm -Rf /tmp/java.pbuild $TMP/${PKGNAM}-$(echo $VERSION|tr - _)-$ARCH-$BUILD.txz $PKG
Root permissions required. The output module will be placed in the working directory.

Enjoy!
NjVFQzY2Rg==

Post Reply