From 73afd8124f34b32f965a34739f35bb4aa2d77459 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Thu, 8 Dec 2016 12:00:53 +0100 Subject: [PATCH] WIP merge big splitted files before import --- admin/fill_exercices.sh | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/admin/fill_exercices.sh b/admin/fill_exercices.sh index 797c1352..6fd77cbe 100755 --- a/admin/fill_exercices.sh +++ b/admin/fill_exercices.sh @@ -3,7 +3,7 @@ BASEURL="http://localhost:8081/admin" BASEURI="https://owncloud.srs.epita.fr/remote.php/webdav/FIC 2017" BASEFILE="/mnt/fic/" -CLOUDPASS=fic:'f>t\nV33R|(+?$i*' +CLOUDPASS=nemunaire:'p0WJ$&I#OWEtC5UI4@dD' new_theme() { NAME=`echo $1 | sed 's/"/\\\\"/g'` @@ -29,9 +29,18 @@ new_file() { THEME="$1" EXERCICE="$2" URI="$3" + shift 3 + + PARTS= + while [ -z "$1" ] + do + [ -z "${PARTS}" ] && PARTS="[" || PARTS="${PARTS}," + PARTS="${PARTS}\"$1\"" + done + PARTS="${PARTS}]" # curl -f -s -d "{\"URI\": \"${BASEFILE}${URI}\"}" "${BASEURL}/api/themes/$THEME/$EXERCICE/files" | - curl -f -s -d "{\"path\": \"${BASEFILE}${URI}\"}" "${BASEURL}/api/themes/$THEME/$EXERCICE/files" | + curl -f -s -d "{\"path\": \"${BASEFILE}${URI}\", \"parts\": ${PARTS}}" "${BASEURL}/api/themes/$THEME/$EXERCICE/files" | grep -Eo '"id":[0-9]+,' | grep -Eo "[0-9]+" } @@ -140,8 +149,27 @@ do done - # Files - get_dir "${THM_BASEURI}${EXO_BASEURI}files/" | grep -v DIGESTS.txt | while read f; do basename "$f"; done | while read FILE_URI + # Files: splited + + get_dir "${THM_BASEURI}${EXO_BASEURI}files/" | grep -v DIGESTS.txt | grep '[0-9][0-9]$' | sed -E 's/\.?([0-9][0-9])$//' | sort | uniq | while read f; do basename "$f"; done | while read FILE_URI + do + PARTS= + for part in $(ls | grep "${FILE_URI}" | sort) + do + PARTS="${PARTS} '${THM_BASEURI}${EXO_BASEURI}files/${part}'" + done + echo "Import splited file ${THM_BASEURI}${EXO_BASEURI}files/${FILE_URI} from ${PART}" + + FILE_ID=`new_file "${THEME_ID}" "${EXO_ID}" "${THM_BASEURI}${EXO_BASEURI}files/${FILE_URI}" ${PARTS}` + 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:\e[00m $FILE_ID - $FILE_URI" + fi + done + + # Files: entire + get_dir "${THM_BASEURI}${EXO_BASEURI}files/" | grep -v DIGESTS.txt | grep -v '[0-9][0-9]$' | while read f; do basename "$f"; done | while read FILE_URI do echo "Import file ${THM_BASEURI}${EXO_BASEURI}files/${FILE_URI}" FILE_ID=`new_file "${THEME_ID}" "${EXO_ID}" "${THM_BASEURI}${EXO_BASEURI}files/${FILE_URI}"`