#/bin/bash function action_list() { # Check workspace assert_workspace; if [ $? -eq 1 ]; then return 1; fi # List exams verbose "List of exams in current workspace:" for exam in $(find $DIR_WORKSPACE/$DIR_EXAMS -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sort); do color_echo "$exam" done # Done return 0 } function get_exam_list() { assert_workspace "quiet"; if [ $? -eq 1 ]; then return 1; fi find $DIR_WORKSPACE/$DIR_EXAMS -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sort } function action_add-exam() { # Check workspace assert_workspace; if [ $? -eq 1 ]; then return 1; fi # Set source DIR_EXAM=$DIR_WORKSPACE_TEMPLATE/$DIR_EXAMS/skel if [ ! -d $DIR_EXAM ]; then error_echo "Directory '$DIR_EXAM' not found." return 1 fi is_set 'exam' if [ $? -eq 1 ]; then DESTINATION=$(get_parameter 'exam'); fi is_set 'e' if [ $? -eq 1 ]; then DESTINATION=$(get_parameter 'e'); fi if [ -z "$DESTINATION" ]; then error_echo "No exam name provided. Add parameter 'exam=exam-name' to your command line. ('$ bamc add-exam -p exam=exam_name')"; return 1; fi # Set destination DESTINATION=$DIR_WORKSPACE/$DIR_EXAMS/$DESTINATION if [ -d $DESTINATION ]; then warn "This exam already exists!" confirm "Do you want to write in existing exam '$(basename $DESTINATION)' ?" if [ $? -eq 0 ]; then return 1; fi fi # Copy color_echo_n "Creating new exam '$(basename $DESTINATION)' from '$DIR_EXAM'... " cp -rp $DIR_EXAM $DESTINATION check_rc_echo $? return $? } function assert_exam() { # Check workspace assert_workspace; if [ $? -eq 1 ]; then return 1; fi local exam=$1 local mode=$2 if [ ! -d $DIR_WORKSPACE/$DIR_EXAMS/$exam ]; then if [ "$mode" != "quiet" ]; then error_echo "This exam does not exists: '$exam'. Please check the list of exams in this workspace using the 'list' action."; fi return 1 fi return 0 } function get_exam_parameter() { cat $DIR_WORKSPACE/$DIR_EXAMS/$1/$FILE_EXAM | grep "^$2:" | cut -d ':' -f 2- } function get_lang() { get_exam_parameter $1 'LANG' } # EOF