Bookshelf PDF download

pull/343/merge
Serge Schneider 2020-05-13 13:09:03 +01:00
parent 08fc0b9a82
commit b9bb59c237
3 changed files with 15 additions and 15 deletions

15
stage4/03-bookshelf/00-run.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh -e
BOOKSHELF_URL="https://magpi.raspberrypi.org/bookshelf.xml"
GUIDE_URL="$(curl -s "$BOOKSHELF_URL" | awk -F '[<>]' "/<TITLE>Raspberry Pi Beginner's Guide v3<\/TITLE>/ {f=1; next} f==1 && /PDF/ {print \$3; exit}")"
OUTPUT="$(basename "$GUIDE_URL" | cut -f1 -d'?')"
if [ ! -f "files/$OUTPUT" ]; then
rm files/*.pdf -f
curl -s "$GUIDE_URL" -o "files/$OUTPUT"
fi
file "files/$OUTPUT" | grep -q "PDF document"
install -v -o 1000 -g 1000 -d "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/Bookshelf"
install -v -o 1000 -g 1000 -m 644 "files/$OUTPUT" "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/Bookshelf/"

View File

@ -1,15 +0,0 @@
#!/bin/sh -e
magpi_regex="MagPi[[:digit:]]*.pdf"
magpi_loc="$(curl -s https://magpi.raspberrypi.org/latest-pdf)"
magpi_latest="$(echo "$magpi_loc" | grep "$magpi_regex" -m 1 -o)"
if [ ! -f "files/$magpi_latest" ]; then
find files/ -regextype grep -regex "files/$magpi_regex" -delete
wget "$magpi_loc" -O "files/$magpi_latest"
fi
file "files/$magpi_latest" | grep -q "PDF document"
install -v -o 1000 -g 1000 -d "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/MagPi"
install -v -o 1000 -g 1000 -m 644 "files/$magpi_latest" "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/MagPi/"