diff --git a/admin/fill_exercices.sh b/admin/fill_exercices.sh
index 6e49b635..4b8227da 100755
--- a/admin/fill_exercices.sh
+++ b/admin/fill_exercices.sh
@@ -1,7 +1,8 @@
#!/bin/sh
BASEURL="http://localhost:8081"
-BASEURI="http://srs.epita.fr/owncloud/remote.php/webdav/FIC 2016"
+BASEURI="https://srs.epita.fr/owncloud/remote.php/webdav/FIC 2016"
+CLOUDPASS=fic:'f>t\nV33R|(+?$i*'
new_theme() {
NAME=`echo $1 | sed 's/"/\\\\"/g'`
@@ -12,8 +13,8 @@ new_theme() {
new_exercice() {
THEME="$1"
TITLE=`echo "$2" | sed 's/"/\\\\"/g'`
- STATEMENT=`echo "$3" | sed 's/"/\\\\"/g'`
- HINT=`echo "$4" | sed 's/"/\\\\"/g'`
+ STATEMENT=`echo "$3" | sed 's/"/\\\\"/g' | sed ':a;N;$!ba;s/\n/
/g'`
+ HINT=`echo "$4" | sed 's/"/\\\\"/g' | sed ':a;N;$!ba;s/\n/
/g'`
DEPEND="$5"
GAIN="$6"
VIDEO="$7"
@@ -67,20 +68,6 @@ do
EXO_NAME="Exercice ${EXO_NUM}"
fi
- if [ "${LAST}" = "null" ]; then
- echo ">>> Assuming this exercice has no dependency"
- else
- echo ">>> Assuming this exercice depends on the last entry (id=${LAST})"
- fi
-
- EXO_GAIN=$((5 ** $EXO_NUM))
- echo ">>> Using default gain: ${EXO_GAIN} points"
-
- echo "--- Enter the description for ${EXO_NUM} in theme ${THEME_NAME}"
- EXO_DESC=`cat`
-
- echo "--- Enter the optional hint for ${EXO_NUM} in theme ${THEME_NAME}"
- EXO_HINT=`cat`
if [ -z "${THM_BASEURI}" ]
then
@@ -94,7 +81,39 @@ do
EXO_BASEURI="${EXO_NAME}/"
fi
- read -p "Video URI: ${BASEURI}${THM_BASEURI}${EXO_BASEURI}" EXO_VIDEO
+ FILES=$(curl -f -s -X PROPFIND -u "${CLOUDPASS}" "${BASEURI}${THM_BASEURI}${EXO_BASEURI}" | xmllint --format - | grep 'd:href' | sed -E 's/^.*>(.*)<.*$/\1/' | sed 1d | while read f; do basename $f; done)
+
+ DEF_VIDEO=$(echo "$FILES" | grep -E "\.(mov|mkv|mp4|avi)$" | head -1)
+
+ read -p "Video URI [${DEF_VIDEO}]: ${BASEURI}${THM_BASEURI}${EXO_BASEURI}" EXO_VIDEO
+ if [ -z "${EXO_VIDEO}" ]; then
+ EXO_VIDEO="$DEF_VIDEO"
+ fi
+
+ README=$(echo "$FILES" | grep -iE "readme" | head -1)
+ if ! [ -z "$README" ]; then
+ echo
+ echo "################################# $README #################################"
+ curl -f -u "${CLOUDPASS}" "${BASEURI}${THM_BASEURI}${EXO_BASEURI}/${README}"
+ echo
+ echo "###########################################################################"
+ echo
+ fi
+
+ if [ "${LAST}" = "null" ]; then
+ echo ">>> Assuming this exercice has no dependency"
+ else
+ echo ">>> Assuming this exercice depends on the last entry (id=${LAST})"
+ fi
+
+ EXO_GAIN=$((5 * (2 ** $EXO_NUM)))
+ echo ">>> Using default gain: ${EXO_GAIN} points"
+
+ echo "--- Enter the description for ${EXO_NUM} in theme ${THEME_NAME}"
+ EXO_DESC=`cat`
+
+ echo "--- Enter the optional hint for ${EXO_NUM} in theme ${THEME_NAME}"
+ EXO_HINT=`cat`
EXO_ID=`new_exercice "${THEME_ID}" "${EXO_NAME}" "${EXO_DESC}" "${EXO_HINT}" "${LAST}" "${EXO_GAIN}" "${THM_BASEURI}${EXO_BASEURI}${EXO_VIDEO}"`
if [ -z "$EXO_ID" ]; then
@@ -125,18 +144,16 @@ do
# Files
- while read -p "Import file ${BASEURI}${THM_BASEURI}${EXO_BASEURI}" FILE_URI
+ for FBASE in $(for f in $FILES; do echo $f; done | grep -vEi "(readme|${EXO_VIDEO})")
do
- if [ -z "${FILE_URI}" ]
+ if read -p "Import file ${BASEURI}${THM_BASEURI}${EXO_BASEURI}${FBASE}? (Enter: yes, ^D: no)"
then
- break
- fi
-
- FILE_ID=`new_file "${THEME_ID}" "${EXO_ID}" "${THM_BASEURI}${EXO_BASEURI}${FILE_URI}"`
- if [ -z "$FILE_ID" ]; then
- echo -e "\e[31;01m!!! An error occured during file import! Please check path.\e[00m"
- else
- echo -e "\e[32m>>> New file added: $FILE_ID - $FILE_URI\e[00m"
+ FILE_ID=`new_file "${THEME_ID}" "${EXO_ID}" "${THM_BASEURI}${EXO_BASEURI}${FBASE}"`
+ if [ -z "$FILE_ID" ]; then
+ echo -e "\e[31;01m!!! An error occured during file import! Please check path.\e[00m"
+ else
+ echo -e "\e[32m>>> New file added: $FILE_ID - $FBASE\e[00m"
+ fi
fi
done