From cd3b6bc800cf7a02cfa8357fe3261241f94523ad Mon Sep 17 00:00:00 2001 From: Hamed Faramarzi Date: Mon, 30 Oct 2023 14:50:37 +0100 Subject: [PATCH] feat: make docker also working for the special issues Signed-off-by: Hamed Faramarzi --- docker/Readme.md | 6 ++++ linux_mac/magpi-issue-downloader.sh | 46 +++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/docker/Readme.md b/docker/Readme.md index 01a9f6c..754d793 100644 --- a/docker/Readme.md +++ b/docker/Readme.md @@ -18,6 +18,12 @@ docker run -v $(pwd)/issues:/app/issues/ -u $(id -u):$(id -g) magpidownloader -f docker run -v $(pwd)/issues:/app/issues/ joergi/mag-pi-downloader -f 1 -l 2 ``` +To download special issues (books), the type argument can be used: + +```bash +docker run -v $(pwd)/special_issues:/app/issues/ -u $(id -u):$(id -g) magpidownloader -t special +docker run -v $(pwd)/special_issues:/app/issues/ joergi/mag-pi-downloader -t special +``` (unfortunately the issues folder is root, so you have to change it to your user) diff --git a/linux_mac/magpi-issue-downloader.sh b/linux_mac/magpi-issue-downloader.sh index ff37419..6817b94 100755 --- a/linux_mac/magpi-issue-downloader.sh +++ b/linux_mac/magpi-issue-downloader.sh @@ -4,6 +4,17 @@ set -o errexit set -o nounset IFS=$'\n\t' +while getopts f:l:t: flag +do + case "${flag}" in + t) type=${OPTARG};; + *) echo "Invalid option: -${OPTARG}";; + esac +done +if [[ -z ${type+x} ]]; then + type="issue" +fi + # ------------------------------------------------------------------ # [Author] joergi - https://github.com/joergi/MagPiDownloader # use now the generic common downloader (https://github.com/joergi/downloader/) @@ -21,24 +32,33 @@ BASEDIR=$(dirname "$0")/.. OUTDIR=$BASEDIR/issues if [ ! -d "$OUTDIR" ]; then - mkdir "$OUTDIR" + mkdir "$OUTDIR" fi -downloadUrl="https://magpi.raspberrypi.com/issues/%02d/pdf/download" +if [[ $type = "issue" ]]; then + echo "Downloading issues" -file="$BASEDIR/sources-for-download/regular-issues.txt"; -if [ "${IS_DOCKER:-false}" == "true" ]; then - remote_url="https://raw.githubusercontent.com/joergi/MagPiDownloader/main/sources-for-download/regular-issues.txt" - recentIssue=$(curl -s "$remote_url") -else - recentIssue=$(cat "$file") -fi + downloadUrl="https://magpi.raspberrypi.com/issues/%02d/pdf/download" -# workaround for a known limitation in bash 3.x: http://lists.gnu.org/archive/html/bug-bash/2006-01/msg00018.html -# stackoverflow: https://stackoverflow.com/questions/32596123/why-source-command-doesnt-work-with-process-substitution-in-bash-3-2/32596626#32596626 -# shellcheck disable=SC1091 -source /dev/stdin <<<"$(curl -s https://raw.githubusercontent.com/joergi/downloader/0.4.6/linux_mac/downloader.sh)" "$downloadUrl" "$OUTDIR" "$recentIssue" MagPi_ "$@" + file="$BASEDIR/sources-for-download/regular-issues.txt"; + + if [ "${IS_DOCKER:-false}" == "true" ]; then + remote_url="https://raw.githubusercontent.com/joergi/MagPiDownloader/main/sources-for-download/regular-issues.txt" + recentIssue=$(curl -s "$remote_url") + else + recentIssue=$(cat "$file") + fi + curl -s https://raw.githubusercontent.com/joergi/downloader/0.4.6/linux_mac/downloader.sh | bash /dev/stdin "$downloadUrl" "$OUTDIR" "$recentIssue" MagPi_ "${@}" +elif [[ $type = "special" ]]; then + echo "Downloading special issues" + + file=$BASEDIR"/sources-for-download/special-issues.txt" + while IFS= read -r line + do + curl -s https://raw.githubusercontent.com/joergi/downloader/0.4.6/linux_mac/downloader.sh | bash /dev/stdin "$line" "$OUTDIR" + done < "$file" +fi exit 0