Skip to content

Commit

Permalink
feat: make docker also working for the special issues
Browse files Browse the repository at this point in the history
Signed-off-by: Hamed Faramarzi <hamed.faramarzi@gmail.com>
  • Loading branch information
ha36d committed Oct 30, 2023
1 parent bfb666c commit 5ef9ac7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
6 changes: 6 additions & 0 deletions docker/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
46 changes: 33 additions & 13 deletions linux_mac/magpi-issue-downloader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand All @@ -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

0 comments on commit 5ef9ac7

Please sign in to comment.