WIP merge big splitted files before import

This commit is contained in:
nemunaire 2016-12-08 12:00:53 +01:00 committed by Pierre-Olivier Mercier
parent 4cccf95aa8
commit 73afd8124f

View File

@ -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}"`