Last active
January 26, 2020 17:53
-
-
Save rfuehrer/324b0ca212dafabd26d5fc412f0b3ce9 to your computer and use it in GitHub Desktop.
A downloader to get a portable OpenJDK (customized "tinyMediaManager" script included)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
OVERWRITE_EXISTING=0 | |
CLEANUP_DESTINATION=1 | |
# relatibe path (from script location) to java storage path | |
DIR_DESTINATION="./java_portable" | |
SITE_OPENJDK="https://jdk.java.net/archive/" | |
# ----------------------- DO NOT EDIT BELOW THIS LINE ----------------------- | |
# set internal vars | |
DIR_TEMP=$(mktemp -d) | |
ABSOLUTE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
DIR_DESTINATION=$ABSOLUTE_PATH/$DIR_DESTINATION | |
echo "OpenJDK destination path : $DIR_DESTINATION" | |
if [[ "$OSTYPE" == "linux-gnu" ]]; then | |
PLATFORM="linux" | |
elif [[ "$OSTYPE" == "darwin"* ]]; then | |
PLATFORM="osx" | |
elif [[ "$OSTYPE" == "cygwin" ]]; then | |
PLATFORM="windows" | |
echo "Platform not supported at the moment. Abort." | |
exit 1 | |
elif [[ "$OSTYPE" == "msys" ]]; then | |
PLATFORM="windows" | |
echo "Platform not supported at the moment. Abort." | |
exit 1 | |
elif [[ "$OSTYPE" == "win32" ]]; then | |
Echo "Platform (32-bit) not supported. Abort." | |
exit 1 | |
elif [[ "$OSTYPE" == "freebsd"* ]]; then | |
PLATFORM="linux" | |
else | |
echo "Platform can not be detected. Abort." | |
exit 1 | |
fi | |
# get latest openjdk link | |
# get website content | |
DUMMY1=$(curl -s "$SITE_OPENJDK") | |
# get all links | |
DUMMY2=$(echo "$DUMMY1" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*(\.tar\.gz)") | |
# get first link auf all links of specified platform | |
DOWNLOAD=$(echo "$DUMMY2" | grep "$PLATFORM" | head -n 1) | |
# download openjdk | |
SITE_VERSION=$(echo "$DOWNLOAD" | sed -e 's#.*jdk-\(.*\)_.*#\1#' | sed -e 's#^\(.*\)_.*#\1#') | |
TEMPFILE="$DIR_TEMP/temp.openjdk-$PLATFORM-$SITE_VERSION.tar.gz" | |
# Cleaup obsolete versions | |
if [ $CLEANUP_DESTINATION -eq 1 ]; then | |
echo "Clean up destination dir..." | |
find "$DIR_DESTINATION/" -mindepth 1 -maxdepth 1 -not -name "openjdk-$PLATFORM-$SITE_VERSION" -print0 | xargs -0 rm -rf | |
fi | |
# check if platform/version already exists | |
if [[ -d "$DIR_DESTINATION/openjdk-$PLATFORM-$SITE_VERSION" ]]; then | |
if [ $OVERWRITE_EXISTING -eq 0 ]; then | |
echo "Version seems to exists in destination directory. Abort." | |
exit 1 | |
else | |
echo "Overwritung existing version..." | |
fi | |
fi | |
# downloading openjdk | |
echo "Downloading OpenJDK v.$SITE_VERSION / $PLATFORM. Please wait..." | |
curl -s -o "$TEMPFILE" "$DOWNLOAD" | |
# extract openjdk | |
tar -xf "$TEMPFILE" -C "$DIR_TEMP/" --strip=3 | |
# get downloaded version | |
VERSION=$("$DIR_TEMP/Home/bin/java" --version | head -n 1 | awk '{ print $2 }') | |
# prepare destination directory | |
mkdir -p "$DIR_DESTINATION" | |
FINALDIR="$DIR_DESTINATION/openjdk-$PLATFORM-$SITE_VERSION" | |
echo "OS detected : $PLATFORM" | |
echo "Temporary dir : $DIR_TEMP" | |
#osascript -e "tell application \"System Events\" to display dialog \"DEBUG: $DIR_TEMP\"" | |
echo "OpenJDK download link : $DOWNLOAD" | |
echo "OpenJDK link version : $SITE_VERSION" | |
echo "OpenJDK version : $VERSION" | |
echo "OpenJDK destination path : $DIR_DESTINATION" | |
echo "OpenJDK downloaded version: $FINALDIR" | |
echo "Please press CTRL+C to abort NOW! (waiting 5 seconds)" | |
sleep 5 | |
echo "Remove old files and dirs..." | |
# remove old openjdk (if exists) | |
if [ ! -z "$FINALDIR" ]; then rm -rf "$FINALDIR/"; fi | |
# copy downloaded openjdk to destination | |
cp -Rp "$DIR_TEMP/Home" "$FINALDIR" | |
# copy downloaded tar to destination (as backup; will be deleted at next activated cleanup!) | |
#cp $TEMPFILE $DIR_DESTINATION/ | |
# remove downloaded/extracted temp parts | |
if [ ! -z "$DIR_TEMP" ]; then rm -rf "$DIR_TEMP/"; fi | |
if [ -f "$TEMPFILE" ]; then rm -rf "$TEMPFILE"; fi | |
echo "Done." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
##################################################################################### | |
# This is a "kickstarter" for OSX; we need to do some logic here, because in OSX | |
# there is no way to provide an updater and the app itself inside one app. | |
# There is exactly one "entry point" per .app which is defined in the info.plist. | |
# In our case this is JavaApplicationStub which is a simple shellscript that launches | |
# this shellscript. Here we do differend checks | |
# | |
# a) search the right Java JVM | |
# b) decide whether we need to launch the updater or launch tmm | |
# | |
##################################################################################### | |
# find the path where to execute tmm | |
PRG=$0 | |
while [ -h "$PRG" ]; do | |
ls=`ls -ld "$PRG"` | |
link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null` | |
if expr "$link" : '^/' 2> /dev/null >/dev/null; then | |
PRG="$link" | |
else | |
PRG="`dirname "$PRG"`/$link" | |
fi | |
done | |
progdir=`dirname "$PRG"` | |
# check if tmm has been executed in a read only environment | |
if [ ! -w "$progdir" ]; then | |
osascript -e "tell application \"System Events\" to display dialog \"ERROR launching tinyMediaManager! | |
You need to execute tinyMediaManager from a writeable location (e.g. the Applications folder)\" with title \"tinyMediaManager\" buttons {\" OK \"} default button 1 with icon path to resource \"tmm.icns\" in bundle (path to me)" | |
exit 1 | |
fi | |
# By default Mac OS X LC_ALL is set to "C", which means files with special characters will not be found. | |
export LC_ALL="en_US.UTF-8" | |
# --- rfuehrer: start --- | |
ABSOLUTE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
"$ABSOLUTE_PATH/openjdk_portable_downloader.sh" | |
JAVACMD=$(find "$ABSOLUTE_PATH" -type f -name "java" -perm +0111 -print | head -n 1) | |
# # search for the right JVM - priority is java 8 | |
# if [ -x /usr/libexec/java_home ]; then | |
# JAVA_HOME="`/usr/libexec/java_home -v 1.8 -F`" | |
# export JAVA_HOME | |
# fi | |
# if [ ! -f "$JAVA_HOME/bin/java" -a -x "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java" ]; then | |
# JAVA_HOME="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home" | |
# export JAVA_HOME | |
# fi | |
# JAVACMD="${JAVA_HOME}/bin/java" | |
#if [ ! -f "$JAVACMD" -o ! -x "$JAVACMD" ]; then | |
# # display error message with applescript | |
# osascript -e "tell application \"System Events\" to display dialog \"ERROR launching tinyMediaManager! | |
##You need to have JAVA installed on your Mac! | |
##Visit http://java.com for more information...\" with title \"tinyMediaManager\" buttons {\" OK \"} default button 1 with icon path to resource \"tmm.icns\" in bundle (path to me)" | |
# | |
# # and open java.com | |
# open http://java.com | |
# | |
# # exit with error | |
# exit 1 | |
#fi | |
# --- rfuehrer: end --- | |
# have a look if we need to launch the updater or tmm directly | |
if [ -f tmm.jar ]; then | |
ARGS="-Dsilent=noupdate" | |
else | |
ARGS="-Xdock:name=`tinyMediaManager updater`" | |
ARGS="$ARGS -Xdock:icon=../tmm.icns" | |
fi | |
ARGS="$ARGS -Djava.net.preferIPv4Stack=true -Dappbase=http://www.tinymediamanager.org/" | |
# execute it :) | |
# --- rfuehrer: start --- | |
exec "$JAVACMD" ${ARGS} -jar getdown.jar . | |
# --- rfuehrer: end --- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment