Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60171468
project_build_script.sh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Apr 28, 01:21
Size
8 KB
Mime Type
text/x-shellscript
Expires
Tue, Apr 30, 01:21 (2 d)
Engine
blob
Format
Raw Data
Handle
17312336
Attached To
R1066 amc-cape
project_build_script.sh
View Options
#!/bin/bash
# This part is specific to the template.
# Entry point from bamc: build_project $exam
# $exam: name of the exam to build
#
# Useful variable
# ---------------
# DIR_WORKSPACE [current workspace dir (absolute)]
# DIR_PROJECTS [projects target directory]
# DIR_EXAMS [exams'directory in workspace] e.g. $DIR_WORKSPACE/$DIR_EXAMS/$exam
# DIR_PROJECTS [projects's directory in workspace]
# DIR_EXAM_TEMPLATE [directory of the exam template in use]
# FILE_STUDENTS
# ...
# see 'conf/bamc.conf' for full reference
#
# Useful functions
# ----------------
# verbose "text"
# debug "text"
# get_lang $exam
# ...
# see 'lib/bash/*.sh' files for full reference
function
build_project
()
{
local
exam
=
$1
lang
=
$(
get_lang
$exam
)
assert_exam
$exam
verbose
"Project '$exam' uses '$lang' language"
if
[
$?
-eq 1
]
;
then return
1;
fi
verbose
"Building AMC project for '$exam' in workspace '$DIR_WORKSPACE'..."
# Project structure
build_amc_project
$exam
if
[
$?
-ne 0
]
;
then
error
"Could not build AMC project :("
;
return
1;
fi
# Build LaTeX sections
build_sections
$exam
$lang
if
[
$?
-ne 0
]
;
then
error
"Could not build project sections :("
;
return
1;
fi
# Add media files
import_media_files
$exam
$lang
if
[
$?
-ne 0
]
;
then
error
"Could not import media files :("
;
return
1;
fi
# Import LaTeX files
import_tex_files
$exam
$lang
if
[
$?
-ne 0
]
;
then
error
"Could not import LaTeX files :("
;
return
1;
fi
# Import local LaTeX files
override_tex_files
$exam
$lang
if
[
$?
-ne 0
]
;
then
error
"Could not override LaTeX files :("
;
return
1;
fi
# Customize LaTeX file
customize_tex_files
$exam
$lang
if
[
$?
-ne 0
]
;
then
error
"Could not customize LaTeX files :("
;
return
1;
fi
# Import media files
add_media_files
$exam
if
[
$?
-ne 0
]
;
then
error
"Could not import media files :("
;
return
1;
fi
# Build student list file
import_student_file
$exam
if
[
$?
-ne 0
]
;
then
error
"Could not create student list :("
;
return
1;
fi
return
0
}
function
import_student_file
()
{
verbose
"Customizing student files"
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$1
local
exam
=
$DIR_WORKSPACE
/
$DIR_EXAMS
/
$1
local
lang
=
$2
local
FILE
=
$exam
/
$FILE_STUDENTS
check_file_exists
$FILE
if
[
$?
-ne 0
]
;
then return
1;
fi
cp
$FILE
$project
/
$FILE_STUDENTS
# Add extra students
local
nb
IFS
=
$'\n'
local
id
=
$(
tail -n 1
$project
/
$FILE_STUDENTS
| cut -d
','
-f 1
)
local
sample
=
$(
head -n 1
$DIR_EXAM_TEMPLATE
/csv/extra.csv
)
nb
=
0
local
extra_students
=
$(
read_variable_from_project EXTRA_STUDENTS
$exam
)
while
[
$nb
-lt
$extra_students
]
;
do
((
nb++
))
((
id++
))
echo
$sample
|
\
sed
"s/#NB#/$nb/g"
|
\
sed
"s/#ID#/$id/g"
|
\
sed
"s/#SCIPER#/FAKE-$nb/g"
|
\
sed
"s/#EMAIL#/$DEFAULT_EMAIL/g"
|
\
sed
"s/#SEMESTER#/$SEMESTER/g"
>>
$project
/
$FILE_STUDENTS
done
return
0
}
function
add_media_files
()
{
verbose
"Importing media files"
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$1
cp
$DIR_EXAM_TEMPLATE
/media/*
$project
/media/
}
function
customize_tex_files
()
{
verbose
"Customizing LaTeX files"
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$1
local
exam
=
$DIR_WORKSPACE
/
$DIR_EXAMS
/
$1
local
lang
=
$2
local
replace
IFS
=
$'\n'
local
CONFIG_EXAM
=
$exam
/
$FILE_EXAM
check_file_exists
$CONFIG_EXAM
if
[
$?
-ne 0
]
;
then return
1;
fi
# professor.tex
local
prof_file
=
$project
/professor.tex
check_file_exists
$prof_file
if
[
$?
-ne 0
]
;
then return
1;
fi
for
replace in
$(
cat
$CONFIG_EXAM
| grep -v
'^#'
| grep
':'
)
;
do
replace_in_file
"#$(echo $replace | cut -d ':' -f 1)#"
"$(echo $replace | cut -d ':' -f 2-)"
$prof_file
done
# first_page.tex (SIGNATURE) AND (ROOM)
local
first_page_file
=
$project
/first_page.tex
if
[
$(
grep -c
'^SIGNATURE$'
$CONFIG_EXAM
)
-gt 0
]
;
then
replace_in_file
"%SIGNATURE"
""
$first_page_file
;
fi
if
[
$(
grep -c
'^ROOM$'
$CONFIG_EXAM
)
-gt 0
]
;
then
replace_in_file
"%ROOM"
""
$first_page_file
;
fi
# exam.tex (FONT_SIZE)
local
exam_file
=
$project
/exam.tex
replace_in_file
"#LANG#"
$(
echo
$lang
| tr
'[a-z]'
'[A-Z]'
)
$exam_file
if
[
$(
grep -c
'^FONT_SIZE:'
$CONFIG_EXAM
)
-gt 0
]
;
then
replace_in_file
"\[a4paper\]"
"\[a4paper,$(grep '^FONT_SIZE:' $CONFIG_EXAM | tail -n 1 | cut -d ':' -f 2-)\]"
$exam_file
fi
# Add extra_packages.tex file
if
[
-r
$project
/common_packages.tex
]
;
then
replace_in_file
'% #COMMON_PACKAGES#'
'\\input{./common_packages.tex}'
$exam_file
fi
# Add extra_packages.tex file
if
[
-r
$project
/common_commands.tex
]
;
then
replace_in_file
'% #COMMON_COMMANDS#'
'\\input{./common_commands.tex}'
$exam_file
fi
# Add extra_section.tex file
if
[
-r
$project
/extra_section.tex
]
;
then
replace_in_file
'% #EXTRA_SECTION#'
'\\input{./extra_section.tex}'
$exam_file
fi
# Add extra_packages.tex file
if
[
-r
$project
/extra_packages.tex
]
;
then
replace_in_file
'% #EXTRA_PACKAGES#'
'\\input{./extra_packages.tex}'
$exam_file
fi
# Add extra_packages.tex file
if
[
-r
$project
/extra_commands.tex
]
;
then
replace_in_file
'% #EXTRA_COMMANDS#'
'\\input{./extra_commands.tex}'
$exam_file
fi
return
0
}
function
override_tex_files
()
{
verbose
"Importing supplementary LaTeX files"
local
common
=
$DIR_WORKSPACE
/
$DIR_COMMON
local
exam
=
$DIR_WORKSPACE
/
$DIR_EXAMS
/
$1
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$1
local
lang
=
$2
local
f
# Common (without lang)
if
[
-d
$common
]
;
then
for
f in
$(
find
$common
-maxdepth 1 -type f -name
'*.tex'
)
;
do
verbose
"- Common LaTeX file found: $f"
cp
$f
$project
/
done
fi
# Common (with lang)
if
[
-d
$common
/
$lang
]
;
then
for
f in
$(
find
$common
/
$lang
-type f -name
'*.tex'
)
;
do
verbose
"- Common LaTeX file found ($lang): $f"
cp
$f
$project
/
done
fi
# Extra
for
f in
$(
find
$exam
/ -type f -name
'*.tex'
)
;
do
verbose
"- Extra LaTeX file found: $f"
done
find
$exam
/ -type f -name
'*.tex'
-exec cp
{}
$project
/
\;
return
0
}
function
import_tex_files
()
{
verbose
"Importing LaTeX files"
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$1
local
lang
=
$2
cp
$DIR_EXAM_TEMPLATE
/base/*
$project
/
cp
$DIR_EXAM_TEMPLATE
/
$lang
/*
$project
/
return
0
}
function
build_amc_project
()
{
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$1
verbose
"Creating AMC project structure"
mkdir -p
$project
/cr/corrections/jpg
mkdir -p
$project
/cr/corrections/pdf
mkdir -p
$project
/cr/diagnostic
mkdir -p
$project
/cr/zooms
mkdir -p
$project
/data
mkdir -p
$project
/exports
mkdir -p
$project
/scans
mkdir -p
$project
/copies
mkdir -p
$project
/media
cp
$DIR_EXAM_TEMPLATE
/config/
$FILE_AMC_OPTIONS
$project
/
$FILE_AMC_OPTIONS
return
$?
}
function
import_media_files
()
{
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$1
local
exam
=
$DIR_WORKSPACE
/
$DIR_EXAMS
/
$1
local
lang
=
$2
local
questions_dir
=
$DIR_WORKSPACE
/
$DIR_QUESTIONS
/
$lang
local
media_file
verbose
"Importing media files"
for
media_file in
$(
find
$questions_dir
/ -type f -not -name
'*\.tex'
)
;
do
verbose
"Importing file '$media_file'"
cp
$media_file
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$1
/
done
return
0
}
function
is_option_active
()
{
local
section_line
=
$1
local
option
=
$2
if
[
$(
echo
$section_line
| grep -c
"!$2,"
)
-gt 0
]
;
then
return
1
else
return
0
fi
}
function
build_sections
()
{
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$1
local
exam
=
$DIR_WORKSPACE
/
$DIR_EXAMS
/
$1
local
lang
=
$2
local
question_file question section_file section
local
IFS
=
$'\n'
FILE
=
$exam
/
$FILE_SECTIONS
verbose
"Importing questions"
check_file_exists
$FILE
if
[
$?
-ne 0
]
;
then return
1;
fi
local
section_num
=
0
rm -f
$project
/sections.tex
$project
/random-sections.tex
for
section in
$(
cat
$FILE
)
;
do
# Sample format of a section line:
# !OPTION1,!OPTION2,tex_file1.tex,tex_file2.tex,...
((
section_num++
))
section_file
=
$project
/section_
${
section_num
}
.tex
rm -f
$section_file
for
question in
$(
echo
$section
| tr
','
'\n'
)
;
do
# Skip options (options start with "!")
if
[[
$question
=
~ ^!
]]
;
then
verbose
"This is an option, and not a question: $question (skipping)"
continue
;
fi
verbose
"Adding $question to section $section_file..."
;
question_file
=
$DIR_WORKSPACE
/
$DIR_QUESTIONS
/
$lang
/
$question
check_file_exists
$question_file
if
[
$?
-ne 0
]
;
then return
1;
fi
echo
"%% From $lang/$question ======================================="
>>
$section_file
echo
'\element{section'
$section_num
'}{'
>>
$section_file
cat
$question_file
>>
$section_file
echo
'}'
>>
$section_file
done
echo
"\input{./section_${section_num}.tex}"
>>
$project
/sections.tex
echo
"\input{./header_${section_num}.tex}"
>>
$project
/random-sections.tex
is_option_active
$section
'NORAND'
if
[
$?
-eq 0
]
;
then
# RANDOM order
echo
"\melangegroupe{section${section_num}}"
>>
$project
/random-sections.tex
fi
echo
"\restituegroupe{section${section_num}}"
>>
$project
/random-sections.tex
done
return
0
}
# EOF
Event Timeline
Log In to Comment