Sélectionner une révision Git
matrixpack.sh 965 o
#!/bin/bash
# usage
# matrixpack token
#
# pack name is the folder name
# sticker name is the file name
# /!\ token is sensible information
if test $# != 1 ; then
echo 1>&2 "$0:FATAL: $# invalid argument number (expected 1)"
exit 1
fi
dir=$(pwd)
token=$1
packname=${dir##*/}
echo -e "Creating sticker pack\ndir=$dir\npackname=$packname"
echo -n "{\"title\":\"$packname\",\"id\":\"$packname\",\"stickers\":[" > "$packname.json"
first=0
for f in *
do
if test $first != 1 ; then
first=1
else echo -n "," >> "$packname.json"
fi
mxc=$(curl -X POST -H "Content-Type: image/png" --data-binary "@$f" "https://serveur.d'accueil/_matrix/media/r0/upload?access_token=$token" | python3 -c "import sys, json; print(json.load(sys.stdin)['content_uri'])")
echo -n "{\"body\":\"$f\",\"info\":{\"h\":128,\"w\":128,\"thumbnail_url\":\"$mxc\"},\"msgtype\":\"m.sticker\",\"url\":\"$mxc\",\"id\":\"$f\"}" >> "$packname.json"
done
echo -n "]}" >> "$packname.json"