notificaciones-comentarios.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. # Modificar
  3. ## Archivo del sqlite - sqlite's file
  4. db="/var/lib/isso/comments.db"
  5. ## JID de XMPP a notificar - XMPP JID to notify
  6. jid=""
  7. ## Directorio en el que guardar algunos archivos necesarios - Directory in which to save some needed files
  8. dir="~/.comentarios/"
  9. ## Nombre del dominio - Domain name
  10. web=""
  11. cd "$dir"
  12. # Si existe el fichero...
  13. if [[ -e "comentarios" ]];
  14. then
  15. # Volcar los comentarios
  16. sqlite3 -line $db "select * from threads;" > comentarios_temporal
  17. # Controlar si se han borrado comentarios, remediarlo y salir
  18. if [[ $(wc -l comentarios_temporal | cut -d' ' -f1) -lt $(wc -l comentarios | cut -d' ' -f1) ]];
  19. then
  20. cp comentarios_temporal comentarios
  21. exit 1
  22. fi
  23. # Comprobar si hay diferencias y enviar los nuevos
  24. ids=$(diff comentarios comentarios_temporal | grep ">"| grep tid | cut -d'=' -f2 | sed "s/ //")
  25. if [[ -n "$ids" ]]; # Si la variable no está vacía...
  26. then
  27. for id in `echo $ids`;
  28. do
  29. echo "Nuevo comentario en: " > mensaje
  30. sqlite3 -line $db "select title from threads where id = $id;" | grep title | cut -d'=' -f2 | sed "s/ //" | sed "s/+/ /g" >> mensaje
  31. echo "$web$(sqlite3 -line $db "select uri from threads where id = $id;" | cut -d'=' -f2 | sed 's/ //')" >> mensaje
  32. torify /usr/local/bin/sendxmpp mensaje $jid
  33. done
  34. cp comentarios_temporal comentarios
  35. fi
  36. else
  37. sqlite3 -line $db "select * from threads;" > comentarios
  38. fi