Skip to content
Extraits de code Groupes Projets
Valider 3cff0da2 rédigé par Miryuni's avatar Miryuni
Parcourir les fichiers

Added check test on homeserver and token

parent 7df02c4f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -32,22 +32,72 @@ if test $# -lt 3 ; then ...@@ -32,22 +32,72 @@ if test $# -lt 3 ; then
exit 1 exit 1
fi fi
for i in "$@" # Display usage funtion
do display_usage (){
if [ -d "$i" ]; then echo -e "\nUsage : ./matrixpack.sh token homeserver directory\n"
}
# Changing directory to work directly in it # Erase http:// or https:// if added in the homeserver
cd "$i" slug_homeserver() {
echo "$1" | iconv -c -t ascii//TRANSLIT | sed -E 's/^http:\/\/|^https:\/\///g' | sed -E 's/^-+|-+$//g'
}
# Checking params
if test $# -lt 3 ; then
echo 1>&2 "$0:FATAL: invalid argument number (expected 3)"
display_usage
exit 1
fi
# Checking if ImageMagick is installed
if ! command -v convert &> /dev/null && ! command -v montage &> /dev/null; then
echo "$0:ERROR: ImageMagick could not be found"
exit
fi
# Setting variables # Setting variables
dir=$(pwd) dir=$(pwd)
token=$1 token=$1
packname=${dir##*/} packname=${dir##*/}
slug=$(slugify "$packname") slug=$(slugify "$packname")
homeserver=$2 homeserver=$(slug_homeserver $2)
# Checking if the homeserver exist
curl "https://$homeserver" -I -o headers -s
if test -f "headers"; then
rm headers
else
echo 1>&2 "$0:FATAL: The homeserver \"$2\" is not correct."
exit 1
fi
# Checking if the token exist
curl -s -X POST "https://$homeserver/_matrix/media/r0/upload?access_token=$token" | python3 -c "import sys, json; print(json.load(sys.stdin)['errcode'])" >> headers
while read line; do
if [[ ($line == "M_UNKNOWN") ]]
then
rm headers
else if [[ ($line == "M_UNKNOWN_TOKEN") ]]
then
echo "$0:ERROR: The token provided does not exist"
rm headers
exit 1
else
echo "$0:ERROR: Not yet implemented error"
exit 1
fi
fi
done < headers
for i in "$@"
do
if [ -d "$i" ]; then
# Changing directory to work directly in it
cd "$i"
# Printing informations # Printing informations
echo -e "Creating sticker pack \033[94;1m$packname\033[0m\nhomeserver=\033[94m$homeserver\033[0m\noutput=\033[94m$slug\033[0m" echo -e "Creating sticker pack : \033[94;1m$packname\033[0m\nhomeserver=\033[94m$homeserver\033[0m\noutput=\033[94m$slug\033[0m"
# Making result folder # Making result folder
if ! [ -d $slug ]; then mkdir $slug; fi if ! [ -d $slug ]; then mkdir $slug; fi
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter