Husk zeropad på hex-verdier
[einar-bin] / minecraft.sh
1 #!/bin/bash
2 # This script assumes that you have prepared various versions of
3 # Minecraft bin folders in your $MC_HOME like this:
4 # ${MC_HOME}/bin-version (example: ${MC_HOME}/bin-1.2.5)
5 #
6 # The script tries to preserve the various versions of the bin folder
7 # by copying the selected bin folder to a "working folder", to prevent
8 # accidental updates on launch.
9 #
10 # Use at your own risk, changing minecraft versions around may result in
11 # unexpected and undesirable behaviour. You may lose your saves.
12 # This script does not handle backups of the world data, I suggest using
13 # deja-dup or similar backup software. It's good for you.
14
15 # Written by Einar Jørgen Haraldseid <einar@haraldseid.net>
16 # inspired by a similar idea by Lars Erik Pedersen
17
18 # Released to the public under the WTFPL: http://sam.zoy.org/wtfpl/COPYING
19
20 # CONFIG STUFF - change these to suit your system
21 # Minecraft home folder, where the binaries and saves and stuff are stored:
22 MC_HOME="${HOME}/.minecraft"
23 # Location and filename for the Minecraft launcher jar:
24 MC_LAUNCHER="${HOME}/bin/minecraft.jar"
25 # Command line to run to start Minecraft:
26 MC_COMMAND="java -Xmx2048M -Xms1024M -cp ${MC_LAUNCHER} net.minecraft.LauncherFrame"
27
28 # This might be needed to fix 64bit java on Linux (path to your 64bit java libs)
29 # Uncomment this if not suitable.
30 export LD_LIBRARY_PATH="/usr/java/latest/lib/amd64/"
31
32
33 # Here comes the code
34
35 UPDATEMC=0
36
37 if [ ${#} -lt 1 ]; then
38 echo "Usage: 'minecraft <version>' or 'minecraft --add <version>'"
39 exit 1
40 fi
41
42 if [ "${1}" == "--add" ]; then
43 if [ "${#}" -ne 2 ]; then
44 echo "You must supply what version you are adding: 'minecraft --add <version>'"
45 exit 1
46 else
47 MC_NEW_FOLDER="${MC_HOME}/bin-${2}"
48 read -p "Will save new bin-folder called bin-${2}, press update when prompted."
49 UPDATEMC=1
50 fi
51 fi
52
53 if [ -z ${MC_HOME} ]; then
54 echo "Minecraft home folder not set! Baaaad idea!"
55 exit 1
56 fi
57
58 if [ ! -d ${MC_HOME} ]; then
59 echo "Minecraft home folder (${MC_HOME}) not found!"
60 exit 1
61 fi
62
63 if [ ${UPDATEMC} -ne 1 ]; then
64 MC_VERSION_FOLDER="${MC_HOME}/bin-${1}"
65 else
66 MC_VERSION_FOLDER=$(ls -d ${MC_HOME}/bin-* | tail -n 1)
67 fi
68
69 MC_WORKING_FOLDER="${MC_HOME}/bin"
70
71 if [ ! -d "${MC_VERSION_FOLDER}" ]; then
72 echo "Could not find that version folder (${MC_VERSION_FOLDER})"
73 echo -e "\nAvailable Minecraft versions are:"
74 echo "---------------------------------"
75 ls -d ${MC_HOME}/bin-* | cut -d "-" -f 2
76 exit 1
77 fi
78
79 if [ -d "${MC_WORKING_FOLDER}" ]; then
80 rm -rf ${MC_WORKING_FOLDER}
81 elif [ ! -d "${MC_WORKING_FOLDER}" ]; then
82 echo "Minecraft bin folder (${MC_WORKING_FOLDER}) is not a directory, bailing out."
83 exit 1
84 fi
85
86 if [ ! -e "${MC_WORKING_FOLDER}" ]; then
87 cp -r ${MC_VERSION_FOLDER} ${MC_WORKING_FOLDER}
88 ${MC_COMMAND}
89 if [ ${UPDATEMC} == 1 ]; then
90 cp -r ${MC_WORKING_FOLDER} ${MC_NEW_FOLDER}
91 fi
92 fi