Last active
December 15, 2015 05:39
-
-
Save didenko/5210584 to your computer and use it in GitHub Desktop.
A Technic downloader and launcher for OSX systems where Java 6 got upgraded to Java 7. Save the gist as `.command` file, e.g. `technic_osx.command`, make it executable and run it from Finder.
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 | |
# | |
# Copyright 2013 Vlad Didenko | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see http://www.gnu.org/licenses/. | |
# | |
# Vlad Didenko can be reached for comments via the distribution URL | |
# of this program at https://gist.github.com/didenko/5210584 | |
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home | |
SOURCE_URL=http://mirror.technicpack.net/files/technic-launcher-latest.jar | |
function on_exit() { | |
echo "Please, copy the output above for troubleshooting." 1>&2 | |
echo "Press ENTER/RETURN to exit." 1>&2 | |
read junk | |
} | |
trap on_exit ERR EXIT | |
[ "$(uname -s)" == "Darwin" ] || { | |
echo "This script should be only run on Apple OS X systems." 1>&2 | |
exit 1 | |
} | |
CACHE_DIR=~/Library/Caches/com.didenko.technic_osx_shell | |
DOWNLOADED=$(basename ${SOURCE_URL}) | |
EPOC_TIME=$(date +%s) | |
PREFIX=launcher_ | |
KEEP_LIMIT=10 | |
[ -d "${CACHE_DIR}" ] || mkdir -p ${CACHE_DIR} | |
pushd ${CACHE_DIR} >/dev/null 2>&1 | |
LAST_CACHED=$(ls -r1 ${PREFIX}*.jar 2>/dev/null | head -n 1) | |
if curl -s -O ${SOURCE_URL} | |
then | |
if diff -q ${LAST_CACHED} ${DOWNLOADED} >/dev/null 2>&1 | |
then | |
rm ${DOWNLOADED} | |
else | |
LAST_CACHED=${PREFIX}${EPOC_TIME}.jar | |
mv ${DOWNLOADED} ${LAST_CACHED} | |
fi | |
else | |
echo "Failed to download the latest technic launcher." 1>&2 | |
echo "Will try to use a previously downloaded launcher." 1>&2 | |
echo "Press ENTER/RETURN to continue." | |
read junk | |
fi | |
[ -f "${LAST_CACHED}" ] || { | |
echo "Failed to download or find a previously downloaded technic launcher." 1>&2 | |
echo "Aborted script $0" 1>&2 | |
exit 1 | |
} | |
java -jar ${LAST_CACHED} | |
ls -r1 ${PREFIX}*.jar 2>/dev/null | | |
tail -n +$((KEEP_LIMIT + 1)) | | |
xargs -L 1 -J % rm % | |
popd >/dev/null | |
trap - ERR EXIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the script featured in the http://youtu.be/AzZzaWwGaQ4 tutorial.