#!/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 . WORKDIR /dl CMD echo "Usage: gamedl []" 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 [] DESCRIPTION Run game platform downloaders in a docker container. Currently supported are: - Humble (https://pypi.org/project/humblebundle-downloader/) - Itch.io (https://pypi.org/project/itchiodl/) The downloaders run in a docker container with your current working dir mounted to /dl inside the container. COMMANDS Every command except help and build get forwarded into the container, so you can run arbitrary commands if you know what you are doing. hbd Run the Humble downloader. Run 'gamedl hbd -h' for help. itch-download Run the Itch.io downloader. Run 'gamedl itch-download -h' for help. 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