-
Notifications
You must be signed in to change notification settings - Fork 1
/
bashcraft.sh
123 lines (107 loc) · 4.53 KB
/
bashcraft.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# bashcraft, a minimal Minecraft launcher and updater
# crafted by Alex (Qwertylex), Alice Jenkinson (0x52a1) and maybe some more
# see https://github.com/Qwertylex/bashcraft/blob/master/README.md for details
# License: This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
# To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/
BashCraftVersion="v0.2"
# colors up in this thing
BRed='\033[1;31m'
BBlue='\033[1;34m'
BGreen='\033[1;32m'
BYellow='\033[1;33m'
BWhite='\033[1;37m'
NColor='\033[0m'
StatusInfo() { echo -e "$BBlue::$BWhite $*$NColor"; }
StatusAction() { echo -e "$BGreen::$BWhite $*$NColor"; }
StatusQuestion() { echo -e "$BYellow::$BWhite $*$NColor"; }
StatusError() { echo -e "$BRed::$BWhite $*$NColor"; }
ReadInput() { echo -ne "$BYellow::$BWhite $*$NColor " && read -e; }
ReadSilentInput() { echo -ne "$BYellow::$BWhite $*$NColor " && read -se && echo; }
# define some functions
DoMinecraftUpdate() {
if [ ! "$MCdir" == "" ]; then # we might as well check if we have a valid dir i guess
mkdir -p "$MCdir/bin"
cd "$MCdir/bin"
StatusInfo "Downloading OS natives..."
case "$OS" in
"Linux") curl -s -O http://s3.amazonaws.com/MinecraftDownload/linux_natives.jar;;
"Darwin") curl -s -O http://s3.amazonaws.com/MinecraftDownload/macosx_natives.jar;;
"SunOS") curl -s -O http://s3.amazonaws.com/MinecraftDownload/solaris_natives.jar;;
esac
StatusInfo "Extracting OS natives..."
unzip -qq *_natives.jar -d natives
rm *_natives.jar
StatusInfo "Downloading LWJGL..."
curl -s -O http://s3.amazonaws.com/MinecraftDownload/lwjgl.jar
curl -s -O http://s3.amazonaws.com/MinecraftDownload/jinput.jar
curl -s -O http://s3.amazonaws.com/MinecraftDownload/lwjgl_util.jar
StatusInfo "Downloading Minecraft..."
curl -s -O http://s3.amazonaws.com/MinecraftDownload/minecraft.jar
StatusAction "Update complete."
else
StatusError "Internal error."
fi
}
PrintHelp() {
StatusQuestion "bashcraft $BashCraftVersion, a Bash Minecraft launcher"
StatusQuestion "Usage: $0 [--force-update] [--remove-prefs] [--change-prefs] [--help]"
StatusQuestion "For more information, see https://github.com/Qwertylex/bashcraft"
}
# determine what OS we're running under
OS=`uname -s`
case "$OS" in
"Linux"|"SunOS") MCdir=~/.minecraft;;
"Darwin") MCdir=~/Library/Application\ Support/minecraft;;
*) StatusError "Unsupported operating system, exiting."; exit 2;;
esac
StatusInfo "OS is $OS, Minecraft directory is $MCdir"
# check command-line parameters
for ARG in "$@"; do
case "$ARG" in
"--force-update")
StatusAction "Forcing Minecraft update"; DoMinecraftUpdate;;
"--remove-prefs")
rm "$MCdir/bashcraft-prefs"; exit;;
"--change-prefs")
rm "$MCdir/bashcraft-prefs";;
"--help")
PrintHelp; exit;;
*)
StatusError "Invalid option \"$ARG\", see $0 --help for info"; exit 1;;
esac
done
# check if minecraft even exists
if [ ! -f "$MCdir/bin/minecraft.jar" ]; then
# minecraft.jar doesn't exist, hand off to the updater
StatusAction "minecraft.jar doesn't exist, forcing Minecraft update"
DoMinecraftUpdate
fi
# check for authentication details
if [ ! -f "$MCdir/bashcraft-prefs" ]; then
# we don't have any auth details, so request them
StatusQuestion "No Minecraft authentication details found."
StatusQuestion "If you don't have a Minecraft account, just press Enter."
ReadInput "Username:"; username=$REPLY
if [ ! "a$username" == "a" ]; then
# we'll only get here if we were actually given a username
# so, prompt for password here. just a little UX thing i guess
ReadSilentInput "Password:"; password=$REPLY
fi
# save the details
StatusAction "Saving preferences..."
echo "username=\"$username\"" > "$MCdir/bashcraft-prefs"
echo "password=\"$password\"" >> "$MCdir/bashcraft-prefs"
echo "MCoptions=\"\"" >> "$MCdir/bashcraft-prefs"
else
# we have auth details, so load them
StatusAction "Loading preferences..."
source "$MCdir/bashcraft-prefs"
fi
# do the actual Minecraft launch
cd "$MCdir/bin"
java -Xms512M -Xmx1024M -Xincgc \
-cp "minecraft.jar:jinput.jar:lwjgl.jar:lwjgl_util.jar" \
-Dorg.lwjgl.librarypath="$(pwd)/natives" \
-Dnet.java.games.input.librarypath="$(pwd)/natives" \
net.minecraft.client.Minecraft $username $password $MCoptions