Skip to content

Instantly share code, notes, and snippets.

@zendeavor
Created June 11, 2012 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zendeavor/2909220 to your computer and use it in GitHub Desktop.
Save zendeavor/2909220 to your computer and use it in GitHub Desktop.
HIB manager script for Archlinux
#!/usr/bin/env bash
#_humblebundletorrent=""
[[ -f PKGBUILD ]] || {
echo "This script requires the game's PKGBUILD to function."
echo "Please extract the tarball for the desired game and run this script again."
}
. PKGBUILD
_archive="source[0]%%:*"
hibenv=('_humblebundle1key'
'_humblebundle2key'
'_humblebundle3key'
'_humblebundle4key'
'_humblebundleVkey')
hibvox=('_humblevoxatronkey')
hibfb=('_humblebundlefrozenkey')
hibfs=('_humblebundlesynapsekey')
hibandroid=('_humblebundleandroidkey'
'_humblebundleandroid2key')
[[ -f "${_humblebundledir}/${!_archive}" ]] && {
ln -sf "${_humblebundledir}/${!_archive}" .
}
_genkeyarray() {
_checkkey
}
_checkkey() {
for keyvar in "${_keyarray[@]}"; do
_key="keyvar"
[[ -n "${!_key}" ]] && break
done
_checkgame
}
_checkgame() {
[[ -f "${!_archive}" ]] || {
local _prompt="Absolute path (omit trailing slashes): "
[[ -z "${_humblebundledir}" ]] && {
echo "Specify the path to the directory containing ${!_archive}"
echo -n "${_prompt}"
while read -r _dir; do
while [[ -f "${_dir}/${!_archive}" ]]; do
[[ $(md5sum "${_dir}/${!_archive}") == ${md5sum[0]} ]] {
ln -sf "${_dir}/${!_archive}" .
export _humblebundledir="${_dir}"
}
done
done
}
echo "Y to specify path to existing download, blank to specify your humble indie bundle key."
echo "Alternatively, place the download into ${_humblebundledir} and retry."
read -r _cont
case "${_cont}" in
[yY]) _dlgame
;;
*) echo "Specify your humble indie bundle key."
echo -n "Humble Indie Bundle key: "
read -r _hib
[[ -n "${_hib}" ]] && _key="_hib"
;;
esac
}
}
_dlgame() {
_uri="$(curl -s http://www.humblebundle.com/downloads?key="${!_key}" \
| grep "${!_archive}")"
echo " 1. Torrent with aria2c"
echo " 2. HTTP with curl"
echo -n "Choose download method: "
read -a _method
case "${_method}" in
1)
if [[ -x "$(type -p aria2c)" ]]; then
_uri="${_uri##*data-bt\=\'}"
_uri="${_uri%%\'*}"
echo "To resume this download later run:"
echo "\`aria2c ${pkgname}.torrent\`"
[[ ! -f "${pkgname}.torrent" ]] &&
curl -o "${pkgname}.torrent" "${_uri}"
aria2c "${pkgname}.torrent" --seed-time=0
else
error "aria2c executable not found! Please install aria2."
fi
} ;;
2)
_uri="${_uri##*data-web\=\'}"
_uri="${_uri%%\'*}"
[[ -f "${!_archive}.part" ]] &&
curl -o "${!_archive}.part" "${_uri}"
mv "${!_archive}.part" "${!_archive}" ;;
*) echo "Please choose option 1 or 2." ;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment