Add color and error recovery
This commit is contained in:
parent
fa8343405b
commit
b30d109529
1 changed files with 31 additions and 12 deletions
|
|
@ -4,16 +4,16 @@ BASEURL="http://localhost:8081"
|
||||||
BASEURI="http://srs.epita.fr/owncloud/remote.php/webdav/FIC 2016"
|
BASEURI="http://srs.epita.fr/owncloud/remote.php/webdav/FIC 2016"
|
||||||
|
|
||||||
new_theme() {
|
new_theme() {
|
||||||
NAME="$1"
|
NAME=`echo $1 | sed 's/"/\\\\"/g'`
|
||||||
curl -f -s -d "{\"name\": \"$NAME\"}" "${BASEURL}/api/themes/" |
|
curl -f -s -d "{\"name\": \"$NAME\"}" "${BASEURL}/api/themes/" |
|
||||||
grep -Eo '"id":[0-9]+,' | grep -Eo "[0-9]+"
|
grep -Eo '"id":[0-9]+,' | grep -Eo "[0-9]+"
|
||||||
}
|
}
|
||||||
|
|
||||||
new_exercice() {
|
new_exercice() {
|
||||||
THEME="$1"
|
THEME="$1"
|
||||||
TITLE="$2"
|
TITLE=`echo "$2" | sed 's/"/\\\\"/g'`
|
||||||
STATEMENT="$3"
|
STATEMENT=`echo "$3" | sed 's/"/\\\\"/g'`
|
||||||
HINT="$4"
|
HINT=`echo "$4" | sed 's/"/\\\\"/g'`
|
||||||
DEPEND="$5"
|
DEPEND="$5"
|
||||||
GAIN="$6"
|
GAIN="$6"
|
||||||
VIDEO="$7"
|
VIDEO="$7"
|
||||||
|
|
@ -35,7 +35,7 @@ new_key() {
|
||||||
THEME="$1"
|
THEME="$1"
|
||||||
EXERCICE="$2"
|
EXERCICE="$2"
|
||||||
NAME="$3"
|
NAME="$3"
|
||||||
KEY="$4"
|
KEY=`echo $4 | sed 's/"/\\\\"/g'`
|
||||||
|
|
||||||
curl -f -s -d "{\"name\": \"$NAME\", \"key\": \"$KEY\"}" "${BASEURL}/api/themes/$THEME/$EXERCICE/keys" |
|
curl -f -s -d "{\"name\": \"$NAME\", \"key\": \"$KEY\"}" "${BASEURL}/api/themes/$THEME/$EXERCICE/keys" |
|
||||||
grep -Eo '"id":[0-9]+,' | grep -Eo "[0-9]+"
|
grep -Eo '"id":[0-9]+,' | grep -Eo "[0-9]+"
|
||||||
|
|
@ -49,13 +49,18 @@ do
|
||||||
fi
|
fi
|
||||||
|
|
||||||
THEME_ID=`new_theme "$THEME_NAME"`
|
THEME_ID=`new_theme "$THEME_NAME"`
|
||||||
echo ">>> New theme created: $THEME_ID - $THEME_NAME"
|
if [ -z "$THEME_ID" ]; then
|
||||||
|
echo -e "\e[31;01m!!! An error occured during theme add\e[00m"
|
||||||
|
continue
|
||||||
|
else
|
||||||
|
echo -e "\e[32m>>> New theme created:\e[00m $THEME_ID - $THEME_NAME"
|
||||||
|
fi
|
||||||
|
|
||||||
LAST=null
|
LAST=null
|
||||||
EXO_NUM=1
|
EXO_NUM=1
|
||||||
THM_BASEURI=
|
THM_BASEURI=
|
||||||
echo
|
echo
|
||||||
echo "--- Filling exercice ${EXO_NUM} in theme ${THEME_NAME}"
|
echo -e "\e[36m--- Filling exercice ${EXO_NUM} in theme ${THEME_NAME}\e[00m"
|
||||||
while read -p "Exercice title (^D to pass to the next theme) [Exercice ${EXO_NUM}]: " EXO_NAME
|
while read -p "Exercice title (^D to pass to the next theme) [Exercice ${EXO_NUM}]: " EXO_NAME
|
||||||
do
|
do
|
||||||
if [ -z "${EXO_NAME}" ]; then
|
if [ -z "${EXO_NAME}" ]; then
|
||||||
|
|
@ -92,7 +97,12 @@ do
|
||||||
read -p "Video URI: ${BASEURI}${THM_BASEURI}${EXO_BASEURI}" EXO_VIDEO
|
read -p "Video URI: ${BASEURI}${THM_BASEURI}${EXO_BASEURI}" EXO_VIDEO
|
||||||
|
|
||||||
EXO_ID=`new_exercice "${THEME_ID}" "${EXO_NAME}" "${EXO_DESC}" "${EXO_HINT}" "${LAST}" "${EXO_GAIN}" "${THM_BASEURI}${EXO_BASEURI}${EXO_VIDEO}"`
|
EXO_ID=`new_exercice "${THEME_ID}" "${EXO_NAME}" "${EXO_DESC}" "${EXO_HINT}" "${LAST}" "${EXO_GAIN}" "${THM_BASEURI}${EXO_BASEURI}${EXO_VIDEO}"`
|
||||||
echo ">>> New exercice created: $EXO_ID - $EXO_NAME"
|
if [ -z "$EXO_ID" ]; then
|
||||||
|
echo -e "\e[31;01m!!! An error occured during exercice add.\e[00m"
|
||||||
|
continue
|
||||||
|
else
|
||||||
|
echo -e "\e[32m>>> New exercice created: $EXO_ID - $EXO_NAME\e[00m"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Keys
|
# Keys
|
||||||
|
|
@ -106,7 +116,11 @@ do
|
||||||
read -p "Key type/kind/hint: " KEY_TYPE
|
read -p "Key type/kind/hint: " KEY_TYPE
|
||||||
|
|
||||||
KEY_ID=`new_key "${THEME_ID}" "${EXO_ID}" "${KEY_TYPE}" "${KEY_RAW}"`
|
KEY_ID=`new_key "${THEME_ID}" "${EXO_ID}" "${KEY_TYPE}" "${KEY_RAW}"`
|
||||||
echo ">>> New key created: $KEY_ID - $KEY_TYPE"
|
if [ -z "$KEY_ID" ]; then
|
||||||
|
echo -e "\e[31;01m!!! An error occured during key add.\e[00m"
|
||||||
|
else
|
||||||
|
echo -e "\e[32m>>> New key created: $KEY_ID - $KEY_TYPE\e[00m"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -118,14 +132,19 @@ do
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FILE_ID=`new_file "${THEME_ID}" "${EXO_ID}" "${BASEURI}${THM_BASEURI}${EXO_BASEURI}${FILE_URI}"`
|
FILE_ID=`new_file "${THEME_ID}" "${EXO_ID}" "${THM_BASEURI}${EXO_BASEURI}${FILE_URI}"`
|
||||||
echo ">>> New file added: $FILE_ID - $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"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
LAST=$EXO_ID
|
LAST=$EXO_ID
|
||||||
EXO_NUM=$((EXO_NUM + 1))
|
EXO_NUM=$((EXO_NUM + 1))
|
||||||
echo
|
echo
|
||||||
echo "--- Filling exercice ${EXO_NUM} in theme ${THEME_NAME}"
|
echo -e "\e[36m--- Filling exercice ${EXO_NUM} in theme ${THEME_NAME}\e[00m"
|
||||||
done
|
done
|
||||||
|
echo
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Reference in a new issue