#/bin/bash function action_list-templates() { assert_template "quiet" local template verbose "Exam templates list:" for template in $(find $DIR_EXAM_TEMPLATES -mindepth 1 -maxdepth 1 -type d -exec basename {} \;); do color_echo_n "- \"$template\"" if [ "$(readlink $DIR_EXAM_TEMPLATES/default)" == "$template" ]; then color_echo_n ", ${White}default${NoColor}" fi if [ "$(basename $DIR_EXAM_TEMPLATE)" == "$template" ]; then color_echo_n ", ${Green}selected${NoColor}" fi color_echo done return 0 } function assert_template() { local mode=$1 if [ -n "$DIR_EXAM_TEMPLATE" ]; then return 0; fi DIR_EXAM_TEMPLATE=$(default_template) if [ "$DIR_EXAM_TEMPLATE" == "~none~" ]; then DIR_EXAM_TEMPLATE="" if [ "$mode" != "quiet" ]; then error_echo "Exam template directory not found. Check your configuration or provide a valid 't=maths' parameter."; fi return 1 fi debug "DIR_EXAM_TEMPLATE is $DIR_EXAM_TEMPLATE" return 0 } function default_template() { local t="" local template_dir="" is_set 'template' if [ $? -eq 1 ]; then t=$(get_parameter 'template'); fi is_set 't' if [ $? -eq 1 ]; then t=$(get_parameter 't'); fi if [ -z "$t" ]; then t="$DEFAULT_EXAM_TEMPLATE"; fi template_dir=$DIR_EXAM_TEMPLATES/$t if [ -h $template_dir ]; then template_dir=$(dirname $template_dir)/$(readlink $template_dir) fi if [ ! -d $template_dir ]; then template_dir="~none~" fi echo $template_dir } # EOF