forked from Gp2mv3/Syntheses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.sh
executable file
·207 lines (169 loc) · 4.74 KB
/
add.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
# _ _
# ___ ___ _ __ ___| |_ __ _ _ __ | |_ ___
# / __/ _ \| '_ \/ __| __/ _` | '_ \| __/ _ \
# | (_| (_) | | | \__ \ || (_| | | | | || __/
# \___\___/|_| |_|___/\__\__,_|_| |_|\__\___|
args=("$@")
nbr_arg=5
section=( "summary" "notes" "exam" "exercises" )
sols="only none both"
months="Janvier Mars Juin Août Novembre"
minmajs="Mineure Majeure All"
size_titre=20
# __ _ _
# / _|_ _ _ __ ___| |_(_) ___ _ __
# | |_| | | | '_ \ / __| __| |/ _ \| '_ \
# | _| |_| | | | | (__| |_| | (_) | | | |
# |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|
function subdirectory {
if [ $1 == exam ] || [ $1 == test ]; then
makef=Makefileexam
fullname="$name-$1-$year-$month-$minmaj"
base=exam
else
if [ $1 == exercises ]; then
makef=Makefileexercises
else
makef=Makefile
fi
fullname="$name-$1"
base=tex
fi
fulldir="$dir/$1"
mkdir -p "$fulldir"
if [ $1 == exam ]; then
if ! [ -f "$fulldir/$1.mk" ]; then
sed "s/name/$name/g; s/type/$1/g" ./templates/exam.mk >> "$fulldir/$1.mk"
fi
fulldir="$fulldir/$year"
mkdir -p "$fulldir"
if ! [ -f "$fulldir/$year.mk" ]; then
sed "s/year/$year/g; s/type/$1/g" ./templates/year.mk >> "$fulldir/$year.mk"
fi
fulldir="$fulldir/$month"
mkdir -p "$fulldir"
if ! [ -f "$fulldir/$month.mk" ]; then
sed "s/month/$month/g; s/year/$year/g" ./templates/month.mk >> "$fulldir/$month.mk"
fi
fulldir="$fulldir/$minmaj"
mkdir -p "$fulldir"
fi
if ! [ -f "$fulldir/Makefile" ]; then
sed "s/sol/$sol/g; s/section/$1/g; s/name/$name/g; s/minmaj/$minmaj/g; s/month/$month/g" ./templates/$makef >> "$fulldir/Makefile"
fi
import="epl$1"
if ! [ -f "$fulldir/$1/$fullname.tex" ]; then
sed "s/name/$name/g; s/quadri/$quadri/g; s/sigle/$sigle/g; s/code/$code/g; s/import/$import/g; s/year/$year/g; s/month/$month/g" ./templates/$base.tex > "$fulldir/$fullname.tex"
fi
}
function mk {
mk=$dir/$name.mk
if ! [ -f $mk ]; then
sed "s/quadri/$quadri/g; s/name/$short/g; s/option/$option/g; s/code/$code/g" ./templates/mk.mk >> $mk
fi
}
function append {
for line in ${@:2}; do
echo $line
done
}
#TODO nettoyage
function valid_section {
if [ $1 = "all" ]; then
return 1
fi
for i in ${section[@]} ; do
if [ $i = $1 ]; then
return 1
fi
done
return 0
}
contains() {
[[ $1 =~ $2 ]] && return 0 || return 1
}
# _ _
# | |__ ___| |_ __
# | '_ \ / _ \ | '_ \
# | | | | __/ | |_) |
# |_| |_|\___|_| .__/
# |_|
# help
if [ $# -lt $nbr_arg ] || [ $1 = "--help" ]; then
echo "
use: bash add.sh quadri titre sigle code repertory sol year month minmaj
e.g: bash add.sh 1 math FSAB 1101 summary
e.g: bash add.sh 1 math FSAB 1201 exercises only
e.g: bash add.sh 1 info FSAB 1401 exam both 2015 Juin All
where repertory is summary, notes, exam, exercises or all
sol is only: only contains the solution
none: only contains the statement
both: contains both"
exit
fi
# ___ _ __ _ __ ___ _ __
# / _ \ '__| '__/ _ \| '__|
# | __/ | | | | (_) | |
# \___|_| |_| \___/|_|
# errors, argument
error=false
re='^[1-8]+$'
if ! [[ $1 =~ $re ]] || [ $1 -lt 1 ] || [ $1 -gt 8 ]; then
echo "Quadrimestre must be a integer in range 1..8"
error=true
fi
if [ ${#args[1]} -gt $size_titre ]; then
echo "Title size (actually ${args[1]}) must be lower than $size_titre"
error=true
fi
if valid_section $5 ; then
echo "Please choice summary, notes, exam, exercises or all"
error=true
fi
if ! contains "${sols}" $6; then
echo "Please choose sol among \`\`${sols}''. You chose \`\`$6''."
error=true
fi
if ! contains "${months}" $8; then
echo "Please choose the month among \`\`${months}''. If you feel one is missing let us know. You chose \`\`$8''."
error=true
fi
if ! contains "${minmajs}" $9; then
echo "Please choose \`\`${minmajs}\'\'. You chose \`\`$9''."
error=true
fi
if [ $error = true ]; then
exit
fi
# _ __ _ __ ___ ___ ___ ___ ___
# | '_ \| '__/ _ \ / __/ _ \/ __/ __|
# | |_) | | | (_) | (_| __/\__ \__ \
# | .__/|_| \___/ \___\___||___/___/
# |_|
sigle=$3
code=$4
dir="src/q$1/$2-$3$4"
quadri=$1
short=$2
option=$3
code=$4
name=$short-$option$code
ext=$5
sol=$6
year=$7
month=$8
minmaj=$9
echo Starting:
echo Create directory...
mkdir -p $dir
mk
echo Create subdirectory...
if [ $ext = "all" ]
then
for s in "${section[@]}" ; do
subdirectory $s
done
else
subdirectory $ext
fi