Commits

fr0stb1te  committed 55fa4af

init!

  • Participants

Comments (0)

Files changed (9)

+# 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.

File ait-extras/arch-syslinux-openrc.patch

+--- syslinux.cfg	2012-11-15 15:58:05.573364287 +0000
++++ syslinux.cfg.openrc	2012-11-15 16:03:07.866698288 +0000
+@@ -19,7 +19,7 @@
+ # Please review the wiki: https://wiki.archlinux.org/index.php/Syslinux
+ # The wiki provides further configuration examples
+ 
+-DEFAULT arch
++DEFAULT gentarch
+ PROMPT 0        # Set to 1 if you always want to display the boot: prompt 
+ TIMEOUT 50
+ # You can create syslinux keymaps with the keytab-lilo tool
+@@ -52,13 +52,19 @@
+ LABEL arch
+ 	MENU LABEL Arch Linux
+ 	LINUX ../vmlinuz-linux
+-	APPEND root=/dev/sda3 ro
++	APPEND root=/dev/sda3 init=/usr/lib/systemd/systemd ro
++	INITRD ../initramfs-linux.img
++
++LABEL gentarch
++	MENU LABEL Arch Linux (OpenRC)
++	LINUX ../vmlinuz-linux
++	APPEND root=/dev/sda3 init=/sbin/init-openrc ro
+ 	INITRD ../initramfs-linux.img
+ 
+ LABEL archfallback
+ 	MENU LABEL Arch Linux Fallback
+ 	LINUX ../vmlinuz-linux
+-	APPEND root=/dev/sda3 ro
++	APPEND root=/dev/sda3 init=/usr/lib/systemd/systemd ro
+ 	INITRD ../initramfs-linux-fallback.img
+ 
+ #LABEL windows
+#!/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.
+#
+# Arch Linux install tool
+# Warning! This script assumes that network has already been configured
+
+### Configuration ###
+
+EDITOR='vim'
+
+cfg_part_file='/tmp/ait_partitions.cfg'
+cfg_part_tool='cfdisk'
+
+cfg_bootloader='syslinux'
+
+runtime_pkgs=( 'vim' )
+base_pkgs=( 'base' )
+extra_pkgs=( 'vim' 'screen' 'openssh' 'syslog-ng' )
+
+syslinux_config='/mnt/boot/syslinux/syslinux.cfg'
+
+### Functions ###
+
+ait.msg() { echo "[ ait ] $1"; }
+ait.die() { ait.msg "[ error ] $2"; exit "$1"; }
+
+ait.get_info() {
+	read -p 'Choose your timezone [Europe/Moscow]: ' cfg_timezone
+	[[ "$cfg_timezone" ]] || { cfg_timezone='Europe/Moscow'; }
+
+	read -p 'Choose your locale [en_US.UTF-8]: ' cfg_locale
+	[[ "$cfg_locale" ]] || { cfg_locale='en_US.UTF-8'; }
+
+	read -p 'Choose a hostname [anus]: ' cfg_hostname
+	[[ "$cfg_hostname" ]] || { cfg_hostname='anus'; }
+
+	read -n1 -p 'Install base-devel? [Y/n] ' ans
+	[[ "$ans" == 'n' ]] || { base_pkgs+=( 'base-devel' ); }
+	echo
+
+	read -n1 -p 'Do you want to install openrc side-by-side with systemd? [y/N] ' ans
+	[[ "$ans" == 'y' ]] && {
+		cfg_openrc='true'
+		extra_pkgs+=( 'net-tools' )
+	    runtime_pkgs+=( 'git' 'base-devel' )
+	}
+	echo
+
+	read -n1 -p 'Do you need a bootloader? Only syslinux is supported right now. [Y/n] ' ans
+	[[ "$ans" == 'n' ]] || {
+		flag_bootloader='1'
+		extra_pkgs+=( 'syslinux' )
+	}
+	echo
+}
+
+ait.preinstall() {
+	ait.get_info
+	[[ "$runtime_pkgs" ]] && { pacman --noconfirm -Sy "${runtime_pkgs[@]}"; }
+	ait.pacman_config
+}
+
+ait.partition() {
+	answer='foo'
+
+	while [[ "$answer" ]]; do
+		for i in `find /dev -maxdepth 1 -name 'sd*'`; do
+			echo "$i"
+		done | sort -h
+
+		read -p "Select a device for partitioning (exit on blank): " answer
+		[[ "$answer" ]] && { "$cfg_part_tool" "$answer"; }
+	done
+}
+
+ait.mountconfig() {
+	read -n1 -p "You will now be tasked with selecting mountpoints. Press any key to continue." foo
+	"$EDITOR" "$cfg_part_file";
+}
+
+ait.mount_all() {
+	cat "$cfg_part_file" | grep -vE '^#|^(\s+)?$' | while read line; do
+		local device=`echo "$line" | awk '{print $1}'`
+
+		local device_cfg=`echo "$line" | awk '{print $2}'`
+		local device_cfg_mountpoint=`echo "$device_cfg" | cut -d ',' -f 1`
+		local device_cfg_fstype=`echo "$device_cfg" | cut -d ',' -f 2`
+		local device_cfg_mkfs=`echo "$device_cfg" | cut -d ',' -f 3`
+
+		[[ "$device_cfg_mountpoint" == '/' ]] && { echo "$device" | cut -d '/' -f3 > /tmp/rootdevice; }
+
+		case "$device_cfg_fstype" in
+			swap)
+				mkswap "$device"
+			;;
+
+			*)
+				[[ "$device_cfg_mkfs" == 'y' ]] && {
+					ait.msg "Creating $device_cfg_fstype on $device"
+					"mkfs.${device_cfg_fstype}" "$device"
+				}
+				[[ -d "/mnt${device_cfg_mountpoint}" ]] || { mkdir "/mnt${device_cfg_mountpoint}"; }
+				mount "$device" "/mnt${device_cfg_mountpoint}"
+			;;
+		esac
+	done
+
+	root_device=`cat /tmp/rootdevice`
+}
+
+ait.pacman_config() {
+	read -n1 -p 'Do you want to configure your mirrorlist? It will go into the installed system as well [Y/n]' ans
+	[[ "$ans" == 'n' ]] || { "$EDITOR" '/etc/pacman.d/mirrorlist'; }
+}
+
+ait.base_install() { pacstrap /mnt "${base_pkgs[@]}" "${extra_pkgs[@]}"; }
+
+ait.booloader_install() {
+	local root_device=`cat /tmp/rootdevice`
+
+	case "$cfg_bootloader" in
+		grub) ait.die 10 "Can't handle GRUB2 yet, sorry";;
+		syslinux)
+			local syslinux_config='/mnt/boot/syslinux/syslinux.cfg'
+
+			sed -ir "s/sda3/${root_device}/g" "$syslinux_config"
+		;;
+	esac
+}
+
+ait.genfstab() {
+	ait.msg "Generating fstab..."
+	genfstab -p /mnt >> /mnt/etc/fstab
+}
+
+ait.postinstall() {
+	ait.msg "Setting hostname... "
+	echo "$cfg_hostname" > /mnt/etc/hostname
+
+	ait.msg "Setting locales... "
+	echo -e "LANG=${cfg_locale}\nLC_ALL=${cfg_locale}" > /mnt/etc/locale.conf
+	sed -ir "s/#${cfg_locale}/${cfg_locale}/" '/mnt/etc/locale.gen'
+	arch-chroot /mnt locale-gen
+
+	ait.msg "Setting timezone... "
+	arch-chroot /mnt ln -s "/usr/share/zoneinfo/${cfg_timezone}" /etc/localtime
+
+	ait.msg "Generating initrd image... "
+	arch-chroot /mnt mkinitcpio -p linux
+
+	ait.msg "Generating SSH keys... "
+	arch-chroot /mnt ssh-keygen -A
+
+	[[ "$flag_bootloader" ]] && {
+		ait.msg "Writing MBR..."
+		arch-chroot /mnt syslinux-install_update -i -a -m
+	}
+
+	[[ "$cfg_openrc" == 'true' ]] && { ait.openrc; }
+
+	read -n1 -p 'Please make sure that the bootloader config is correct. Press any key to continue.'
+	"$EDITOR" "$syslinux_config"
+}
+
+ait.openrc() {
+	local openrc_pkgs=( 'openrc-sysvinit' 'openrc' 'openrc-arch-services-git' )
+	export PKGDEST='/mnt/pkg'
+
+	[[ -d "$PKGDEST" ]] || mkdir -p "$PKGDEST"
+
+	for i in ${openrc_pkgs[@]}; do
+		curl -skL "https://aur.archlinux.org/packages/${i:0:2}/${i}/${i}.tar.gz" | gzip -d | tar xf -
+		cd "$i"
+		makepkg -d --asroot
+		cd
+	done
+
+	openrc_pkgs=( `arch-chroot /mnt find /pkg -type f` )
+
+	arch-chroot /mnt pacman -U "${openrc_pkgs[@]}"
+
+	arch-chroot /mnt ln -s /etc/openrc/init.d/udev /etc/openrc/runlevels/boot/
+	arch-chroot /mnt ln -s /etc/openrc/init.d/syslog-ng /etc/openrc/runlevels/boot/
+	arch-chroot /mnt ln -s /etc/openrc/init.d /etc/init.d
+
+	echo "hostname=\"$cfg_hostname\"" > '/mnt/etc/openrc/conf.d/hostname'
+	sed -i 's/\/run\/systemd\/journal\/syslog/\/dev\/log/' '/mnt/etc/syslog-ng/syslog-ng.conf'
+
+	curl -skL 'zfh.so/arch-syslinux-openrc.patch' | sed -r "s/sda3/${root_device}/" | patch '/mnt/boot/syslinux/syslinux.cfg'
+}
+
+ait.umount_all() {
+	cat "$cfg_part_file" | grep -vE '^#|^(\s+)?$' | awk '{print $1}' | while read line; do
+		umount "$line"
+	done
+}
+
+### Main part ###
+
+# Preinstall actions
+ait.preinstall
+
+# Checking if our chosen editor exists in the system
+which "$EDITOR" &>/dev/null || { ait.die 9 "$EDITOR not found in the system"; }
+
+# Example partitioning configuration
+cat > "$cfg_part_file" << EOF
+# Partitioning config
+# device	mountpoint,fs,mkfs
+
+/dev/sda1	swap
+/dev/sda2	/,ext4,y
+EOF
+
+ait.partition
+ait.mountconfig
+ait.mount_all
+ait.base_install
+ait.booloader_install
+ait.genfstab
+ait.postinstall
+ait.umount_all
+#!/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.
+
+tmp_dir="$HOME/.aur"
+aur_url="https://aur.archlinux.org"
+aur_pkg_url="${aur_url}/packages"
+makepkg_flags='-s'
+
+aur.usage() {
+cat << EOF
+$0 [options] [package]
+
+SYNC (-S):
+-s		Search for a package
+-i		Install a package after building it
+-d		Download a package and don't build it. Implies no -i.
+
+OTHER:
+-h		Show this message
+EOF
+}
+
+aur.die() { echo "$2"; exit "$1"; }
+
+aur.get() {
+	[[ -d "$tmp_dir" ]] || {
+		echo -n "My working directory does not exist, attempting to create it... "
+		mkdir -p "$tmp_dir" && {
+			echo "success"
+		} || {
+			aur.die 9 "failed"
+		}
+	}
+
+	cd "$tmp_dir"
+	echo "Downloading $aur_pkg_url/${1:0:2}/${1}/${1}.tar.gz"
+	curl "$aur_pkg_url/${1:0:2}/${1}/${1}.tar.gz" | gzip -d | tar xf -
+}
+
+aur.build() {
+	cd "$tmp_dir/$package"
+
+	[[ "$flag_install" ]] && { makepkg_flags="${makepkg_flags} -i"; }
+
+	source PKGBUILD
+
+	echo "${depends[@]}"
+
+	for i in ${depends[@]}; do
+		pacman -Q "$i" &>/dev/null || {
+			local pkg_repo=`package-query -f "%r" -AS ${i}`
+
+			[[ "$pkg_repo" ]] || { aur.die 10 "$package depends on $i, but $i is nowhere to be seen."; }
+
+			case "$pkg_repo" in
+				aur) "$0" -Si "$i";;
+			esac
+		}
+	done
+
+	makepkg ${makepkg_flags}
+}
+
+aur.search() {
+	package-query -ASs "$1"
+}
+
+while getopts "Ssidh" option; do
+	case "$option" in
+		S) action_group='sync';;
+		s) action='search';;
+		i) flag_install='1';;
+		d) flag_download='1';;
+		h|?|*) aur.usage; exit;;
+	esac
+done
+
+[[ "$OPTIND" ]] && { shift $(($OPTIND-1)); }
+
+package="$1"
+
+case "$action_group" in
+	sync)
+		[[ "$action" == 'search' ]] && {
+			aur.search "$package"; exit 1
+		} || {
+			aur.get "$package"
+			[[ "$flag_download" ]] || { aur.build "$package"; }
+		}
+	;;
+esac
+#!/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.
+
+# Config
+minecraft_dir="$HOME/.minecraft"
+digger_dir="$HOME/.digger"
+
+java_opts="-Xms1G -Xmx1G"
+
+minecraft_launcher="$digger_dir/launcher.jar"
+minecraft_cmd="java -jar $java_opts $minecraft_launcher"
+
+minecraft_launcher_url="https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft.jar"
+minecraft_archive="http://assets.minecraft.net"
+
+# miner_path="$HOME/bin/miner"
+
+# Do not edit any further if you don't know what you are doing!
+# Functions
+
+digger.usage() {
+	script_basename="${0##*/}"
+
+	echo "Usage: $script_basename [-c] [instance]"
+	echo "Flags:"
+	echo "	-c			Create a new minecraft instance"
+	echo "	-d	<ver>	Download a specific version of minecraft.jar. You need to have a working instance for this."
+	echo "	-p	<zip>	Patch the instance's minecraft.jar with <zip>"
+	echo "	-h			Show this message"
+	echo "	-v			Version"
+	echo ""
+	echo "An instance is a directory in $digger_dir"
+	echo "If an instance is not specified, $script_basename will assume instance “default”. It makes sense to create a link by that name to your most used instance."
+}
+
+digger.patch() {
+	[[ "$miner_path" ]] || { miner_path=`which miner`; }
+	[[ "$miner_path" ]] || { digger.err "miner not found. You can get it at https://bitbucket.org/fbt/scripts"; return 1; }
+
+	"$miner_path" -d "$digger_dir/$minecraft_instance" "$mod_zip" || { digger.err "Something went wrong with miner. Patching failed."; return 1; }
+}
+
+digger.get_jar() {
+	local minecraft_jar="$digger_dir/$minecraft_instance/bin/minecraft.jar"
+	local jar_url="$minecraft_archive/${jar_version//./_}/minecraft.jar"
+
+	[[ "$jar_version" ]] && {
+		[[ `echo "$jar_version" | grep -oE '([0-9]+\.){2}[0-9]+'` == "$jar_version" ]] || {
+			digger.err "Invalid jar version. It shoud be something like this: 1.4.5"
+			return 1
+		}
+	}
+
+	[[ -f "$minecraft_jar" ]] && {
+		cp "$minecraft_jar" "$minecraft_jar.backup"
+		curl -kL "$jar_url" > "$minecraft_jar" 2>>/tmp/digger.log || {
+			digger.err "Could not download minacraft.jar from $jar_url, see /tmp/digger.log for details"
+			return 1
+		}
+	} || {
+		digger.err "$minecraft_jar does not exist. Is there a minecraft instance there?"
+		return 1
+	}
+}
+
+digger.env() {
+	[[ -d "$digger_dir" ]] || {
+		mkdir -p "$digger_dir" || {
+			digger.err "$digger_dir does not exist and could not be created"
+			return 1
+		}
+	}
+
+	[[ -f "$minecraft_launcher" ]] || {
+		digger.err "$minecraft_launcher does not exist, attempting to get it..."
+		curl -skL "$minecraft_launcher_url" > "$minecraft_launcher" && {
+			digger.msg "success"
+		} || {
+			digger.err "...and I failed to download it :("
+			return 1
+		}
+	}
+}
+
+digger.err() { echo "[digger] (error) $1" >&2; }
+digger.msg() { echo "[digger] $1"; }
+
+digger.launch() {
+	digger.msg "Launching $minecraft_instance"
+	$minecraft_cmd &>"$minecraft_dir/.minecraft.log"
+	return 0
+}
+
+digger.new() { mkdir "$digger_dir/$minecraft_instance"; }
+
+# Main part
+while getopts "chd:p:" option; do
+	case $option in
+		d) flag_get_jar='1'; jar_version="$OPTARG";;
+		p) flag_patch='1'; mod_zip="$OPTARG";;
+		c) flag_create='1';;
+		h|?|*) digger.usage; exit;;
+	esac
+done
+
+[[ "$OPTIND" ]] && { shift $(($OPTIND-1)); }
+
+[[ "$1" ]] && {
+	minecraft_instance="$1"
+} || {
+	minecraft_instance='default'
+}
+
+digger.env || exit 27
+
+[[ "$flag_create" ]] && { digger.new; }
+
+[[ "$flag_get_jar" ]] && {
+	[[ "$flag_create" ]] && {
+		digger.err "-c and -d are mutually exclusive. You have to have a working instance to substitute minecraft.jar"
+		exit 17
+	}
+
+	digger.get_jar || { exit 21; }
+}
+
+[[ "$flag_patch" ]] && {
+	[[ "$flag_create" ]] && {
+		digger.err "-c and -p are mutually exclusive. You have to have a working instance to patch minecraft.jar"
+		exit 23
+	}
+
+	digger.patch || { exit 25; }
+}
+
+
+[[ -e "$minecraft_dir" ]] && {
+	[[ -h "$HOME/.minecraft" ]] && {
+		rm "$minecraft_dir"
+	} || {
+		digger.err "$minecraft_dir exists and is not a symlink!"
+		exit 9
+	}
+}
+
+[[ -e "$digger_dir/$minecraft_instance" ]] && {
+	ln -s "$digger_dir/$minecraft_instance" "$minecraft_dir"
+	digger.launch
+} || {
+	digger.err "$minecraft_instance not found in $digger_dir"
+	exit 11
+}
+#!/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.
+#
+# About:
+# Gelbooru/Danbooru downloader
+# I am using the official APIs for this one:
+# http://gelbooru.com/index.php?page=help&topic=dapi
+# http://danbooru.donmai.us/help/api
+
+limit='100'
+action='list'
+api_type='gelbooru'
+cookies_file="$HOME/.cookies"
+
+curl_version=`curl -V | head -1`
+useragent="Booru API tool ($curl_version)"
+curl_args="-sL"
+
+gbrc="$HOME/.gbrc"
+
+while getopts "DGdvtlfe:" option; do
+	case "$option" in
+		D) api_type='danbooru';;
+		G) api_type='gelbooru';;
+
+		l) action='list';;
+		d) action='download';;
+		v) curl_args="$curl_args -vvvv";;
+
+		f) force_download='1';; 
+
+		t) archive='1';;
+		e) email="$OPTARG";;
+	esac
+done
+
+[[ "$OPTIND" ]] && { shift $((OPTIND-1)); }
+
+tags="$1"
+
+trap "rm md5sums" EXIT
+
+case "$api_type" in
+	danbooru)
+		echo "Danbooru \"public\" API requires you to log in."
+
+		[[ -f "$gbrc" ]] && { source "$gbrc"; }
+
+		[[ "$danbooru_username" ]] || { read -p "Username: " danbooru_username; }
+		[[ "$danbooru_pwhash" ]] || {
+			read -sp "Password for ${danbooru_username}: " danbooru_password; echo
+			danbooru_pwhash=`echo -n "choujin-steiner--${danbooru_password}--" | sha1sum | awk '{print $1}'`
+		}
+
+		[[ -f "$gbrc" ]] || {
+			read -p 'Do you wish to save your danbooru login credentials? The password will be encoded [y/N] ' ans
+			[[ "$ans" == 'y' ]] && {
+				echo -e "danbooru_username='${danbooru_username}'\ndanbooru_pwhash='${danbooru_pwhash}'" > "$gbrc"
+			}
+		}
+
+		api_base_url="http://danbooru.donmai.us/post/index.xml?login=${danbooru_username}&password_hash=${danbooru_pwhash}&"
+		posts_request="${api_base_url}tags=${tags}&limit=${limit}&page="
+
+		first_page='1'
+	;;
+
+	gelbooru)
+		api_base_url="http://gelbooru.com/index.php?page=dapi&s=post&q=index&"
+		posts_request="${api_base_url}tags=${tags}&limit=${limit}&pid="
+
+		first_page='0'
+	;;
+esac
+
+post_count=`curl $curl_args -A "$useragent" "${api_base_url}tags=${tags}&limit=1" \
+	| grep "posts count" | sed -E "s/.*count=\"([^ ]+)\".*/\1/"`
+query_count="$(( (post_count/limit)+1 ))"
+
+for i in `seq "$first_page" "$query_count"`; do
+#	posts=`curl $curl_args -A "$useragent" "${posts_request}$((i-1))" | sed -Ee "s/>/>\r\n/g" | grep "post "`
+	posts=( `curl $curl_args -A "$useragent" "${posts_request}$((i))" | sed -Ee "s/>/>\r\n/g" | grep "post " | sed -E "s/\"\s/\"\r\n/g" | grep "file_url=" | sed -E "s/.*file_url=\"(.*)\".*/\1/"` )
+	[[ "$force_download" ]] || find . -maxdepth 1 -mindepth 1 -type f | while read line; do md5sum "$line" | awk '{print $1}'; done > md5sums
+
+#	echo "${posts_request}$((i))"
+
+#	echo "${posts}" | while read line; do
+	for p in "${posts[@]}"; do
+#		post_data="$line"
+#		post_file=`echo "${post_data}" | sed -E "s/\"\s/\"\r\n/g" | grep "file_url=" | sed -E "s/.*file_url=\"(.*)\".*/\1/"`
+		post_file="$p"
+
+		case "$action" in
+			download)
+				unset file_skip
+
+				[[ "$gb_counter" ]] || { gb_counter='1'; }
+
+				echo -ne "${post_file}		[${gb_counter}/${post_count}]"
+				post_file_hash=${post_file##*/}; post_file_hash=${post_file_hash%%.*}
+
+				[[ "$force_download" ]] || {
+					grep "$post_file_hash" md5sums &>/dev/null && { file_skip='1'; }
+				}
+
+				[[ "$file_skip" ]] && {
+					echo -ne " (skip)"
+				} || {
+					wget -cq "${post_file}"
+				}
+
+				echo
+
+				gb_counter=$((gb_counter+1))
+			;;
+
+			list)
+				echo "${post_file}"
+			;;
+		esac
+	done
+done
+
+[[ "$action" == "download" ]] && { echo; }
+
+[[ "$archive" ]] && {
+	tar czf "gb-${tags/ /}.tgz" *
+}
+#!/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.
+
+tmpdir="/tmp/mctmp"
+mcdir="$HOME/.minecraft"
+current_dir="`pwd`"
+
+miner.usage() {
+	echo "Usage: `basename $0` [-d <minecraft_dir>] <mod>"
+}
+
+miner.msg() {
+	echo "[miner] $1"
+}
+
+miner.err() {
+	miner.msg "(error) $1" >&2
+}
+
+while getopts "d:h" option; do
+	case "$option" in
+		d) mcdir=`realpath "$OPTARG"`;;
+		h|?|*) miner.usage; exit 3;;
+	esac
+done
+
+[[ "$OPTIND" ]] && { shift $[OPTIND-1]; }
+
+target_zip=`realpath "$1"`
+
+[[ -d "$tmpdir" ]] && { rm -r "$tmpdir"; }
+
+mkdir -p "$tmpdir"
+cd "$tmpdir"
+
+[[ -f "$target_zip" ]] || { miner.err "$target_zip does not exist"; exit 1; }
+
+cp "$mcdir/bin/minecraft.jar" "$mcdir/bin/minecraft.jar.backup"
+
+miner.msg "Patching ${mcdir}/bin/minecraft.jar with ${target_zip}... "
+
+unzip "$mcdir/bin/minecraft.jar" &>/tmp/miner.log
+rm "$mcdir/bin/minecraft.jar"
+unzip -o "$target_zip" &>>/tmp/miner.log
+[[ -d "META-INF" ]] && { rm -r META-INF; }
+zip -r "$mcdir/bin/minecraft.jar" . &>>/tmp/miner.log
+
+cd; rm -r "$tmpdir"
+
+miner.msg "success"
+#!/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.
+
+# config
+
+cfg_apps_dir='/home/trash/wine.d'
+cfg_tmp_dir='/tmp/scotch'
+cfg_run_dir="$cfg_tmp_dir/run"
+cfg_log_dir="$cfg_tmp_dir/log"
+
+cfg_wine_debug_level='fixme-all'
+
+cfg_desktop="1280x720"
+
+# functions
+
+scotch.usage() {
+	echo "Scotch — a wine helper script"
+	echo "Usage: `basename $0` [-lnks] <app>"
+	echo "Flags:"
+	echo "	-l			Launch the app (default).*"
+	echo "	-n			Create a new app dir in $cfg_apps_dir.**"
+	echo "	-k			Kill all processes in the wine prefix of an app."
+	echo "	-s			Get a shell with all environment variables ready to work with the wine prefix."
+	echo
+	echo "* Scotch takes the app binary from $cfg_apps_dir/\${app}/.app_bin. The path is relative to the app dir."
+	echo "** You should really create $cfg_apps_dir/.template for scotch to copy it into new prefixes."
+}
+
+scotch.msg() { echo "[scotch] $1"; }
+scotch.err() { scotch.msg "(err) $1" >&2; }
+scotch.die() {
+	[[ "$2" ]] && { scotch.err "$2"; }
+	exit "$1"
+}
+
+scotch.env() {
+	export WINEPREFIX="$cfg_apps_dir/$app/wine"
+	export WINEDEBUG="$cfg_wine_debug_level"
+	
+	[[ -d "$cfg_apps_dir/opt/wine/bin" ]] && {
+		export PATH="$cfg_apps_dir/$app/opt/wine/bin:$PATH"
+	}
+
+	export app_bin=`cat $cfg_apps_dir/$app/.app_bin | cut -d ' ' -f 1`
+	export app_bin_args=`cat $cfg_apps_dir/$app/.app_bin | cut -d ' ' -f 2-`
+}
+
+scotch.launch() {
+	[[ -d "$cfg_apps_dir/$app" ]] || {
+		scotch.err "$app not found in $cfg_apps_dir"
+		return 1
+	}
+
+	[[ -f "$cfg_run_dir/$app.pid" ]] && {
+		app_pid=`cat "$cfg_run_dir/$app.pid"`
+
+		ps -p "$app_pid" &>/dev/null && {
+			scotch.err "$app is already running with PID $app_pid"
+			return 1
+		}
+	}
+
+	scotch.msg "Launching $app..."
+
+	[[ "$flag_nodesktop" ]] || { wine_args="explorer /desktop='$app','$cfg_desktop'"; }
+
+	scotch.env
+	cd "$cfg_apps_dir/$app/app"
+
+	[[ "$flag_nodesktop" ]] && {
+		wine "$app_bin" &>"$cfg_log_dir/$app.log" &
+	} || {
+		wine explorer /desktop="$app","$cfg_desktop" "$app_bin" $app_bin_args &>"$cfg_log_dir/$app.log" &
+	}
+
+	echo "$!" > "$cfg_run_dir/$app.pid"
+}
+
+scotch.new() {
+	[[ -d "$cfg_apps_dir/.template" ]] && {
+		[[ -e "$cfg_apps_dir/$app" ]] && {
+			scotch.err "$cfg_apps_dir/$app already exists!"
+			return 1
+		} || {
+			cp -r "$cfg_apps_dir/.template" "$cfg_apps_dir/$app"
+		}
+	} || {
+		scotch.msg "(warn) $cfg_apps_dir/.template not found. If you create a reference WINEPREFIX and put it there, it will make your life a lot easier :)"
+		mkdir -p "$cfg_apps_dir/$app"
+	}
+	
+	"$0" -s "$app"
+}
+
+scotch.kill() {
+	scotch.msg "Killing $app..."
+	scotch.env
+	wineserver -k
+}
+
+scotch.shell() { scotch.env; cd "$cfg_apps_dir/$app"; $SHELL; }
+
+# main
+
+for i in "$cfg_run_dir" "$cfg_log_dir"; do
+	mkdir -p "$i" || { scotch.err "$i does not exist and cannot be created."; exit 7; }
+done
+
+while getopts "hlsnk" option; do
+	case "$option" in
+		s) action='shell';;
+		l) action='launch';;
+		n) action='new';;
+		k) action='kill';;
+		h|?) scotch.usage; exit 3;;
+	esac
+done
+
+[[ "$OPTIND" ]] && { shift $[OPTIND-1]; }
+
+[[ "$1" ]] && {
+	app="$1"
+} || {
+	scotch.usage
+	exit 5
+}
+
+[[ "$action" ]] || { action='launch'; }
+
+scotch.$action
+
+exit "$?"
+#!/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.
+#
+# About:
+# A simple upload script for ZFH (http://zerofiles.org)
+
+# Defaults
+url_regex='^[a-z]+://.+'
+
+tmp_dir='/tmp'
+tmp_file="$tmp_dir/sup_tmp_$RANDOM"
+
+script_url='http://zfh.so/upload'
+
+default_tags='sup'
+# /Defaults
+
+[[ -f $HOME/.suprc ]] && { source $HOME/.suprc; }
+
+usage() {
+cat << EOF
+Usage: $0 [-c title] [-t tags] [-RsF] [-D num] [file/url]
+	-c			Comment/title (deprecated, optional)
+	-t			File tags
+	-R			Set to remove file after uploading (local fs only, obviously)
+	-s			Grab a screenshot to upload instead of a file/url
+	-F			Make a fullscreen shot instead of a selected window/area
+	-D [num]	Delay the screenshot for [num] seconds
+	-h			Show this message
+EOF
+}
+
+while getopts "c:t:D:sFrRh" option; do
+	arg="$OPTARG"
+
+	case $option in
+		c) comment="$arg";;
+		t) tagstr="$arg";;
+
+#		r) set_recursive='yes';;
+		R) file_remove='yes';;
+
+		s) scn='1';;
+		F) scn_fs='1';;
+		D) scn_delay="$arg";;
+
+		h) usage; exit;;
+	esac
+done
+
+[[ "$OPTIND" ]] && { shift $(($OPTIND-1)); }
+
+cleanup() {
+	[[ -f "$tmp_file" ]] && {
+		rm "$tmp_file"
+	}
+}
+
+upload() {
+	[[ "$tagstr" ]] || { tagstr="sup"; }
+	[[ "$comment" ]] || { comment="Uploaded: `date +%Y.%m.%d\ at\ %H:%M:%S`"; }
+
+	curl -b "$HOME/.cookies" -F file="@$file" \
+		-F tags="$tagstr" \
+		-F upload_mode='api' \
+		-F submit="" \
+		"$script_url" -s -L -A 'Sup Phost'
+
+	[[ "$file_remove" ]] && { rm "$file"; }
+}
+
+check_if_url() {
+	echo "$1" | grep -oE "$url_regex" &>/dev/null && { return 0; }; return 1
+}
+
+
+trap "cleanup" EXIT
+
+[[ "$scn" ]] && {
+	scn_cmd='scrot'
+	tags="$tags, screenshot"
+
+	[[ "$scn_fs" ]] || { scn_cmd="${scn_cmd} -s"; }
+	[[ "$scn_delay" ]] && { scn_cmd="${scn_cmd} -d ${scn_delay}"; }
+
+	${scn_cmd} "${tmp_file}.png"; file="$tmp_file.png"
+} || {
+	[[ "$1" ]] || { echo "No file specified"; exit 1; }
+
+	check_if_url "$1" && {
+		[[ "$comment" ]] || { comment="Source: $1, uploaded: `date +%Y.%m.%d\ at\ %H:%M:%S`"; }
+		curl -s "$1" > "$tmp_file"; file="$tmp_file"
+	} || {
+		[[ "$comment" ]] || { comment="Filename: ${1##*/}, uploaded: `date +%Y.%m.%d\ at\ %H:%M:%S`"; }
+		file="$1"
+	}
+}
+
+file_type=`file -ib "$file" | cut -d';' -f1`
+[[ "$file_type" == "text/html" ]] || [[ "$file_type" == "application/x-empty" ]] && { exit 1; }
+
+# DEBUG
+upload