-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
50 lines (41 loc) · 1.62 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh -l
validate_answers_folder() {
subdircount=$(find exercises/ -maxdepth 1 -type d | wc -l)
if [[ "$subdircount" -eq 1 ]]; then
echo "The exercises folder does not contain any subdirectories. Please create a subdirectory for each question."
exit 1
fi
for folder in $(ls -d exercises/*/)
do
# Check if the folder doesn't have 2 files
if [ $(ls -1 $folder | wc -l) -ne 2 ]; then
echo "The folder $folder does not have 2 files. Please check if the folder contains the answer and the input files."
exit 1
fi
# Check if folder/input.txt exists
if [ ! -f $folder/input.txt ]; then
echo "The folder $folder does not have an input.txt file. Please check if the folder contains the answer and the input files."
exit 1
fi
# Check if folder/answer.txt exists
if [ ! -f $folder/answer.txt ]; then
echo "The folder $folder does not have an answer.txt file. Please check if the folder contains the answer and the input files."
exit 1
fi
done
}
if [ -z "$2" ]; then
echo "The ANSWERLOCATION environment variable is not set. Please set it to the location of the zip file containing the answers and the input files."
exit 1
fi
curl -Lo exercises.zip $2
if unzip -qt exercises.zip > /dev/null; then
unzip -q exercises.zip
rm exercises.zip
else
echo "The answers url input is not a valid zip file or the url is not accessible. Please check the url and try again."
exit 1
fi
validate_answers_folder
time=$(date)
echo "::set-output name=time::$time"