Commits

Jack Frost  committed 6863f53

enderman

  • Participants
  • Parent commits 1b25566

Comments (0)

Files changed (1)

+#!/bin/bash
+# Copyright (c) 2012 fbt <fbt@fleshless.org>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#   - Redistributions of source code must retain the above copyright notice, 
+#       this list of conditions and the following disclaimer.
+#   - Redistributions in binary form must reproduce the above copyright notice,
+#       this list of conditions and the following disclaimer in the
+#       documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+[[ "$XDG_CONFIG_DIR" ]] || { XDG_CONFIG_DIR="$HOME/.config"; }
+
+cfg_rc_file="$XDG_CONFIG_DIR/.endermanrc"
+cfg_tmp_dir='/tmp/enderman'
+cfg_zip_url="$1"
+# cfg_miner_path="$HOME/bin/miner"
+
+[[ -f "$cfg_rc_file" ]] && { source "$cfg_rc_file"; }
+
+[[ "$cfg_miner_path" ]] || {
+	cfg_miner_path=`which miner`
+
+	[[ "$cfg_miner_path" ]] || {
+		[[ -f "miner" ]] && {
+			cfg_miner_path="`pwd`/miner"
+		}
+	}
+
+	[[ "$cfg_miner_path" ]] || {
+		enderman.err "miner not found"
+		exit 5
+	}
+}
+
+enderman.msg() { echo "[enderman] $1"; }
+enderman.err() { enderman.msg "(error) $1 :(" >&2; }
+
+enderman.catch() {
+	local name="$1"
+	local cmd="$2"
+
+	$cmd 2>"$cfg_tmp_dir/$name.err" || {
+		enderman.err "$name failed!"
+		cat "$cfg_tmp_dir/$name.err"
+		return 1
+	}
+}
+
+enderman.get_pkg() {
+	curl -fvvvkL "$cfg_zip_url" > "$cfg_tmp_dir/enderman.zip"
+}
+
+enderman.cleanup() { rm -r "$cfg_tmp_dir"; }
+# trap 'enderman.cleanup' EXIT
+
+while getopts 'hd:' opt; do
+	case "$opt" in
+		d) cfg_mc_dir="$OPTARG";;
+		h|?|*) enderman.usage; exit;;
+	esac
+done
+
+[[ "$OPTIND" ]] && { shift $[OPTIND-1]; }
+
+[[ "$cfg_mc_dir" ]] || { cfg_mc_dir="$HOME/.minecraft"; }
+
+[[ -d "$cfg_tmp_dir" ]] || {
+	mkdir -p "$cfg_tmp_dir" || {
+		enderman.err "Cannot create $cfg_tmp_dir, exiting."
+	}
+}
+
+[[ -f 'enderman.zip' ]] && {
+	cp 'enderman.zip' "$cfg_tmp_dir"
+} || {
+	enderman.catch get_pkg enderman.get_pkg || {
+		enderman.err "Could not download pack from $cfg_zip_url, exiting"
+		exit 5
+	}
+}
+
+enderman.catch unzip_pkg "unzip $cfg_tmp_dir/enderman.zip -d $cfg_tmp_dir" && {
+	rm "$cfg_tmp_dir/enderman.zip"
+} || {
+	enderman.err "Could not unzip pack, exiting"
+	exit 7
+}
+
+for d in 'config' 'mods'; do
+	[[ -d "$cfg_tmp_dir/$d" ]] && { cp -r "$cfg_tmp_dir/$d" "$cfg_mc_dir"; }
+done
+
+[[ -d "$cfg_tmp_dir/jarmods" ]] && {
+	for i in `ls "$cfg_tmp_dir/jarmods"`; do
+		miner -j "$cfg_mc_dir/bin/minecraft.jar" "$cfg_tmp_dir/jarmods/$i"
+	done
+}
+
+cd "$cfg_tmp_dir"