-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_assignment
executable file
·82 lines (68 loc) · 2.33 KB
/
create_assignment
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
echo Sheet Number:
read sheetNumber
size=${#sheetNumber}
if [ $size -eq 1 ]
then
sheetNumber="0$sheetNumber"
fi
echo Number of Exercises:
read nmbrExercises
date=$(date '+%Y-%m-%d')
title=$(sed -n '1p' config.txt | sed -E 's/(.*):(.*)/\2/')
group=$(sed -n '2p' config.txt | sed -E 's/(.*):(.*)/\2/')
students=""
studentNames=""
while IFS= read -r line
do
if echo "$line" | grep -Eq 'Name: .*'
then
name=$(echo $line | sed -E 's/Name: (.*) StudentNumber: (.*)/\1/')
studentid=$(echo $line | sed -E 's/Name: (.*) StudentNumber: (.*)/\2/')
students="${students}$name ($studentid) \\\\\\\\ "
studentNames="${studentNames}$(echo $name | sed -E 's/(.*)\s(.*)/\2/')"
fi
done < config.txt
cp -a "template/." "assignment_$sheetNumber/"
cd "assignment_$sheetNumber"
cd main
sed -i "s/%sheetnr/$sheetNumber/g" main.tex
sed -i "s/%Authors/$students/g" main.tex
sed -i "s/XXXXXXXX/$date/g" main.tex
sed -i "s/%Title/$title/g" main.tex
sed -i "s/.*%title/\\\\ihead\{${title} \\\\\\\\%title/g" ../../styles/preamble.tex
sed -i "s/.*%Authors/${students}%Authors/g" ../../styles/preamble.tex
sed -i "s/.*%group/${group}%group/g" ../../styles/preamble.tex
month=$(date '+%m')
year=$(date '+%Y')
if [ $month -le 3 ] || [ $month -ge 10 ]
then
sed -i "s/.*%tornus/Winter $year \\\\\\\\ %tornus/g" ../../styles/preamble.tex
else
if grep -q "Assignment" ../../styles/preamble.tex
then
sed -i "s/.*%tornus/Summer $year \\\\\\\\ %tornus/g" ../../styles/preamble.tex
else
sed -i "s/.*%tornus/Sommer $year \\\\\\\\ %tornus/g" ../../styles/preamble.tex
fi
fi
studentNames=$(echo $studentNames | sed -E 's/ü/ue/g')
studentNames=$(echo $studentNames | sed -E 's/ä/ae/g')
studentNames=$(echo $studentNames | sed -E 's/ö/oe/g')
mv main.tex "${studentNames}_Assignment${sheetNumber}.tex"
cd ..
for (( i=1; i<=$nmbrExercises; i++ ))
do
exercise=""
if [ $i -lt 10 ]
then
exercise="0$i"
else
exercise="$i"
fi
cp -a "exercise_template/." "exercise_$exercise/"
mv exercise_$exercise/ex_00.tex exercise_$exercise/ex_$exercise.tex
sed -i "s/FILENAME/..\/main\/${studentNames}_Assignment$sheetNumber.tex/g" "exercise_$exercise/ex_$exercise.tex"
sed -i "s/%subfile/\\\\subfile\{..\/exercise_$exercise\/ex_$exercise.tex\}\n%subfile/g" "main/${studentNames}_Assignment$sheetNumber.tex"
done
rm -r exercise_template