Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker with special issues - PR for running all tests #207

Draft
wants to merge 2 commits into
base: docker_special_issues
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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