Skip to content

Commit e72a187

Browse files
committed
Cleanup and add comments in main.sh, move Dockerfile
1 parent e75e501 commit e72a187

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

docker/Dockerfile renamed to Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ FROM alpine:3.14
33
RUN apk add --no-cache bash tzdata curl imagemagick && \
44
ln -snf /usr/share/zoneinfo/Europe/Warsaw /etc/localtime && echo Europe/Warsaw > /etc/timezone
55

6-
WORKDIR /pb-rozklad
7-
COPY . .
6+
COPY src /app
87

98
USER 1000:1000
109
VOLUME ["/data"]
1110

12-
CMD ["/bin/bash", "main.sh", "/data/config.txt"]
11+
CMD ["/bin/bash", "/app/main.sh", "/data/config.txt"]

src/main.sh

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,61 @@
11
#!/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
73
source $1
84

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
158

169

10+
cd /data/workdir
11+
# check if PDF exists on webserver
1712
http_status=$(curl -o /dev/null -LIsw "%{http_code}" $PDF_URL)
1813
if [ $http_status -ne 200 ]; then
1914
echo "Error: server returned status code" $http_status
2015
exit 1
2116
fi
22-
curl -o "current.pdf" $PDF_URL -s
17+
# if PDF exists, download it
18+
curl -so "current.pdf" $PDF_URL
2319

20+
# check if PDF for previous schedule exists, compare with current if it does
2421
if [ -r "previous.pdf" ]; then
2522
diff "previous.pdf" "current.pdf"
2623
diff_exitcode=$?
27-
if [ $diff_exitcode -eq 0 ]; then
24+
if [ $diff_exitcode -eq 0 ]; then # PDFs are the same
2825
rm "current.pdf"
2926
exit 0
30-
elif [ $diff_exitcode -ne 1 ]; then
27+
elif [ $diff_exitcode -ne 1 ]; then # some error thrown
3128
echo "Diff exited with code" $diff_exitcode
3229
exit 1
3330
fi
3431
else
32+
# PDF for previous schedule doesn't exist
33+
# don't create a comparison image, send PNG of only the current PDF
3534
diff_exitcode=-1
3635
fi
3736

37+
# create a PNG of current PDF
3838
convert -flatten -density 400 "current.pdf" "current.png"
39+
# if current and previous PDFs differ
3940
if [ $diff_exitcode -eq 1 ]; then
4041
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
4144
compare "current.png" "previous.png" "comparison.png"
4245
fi
4346

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
4548
pdf_nice="$(date $PDF_DATE_FORMAT)"
4649
ln -s "current.pdf" $pdf_nice
4750

4851
if [ $DC_ENABLED = true ]; then
4952
export DC_WEBHOOK DC_MESSAGE pdf_nice diff_exitcode
50-
bash $script_path"/msg_discord.sh"
53+
bash /app/msg_discord.sh
5154
fi
5255

56+
# TODO: check if that still works
5357
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
5559
fi
5660
if [ $ARCHIVE_LOCAL = true ]; then
5761
cp $pdf_nice "/data/archive/"

0 commit comments

Comments
 (0)