This script is discontinued. Use @rerwin's
This post contains a script that hopefully will make your life as a java user easier. It is meant to work out of the box. But as our mileage varies a short tutorial on how to get started follows:
* Copy the code bellow to your favorite editor and save the file as sfs-java.sh in folder /root/my-applications/bin. The name is important as it is used to check if the script is running as a standalone application or sourced by another application.
* Make the script executable by either 1: select it with Ctrl+<left click> in ROX. Then <right click> and select permissions. Then select a+x and OK. or 2: Open a terminal and write chmod +x /root/my-applications/bin/sfs-java.sh
* Now you can run the script from either ROX by <left click> on it. Or from the terminal by issuing the command sfs-java.sh
* When the script finishes the new sfs can be found in /tmp/java-sfs/. The name should be something like jre1.8.0_40.sfs.
* Now you can load the file by <left click> it in ROX. Since the file is located in /tmp you will get some a question whether you would like to move it before you load it. I have experienced conflicts when loading sfs files from /tmp so I recommend you accept to move it.
* When the sfs is loaded you should get a dialog offering to run the java control applet. If it is your first attempt I suggest running it as it will confirm that java is accessible and installed correctly by showing the dialog.
* To confirm that it works with your browser try the link http://java.com/en/download/installed8.jsp?detect=jre
* I'm not into java applications but jedit worked out of the box after loading the sfs. (I downloaded the java based installer )
* Or check out one of the other java applications know to have worked with puppylinux in this thread.
I you like this sfs making script you might like my sfs-seamonkey,sh or my sfs-firefox.sh script.
Code: Select all
#!/usr/bin/env bash
# CREATED_BY: uten: http://murga-linux.com/puppy/profile.php?mode=viewprofile&u=9467
#
# SCRIPT_NAME: sfs-java.sh
#
# PURPOSE: Download latest java files and reate a java sfs file to be used
# with puppylinux
#
# HOMEPAGE: http://murga-linux.com/puppy/viewtopic.php?p=835995
#
# TODO: * Add shunit2 unit test of all functions
# * Add commandline configuration
# * Add help description
# * Cleanup variable names and usage
# * Cleanup function need some thought and work
# * Pristine function need some thought and work
# * Download function should have a local repository option
#
#
# CHANGELOG: Format >> Version: User: Description:
#
# 0.1 Uten Initial release
# 0.1.1 Uten Changed some sed scripts to reflect changes in download pages.
# 0.1.2 Uten Moved linking to /etc/init.d/java.sfs.sh [start] [stop] script
# 0.1.3 Uten Added desktop files. See Menu->Setup->Java control applet
# 0.2.0 Uten Released new version
# 0.2.1 Uten Added java_add_mime_support
# 0.2.2 Uten Added java_include_self
# 0.2.3 Uten Added more error handeling
# 0.2.4 Uten Changed shebang to use env
#
{ # Initial Configuration
THIS_FILE_NAME="sfs-java.sh" #NOTICE: Must be the script file name, used to do test.
THIS_BASENAME=$(basename $0)
TERMINATE_ON_ERROR='True' # If set then err function will terminate script on error
JAVA_SCRIPT_VERSION='0.2.3'
CUR_DIR=$(pwd)
}
function java_set_defaults(){ # Set default values to global variables
#format: variable=${variable-defaultvalue}
WORK_FOLDER=${WORK_FOLDER:-"/tmp"}
TARGET_PATH=${TARGET_PATH:-$WORK_FOLDER/java-sfs}
JAVA_VERSION=${JAVA_VERSION:-7u25} #jre-7u21-linux-i586
JAVA_PATH_VERSION_NAME=${JAVA_PATH_VERSION_NAME:-$(echo $JAVA_VERSION|sed 's/\([0-9]\+\)u\([0-9]\+\)/jre1\.\1\.0_\2/')}
JAVA_BUNDLE_ID=${JAVA_BUNDLE_ID:-78695} #78695=7u25, 76851=7u21, 75250
# TODO: Figure out JAVA_PATH from the unpacked JAVA_VERSION file. Should be
# something like ls $TARGET_PATH/opt/jre*
JAVA_PATH=/opt/jre-$JAVA_VERSION
JAVA_BASE_PATH=${JAVA_BASE_PATH:-"/opt"}
JAVA_PATH=${JAVA_PATH:-$JAVA_BASE_PATH/$JAVA_PATH_VERSION_NAME} #/opt/jre1.7.0_21
#
# JAVA_URL is the url ju get from the download link at www.java.com
# I think number in BundleId=73132 is the only thing changing
JAVA_URL=${JAVA_URL:-"http://javadl.sun.com/webapps/download/AutoDL?BundleId="}
JAVA_WGET_TEMP_FILE=${JAVA_WGET_TEMP_FILE:-/tmp/sfs-java.sh.tmp}
}
function java_dump_variables() { #
echo "WORK_FOLDER:=" $WORK_FOLDER
echo "TARGET_PATH:=" $TARGET_PATH
echo "JAVA_VERSION:=" $JAVA_VERSION
echo "JAVA_PATH_VERSION_NAME:=" $JAVA_PATH_VERSION_NAME
echo "JAVA_BUNDLE_ID:=" $JAVA_BUNDLE_ID
echo "JAVA_BASE_PATH:=" $JAVA_BASE_PATH
echo "JAVA_PATH:=" $JAVA_PATH
echo "JAVA_URL:=" $JAVA_URL
echo "JAVA_WGET_TEMP_FILE:=" $JAVA_WGET_TEMP_FILE
}
function err() { # $? [msg]
# If TERMINATE_ON_ERROR has a value script will terminate
local err=${1:-1}
local COLOR_LIGHT_RED='\e[91m'
local COLOR_BOLD='\e[1m'
local COLOR_RESET='\e[0m'
if [ $# -gt 0 ] && [ $1 -gt 0 ]; then
local msg=${2:-'no err msg'}
local funcname=${FUNCNAME[1]}
local line=${BASH_LINENO[0]}
local script=${BASH_SOURCE[1]}
echo -e "${COLOR_LIGHT_RED}${COLOR_BOLD}ERR ${COLOR_RESET}($line) err:=$err, $msg :: [$funcname] [$script]"
if [ -n $TERMINATE_ON_ERROR ]; then
echo "----------------------------------------------------------------"
java_dump_variables
echo "----------------------------------------------------------------"
echo "terminating due to error $err"
exit $1
fi
fi
return $1
}
function java_get_version_info () { # Get info about the latest java.com release
local ret=0
echo "#TODO: NOTICE: java_get_version_info NOT COMPLETED!"
# Get information
JAVA_VERSION="~~~"
JAVA_BUNDLE_ID="~~~"
wget -O $JAVA_WGET_TEMP_FILE http://www.java.com/en/download/manual.jsp
err $? "wget failed to get manual download information"
if [ -f $JAVA_WGET_TEMP_FILE ]; then
JAVA_BUNDLE_ID=$( grep 'Linux".*" onclick' $JAVA_WGET_TEMP_FILE| sed -n 's/.*=\([0-9]\+\)\".*/\1/p' |sed 1q )
err $? "Failed to parse bundle id"
echo "JAVA_BUNDLE_ID:=" $JAVA_BUNDLE_ID
JAVA_VERSION=$( sed -n 's/.*Version \([0-9]\+\) Update \([0-9]\+\).*/\1u\2/p' "$JAVA_WGET_TEMP_FILE" )
err $? "Failed to parse version info"
echo "JAVA_VERSION:=" $JAVA_VERSION
if [ $ret -eq 0 ]; then
echo "TODO: DELETING: $JAVA_WGET_TEMP_FILE"
#rm -f $JAVA_WGET_TEMP_FILE
fi
else
err 1 "Could not locate $JAVA_WGET_TMP_FILE"
fi
#Copy from java_set_defaults
JAVA_PATH=/opt/jre-$JAVA_VERSION
JAVA_BASE_PATH=${JAVA_BASE_PATH:-"/opt"}
JAVA_PATH=${JAVA_PATH:-$JAVA_BASE_PATH/$JAVA_PATH_VERSION_NAME} #/opt/jre1.7.0_21
#
# JAVA_URL is the url ju get from the download link at www.java.com
# I think number in BundleId=73132 is the only thing changing
JAVA_URL=${JAVA_URL:-"http://javadl.sun.com/webapps/download/AutoDL?BundleId="}
JAVA_WGET_TEMP_FILE=${JAVA_WGET_TEMP_FILE:-/tmp/sfs-java.sh.tmp}
JAVA_PATH_VERSION_NAME=$(echo $JAVA_VERSION|sed 's/\([0-9]\+\)u\([0-9]\+\)/jre1\.\1\.0_\2/')
err $? "Failed to parse JAVA_PATH_VERSION_NAME"
}
function java_add_mime_support() { # Add jar mime support to rox
local ret=0
local d="$TARGET_PATH/root/.config/rox.sourceforge.net/MIME-types/"
local f="$d/application_x-java-archive"
if [ ! -d $d ]; then
mkdir -p "$d"
fi
if [ ! -e $f ]; then
cat << 'EOF' > $f
#! /bin/sh
exec java -jar "$@"
EOF
fi
return $ret
}
function java_include_self() { # Include this script in sfs
local ret=0
local f=$0
local d="$TARGET_PATH/root/my-applications/bin"
if [ ! -d $d ]; then
mkdir -p "$d"
fi
cp -f "$f" "$d"
err $? "Could not copy $f to $d"
return $ret
}
function java_write_init_d_script() { # Create a init.d script to get linking right
mkdir -p $TARGET_PATH/etc/init.d/
err $? "Could not mkdir $TARGET_PATH/etc/init.d/"
cat << 'EOF' > $TARGET_PATH/etc/init.d/java.sfs.sh
#!/usr/bin/env bash
JAVA_PATH=SED_WRITE_JAVA_PATH
LOGFILE=/tmp/java.sfs.sh.log
function remove_plugin_links() {
rm /usr/lib/firefox/plugins/libnpjp2.so
rm /usr/lib/firefox/plugins/libjavaplugin_nscp_gcc29.so
rm /usr/lib/firefox/plugins/libjavaplugin_nscp.so
rm /usr/lib/firefox/plugins/libjavaplugin_oji.so
rm /usr/lib/firefox/plugins/libjavaplugin_jni.so
rm /usr/lib/mozilla/plugins/libnpjp2.so
rm /usr/lib/mozilla/plugins/libjavaplugin_nscp_gcc29.so
rm /usr/lib/mozilla/plugins/libjavaplugin_nscp.so
rm /usr/lib/mozilla/plugins/libjavaplugin_oji.so
rm /usr/lib/mozilla/plugins/libjavaplugin_jni.so
}
function fix_plugin_links() {
#
# Make nescessary plugin folders
mkdir -p /usr/lib/firefox/plugins/
mkdir -p /usr/lib/mozilla/plugins/
ln -s -f -T $JAVA_PATH/lib/i386/libnpjp2.so /usr/lib/firefox/plugins/libnpjp2.so
ln -s -f -T $JAVA_PATH/lib/i386/libjavaplugin_nscp_gcc29.so /usr/lib/firefox/plugins/libjavaplugin_nscp_gcc29.so
ln -s -f -T $JAVA_PATH/lib/i386/libjavaplugin_nscp.so /usr/lib/firefox/plugins/libjavaplugin_nscp.so
ln -s -f -T $JAVA_PATH/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/firefox/plugins/libjavaplugin_oji.so
#ln -s -f -T $JAVA_PATH/lib/i386/libjavaplugin_oji.so /usr/lib/firefox/plugins/libjavaplugin_oji.so
ln -s -f -T $JAVA_PATH/lib/i386/libjavaplugin_jni.so /usr/lib/firefox/plugins/libjavaplugin_jni.so
ln -s -f -T $JAVA_PATH/lib/i386/libnpjp2.so /usr/lib/mozilla/plugins/libnpjp2.so
ln -s -f -T $JAVA_PATH/lib/i386/libjavaplugin_nscp_gcc29.so /usr/lib/mozilla/plugins/libjavaplugin_nscp_gcc29.so
ln -s -f -T $JAVA_PATH/lib/i386/libjavaplugin_nscp.so /usr/lib/mozilla/plugins/libjavaplugin_nscp.so
ln -s -f -T $JAVA_PATH/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/mozilla/plugins/libjavaplugin_oji.so
#ln -s -f -T $JAVA_PATH/lib/i386/libjavaplugin_oji.so /usr/lib/mozilla/plugins/libjavaplugin_oji.so
ln -s -f -T $JAVA_PATH/lib/i386/libjavaplugin_jni.so /usr/lib/mozilla/plugins/libjavaplugin_jni.so
}
function fix_java_links() {
local ret=0
mkdir -p $TARGET_PATH/usr/bin
#
# Make links to java programs
ln -s -f $JAVA_PATH/bin/keytool /usr/bin/keytool
ln -s -f $JAVA_PATH/bin/pack200 /usr/bin/pack200
ln -s -f $JAVA_PATH/bin/orbd /usr/bin/orbd
ln -s -f $JAVA_PATH/bin/servertool /usr/bin/servertool
ln -s -f $JAVA_PATH/bin/policytool /usr/bin/policytool
ln -s -f $JAVA_PATH/bin/java_vm /usr/bin/java_vm
ln -s -f $JAVA_PATH/bin/javaws /usr/bin/javaws
ln -s -f $JAVA_PATH/bin/rmid /usr/bin/rmid
ln -s -f $JAVA_PATH/bin/rmiregistry /usr/bin/rmiregistry
ln -s -f $JAVA_PATH/bin/java /usr/bin/java
ln -s -f $JAVA_PATH/bin/ControlPanel /usr/bin/ControlPanel
ln -s -f $JAVA_PATH/bin/tnameserv /usr/bin/tnameserv
ln -s -f $JAVA_PATH/bin/unpack200 /usr/bin/unpack200
ln -s -f $JAVA_PATH/bin/jcontrol /usr/bin/jcontrol
return $ret
}
function remove_java_links() { #
local ret=0
rm /usr/bin/keytool
rm /usr/bin/pack200
rm /usr/bin/orbd
rm /usr/bin/servertool
rm /usr/bin/policytool
rm /usr/bin/java_vm
rm /usr/bin/javaws
rm /usr/bin/rmid
rm /usr/bin/rmiregistry
rm /usr/bin/java
rm /usr/bin/ControlPanel
rm /usr/bin/tnameserv
rm /usr/bin/unpack200
rm /usr/bin/jcontrol
return $ret
}
function start() { #
echo "start: $0" >> $LOGFILE
local ret=0
fix_java_links || ret+=$?
fix_plugin_links || ret+=$?
return $ret
}
function stop() { #
echo "stop: $0" >> $LOGFILE
local ret=0
remove_java_links || ret+=$?
remove_plugin_links || ret+=$?
return $ret
}
function script_main() { #
local ret=0
case "$1" in
start)
start || ret=$?
;;
stop)
stop || ret=$?
;;
esac
return $ret
}
script_main $@
exit $?
EOF
sed -i "s@SED_WRITE_JAVA_PATH@/opt/$JAVA_PATH_VERSION_NAME@" $TARGET_PATH/etc/init.d/java.sfs.sh
chmod +x $TARGET_PATH/etc/init.d/java.sfs.sh
}
function java_unpack_java(){ # Unpack the downloaded binaries
# TODO_CODE: Verify that wget did not fail
#
# Unpack java
# TODO_CODE: Verify directories
local ret=0
if [ ! -e $TARGET_PATH/opt ]; then
echo "NOTE: Creating: $TARGET_PATH/opt"
mkdir -p $TARGET_PATH/opt
fi
if [ ! -e $TARGET_PATH/opt/$JAVA_VERSION ]; then
#tar --checkpoint=1500 --directory=$TARGET_PATH/opt/ -axf ./jre-$JAVA_VERSION.tar.gz
echo "NOTE: $(pwd)/jre-$JAVA_VERSION.tar.gz unpacking to $TARGET_PATH/opt/"
tar --checkpoint=1500 --directory=$TARGET_PATH/opt/ -axf ./jre-$JAVA_VERSION.tar.gz
fi
sync
return $ret
}
function java_download_java(){ # Download the java version/bundleid
#
# Download java
local ret=0
if [ ! -z "$JAVA_VERSION" ]; then
if [ ! -z "$JAVA_BUNDLE_ID" ]; then
echo "NOTE: DOWNLOAD: $JAVA_URL$JAVA_BUNDLE_ID"
wget -nc $JAVA_URL$JAVA_BUNDLE_ID -O ./jre-$JAVA_VERSION.tar.gz
else
err 1 "JAVA_BUNDLE_ID unresolved. Terminating."
ret=$?
fi
else
err 1 "JAVA_VERSION:=$JAVA_VERSION is unresolved. Terminating"
ret=$?
fi
return $ret
}
function java_help(){ # Write out help information
echo "TODO: java_help not implemeneted"
}
function java_clean(){ #
local ret=0
if [ "$1" == "--clean" -o "$1" == "--pristine" ]; then
rm -rf $WORK_FOLDER/$TARGET_PATH/opt/$JAVA_PATH_VERSION_NAME
# TODO_CODE: clean up links? Can't just remove directories as
# that will remove other apps stuff.
fi
return $ret
}
function java_pristine(){ #
local ret=0
if [ "$1" == "--pristine" ]; then
rm -f ./$JAVA_VERSION.tar.gz
fi
return $ret
}
function java_make_sfs() { # Make the new sfs file
local ret=0
#
# Create the sfs file
#TODO: Usage of WORK_FOLDER, TARGET_PATH and JAVA_PATH_NAME is
# incosistent with other scripts.
# if [ $WORK_FOLDER=='' || $TARGET_PATH=='' ]; then
# echo "WARNING: could not resolve WORK_FOLDER or TARGET_PATH"
# exit 0
# else
cd $TARGET_PATH/
echo "mksquashfs:= $TARGET_PATH $JAVA_PATH_VERSION_NAME.sfs -noappend"
mksquashfs $TARGET_PATH $JAVA_PATH_VERSION_NAME.sfs -noappend
err $? "mksquashfs failed"
ret=$?
# fi
return $ret
}
function java_link_desktop() { # Copy and modify sun's desktop integration file
local ret=0
mkdir -p $TARGET_PATH/usr/share/applications
mkdir -p $TARGET_PATH/usr/share/icons
mv $TARGET_PATH/opt/$JAVA_PATH_VERSION_NAME/plugin/desktop/*.desktop $TARGET_PATH/usr/share/applications/
mv $TARGET_PATH/opt/$JAVA_PATH_VERSION_NAME/plugin/desktop/*.png $TARGET_PATH/usr/share/icons
err $? "mv failed to move dektop files?"
sed -i 's/Categories.*/Categories=X-SetupEntry/' $TARGET_PATH/usr/share/applications/sun_java.desktop
sed -i 's@Icon.*@Icon=/usr/share/icons/sun_java.png@' $TARGET_PATH/usr/share/applications/sun_java.desktop
sed -i 's@Name=.*@Name=Java control applet@' $TARGET_PATH/usr/share/applications/sun_java.desktop
return $?
}
function java_main() { # Main function in script
java_set_defaults || err 99 "java_set_defaults failed"
java_get_version_info || err 99 "java_get_version_info failed"
java_dump_variables || err 99 "java_dump_variables failed"
java_clean || err 99 "java_clean failed"
#java_pristine || err 99 "java_pristine failed"
java_download_java || err 99 "java_download_java failed"
java_unpack_java || err 99 "java_unpack_java failed"
java_write_init_d_script || err 99 "java_write_init_d_script failed"
java_link_desktop || err 99 "java_link_desktop failed"
java_include_self || err 99 "java_include_self failed"
java_add_mime_support || err 99 "java_add_mime_support failed"
}
#
# TODO_CODE: Make java.desktop and icon references.
if [ "$THIS_FILE_NAME" == $THIS_BASENAME ]; then
#TODO: Shuld use push and pop (folder)?
CUR_FOLDER=$(pwd)
java_main || err 99 "java_main failed"
java_make_sfs || err 99 "java_make_sfs failed"
cd $CUR_FOLDER
else
java_main
fi
EDIT: New version 0.2.4
EDIT: Added short tutorial at the top of this post. Moved edit explanation down to the bottom.[/b]
EDIT: Added link to thread with java applications people use ( thanks to @gcmartin for the link ).