Advertisement
Guest User

Untitled

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