created gamedl with build, hbd and itch-download commands

This commit is contained in:
fanir 2022-03-21 01:20:31 +01:00
commit a2e5c666d5

75
gamedl Executable file
View file

@ -0,0 +1,75 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
IMAGE=gamedl
CONTAINER=$IMAGE
function build_image () {
echo "building $IMAGE..."
# docker build --tag "$IMAGE" .
docker build --tag "$IMAGE" - << EOF
FROM python:3-alpine
RUN apk add --no-cache git
RUN pip install itchiodl
WORKDIR /usr/src/humble-dl
RUN \
git clone 'https://github.com/xtream1101/humblebundle-downloader.git' . &&\
wget -O trovefix.patch 'https://patch-diff.githubusercontent.com/raw/xtream1101/humblebundle-downloader/pull/59.patch' &&\
git apply trovefix.patch &&\
pip install -e .
CMD echo "Usage: gamedl <hbd|itch-download|help|build> [<options>]"
EOF
}
function check_image () {
if ! (docker image inspect "$IMAGE" >/dev/null); then
echo "cannot access docker image $IMAGE, it probably does not exist."
while true; do
read -p "build image? [yn] " yn
case $yn in
[Yy]* ) build_image; exit ;;
[Nn]* ) echo "bye"; exit ;;
* ) echo "Please answer yes or no." ;;
esac
done
fi
}
function run_image () {
echo "mounting your local working dir as /dl"
docker run -u $(id -u):$(id -g) -v $PWD:/dl -it --rm --name "$CONTAINER" "$IMAGE" "$@"
}
function show_help () {
echo "Usage $0 <command> [<options>]
Commands:
hbd
Run the Humble downloader.
itch-download
Run the Itch.io downloader.
build
(Re)build the gamedl-image.
help
That is what you are reading now.
"
}
cmd="help"
if [ $# -ge 1 ]; then
cmd="$1"
fi
case "$cmd" in
help | h | -h )
show_help; exit ;;
build )
build_image; exit ;;
* )
run_image $@; exit ;;
esac