|
1 | 1 | #!/bin/bash
|
2 |
| -if (( $# != 1 )); then |
3 |
| - echo "Usage:" |
4 |
| - echo $0 "config-file" |
5 |
| - exit 1 |
6 |
| -fi |
| 2 | +# load config file with env variables |
7 | 3 | source $1
|
8 | 4 |
|
9 |
| -script_path="/pb-rozklad" |
10 |
| -cd /data |
11 |
| - |
12 |
| -mkdir -p "workdir" |
13 |
| -if [ $ARCHIVE_LOCAL = true ]; then mkdir -p "archive"; fi |
14 |
| -cd "workdir" |
| 5 | +# prepare data directory |
| 6 | +mkdir -p /data/workdir |
| 7 | +if [ $ARCHIVE_LOCAL = true ]; then mkdir -p /data/archive; fi |
15 | 8 |
|
16 | 9 |
|
| 10 | +cd /data/workdir |
| 11 | +# check if PDF exists on webserver |
17 | 12 | http_status=$(curl -o /dev/null -LIsw "%{http_code}" $PDF_URL)
|
18 | 13 | if [ $http_status -ne 200 ]; then
|
19 | 14 | echo "Error: server returned status code" $http_status
|
20 | 15 | exit 1
|
21 | 16 | fi
|
22 |
| -curl -o "current.pdf" $PDF_URL -s |
| 17 | +# if PDF exists, download it |
| 18 | +curl -so "current.pdf" $PDF_URL |
23 | 19 |
|
| 20 | +# check if PDF for previous schedule exists, compare with current if it does |
24 | 21 | if [ -r "previous.pdf" ]; then
|
25 | 22 | diff "previous.pdf" "current.pdf"
|
26 | 23 | diff_exitcode=$?
|
27 |
| - if [ $diff_exitcode -eq 0 ]; then |
| 24 | + if [ $diff_exitcode -eq 0 ]; then # PDFs are the same |
28 | 25 | rm "current.pdf"
|
29 | 26 | exit 0
|
30 |
| - elif [ $diff_exitcode -ne 1 ]; then |
| 27 | + elif [ $diff_exitcode -ne 1 ]; then # some error thrown |
31 | 28 | echo "Diff exited with code" $diff_exitcode
|
32 | 29 | exit 1
|
33 | 30 | fi
|
34 | 31 | else
|
| 32 | + # PDF for previous schedule doesn't exist |
| 33 | + # don't create a comparison image, send PNG of only the current PDF |
35 | 34 | diff_exitcode=-1
|
36 | 35 | fi
|
37 | 36 |
|
| 37 | +# create a PNG of current PDF |
38 | 38 | convert -flatten -density 400 "current.pdf" "current.png"
|
| 39 | +# if current and previous PDFs differ |
39 | 40 | if [ $diff_exitcode -eq 1 ]; then
|
40 | 41 | convert -flatten -density 400 "previous.pdf" "previous.png"
|
| 42 | + # important order of arguments: current PNG will be the background, |
| 43 | + # parts of it where blocks were added or removed will appear with a red overlay |
41 | 44 | compare "current.png" "previous.png" "comparison.png"
|
42 | 45 | fi
|
43 | 46 |
|
44 |
| -# nicer name for Discord upload and local archive |
| 47 | +# create a symlink of current PDF with a nicer name for upload and local archive |
45 | 48 | pdf_nice="$(date $PDF_DATE_FORMAT)"
|
46 | 49 | ln -s "current.pdf" $pdf_nice
|
47 | 50 |
|
48 | 51 | if [ $DC_ENABLED = true ]; then
|
49 | 52 | export DC_WEBHOOK DC_MESSAGE pdf_nice diff_exitcode
|
50 |
| - bash $script_path"/msg_discord.sh" |
| 53 | + bash /app/msg_discord.sh |
51 | 54 | fi
|
52 | 55 |
|
| 56 | +# TODO: check if that still works |
53 | 57 | if [ $ARCHIVE_WAYBACK = true ]; then
|
54 |
| - curl -o /dev/null "https://web.archive.org/save/$ROZKLAD_URL" -w %{url_effective} -Ls |
| 58 | + curl -o /dev/null "https://web.archive.org/save/$PDF_URL" -w %{url_effective} -Ls |
55 | 59 | fi
|
56 | 60 | if [ $ARCHIVE_LOCAL = true ]; then
|
57 | 61 | cp $pdf_nice "/data/archive/"
|
|
0 commit comments