#!/bin/bash ################ ### ¡CONFIGURE TO YOUR NEEDS! SOLR_COLLECTION_NAME=collection1 ################ function get_mocked_deletion () { curl 'http://localhost:8090/IndexDeletion_p.html' --compressed -H 'Referer: http://localhost:8090/IndexDeletion_p.html' -H 'Content-Type: multipart/form-data; boundary=---------------------------22910066061661682999626311430' -H 'Origin: http://localhost:8090' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache' -H 'TE: Trailers' --data-binary $'-----------------------------22910066061661682999626311430\r\nContent-Disposition: form-data; name="transactionToken"\r\n\r\n'$2$'\r\n-----------------------------22910066061661682999626311430\r\nContent-Disposition: form-data; name="core"\r\n\r\n'$SOLR_COLLECTION_NAME$'\r\n-----------------------------22910066061661682999626311430\r\nContent-Disposition: form-data; name="querydelete"\r\n\r\nlanguage_s:'$1$'\r\n-----------------------------22910066061661682999626311430\r\nContent-Disposition: form-data; name="simulate-querydelete"\r\n\r\nSimulate Deletion\r\n-----------------------------22910066061661682999626311430--\r\n' 2>/dev/null | grep -i 'documents for deletion' | grep -io 'value=".*"' | cut -f2 -d'"' | tr -d '\r' } function do_real_deletion () { curl 'http://localhost:8090/IndexDeletion_p.html' --compressed -H 'Content-Type: multipart/form-data; boundary=---------------------------31292104144215932753409498446' --data-binary $'-----------------------------31292104144215932753409498446\r\nContent-Disposition: form-data; name="transactionToken"\r\n\r\n'$2$'\r\n-----------------------------31292104144215932753409498446\r\nContent-Disposition: form-data; name="core"\r\n\r\n'$SOLR_COLLECTION_NAME$'\r\n-----------------------------31292104144215932753409498446\r\nContent-Disposition: form-data; name="querydelete"\r\n\r\nlanguage_s:'$1$'\r\n-----------------------------31292104144215932753409498446\r\nContent-Disposition: form-data; name="engage-querydelete"\r\n\r\nEngage Deletion\r\n-----------------------------31292104144215932753409498446\r\nContent-Disposition: form-data; name="count"\r\n\r\n'$3$'\r\n-----------------------------31292104144215932753409498446--\r\n' >/dev/null 2>&1 | tr -d '\r' if [ "$?" == 0 ]; then echo 'I| done!' echo echo '---- SUMMARY ----' echo 'I| solr query : q=language_s:'$1 echo 'I| items purged : '$3 else echo 'E| CURL failed on deleting documents' exit 3 fi } function get_transaction_token () { curl -I -L 'http://localhost:8090/IndexDeletion_p.html' 2>/dev/null | grep -i X-YaCy-Transaction-Token | awk '{print $2}' | tr -d '\r' } if [[ "$1" == '' ]]; then echo 'E| you must specify the pattern to delete' exit 1 fi echo 'I| getting transaction token...' TOKEN=`get_transaction_token` if [[ "$TOKEN" == '' ]]; then echo echo 'E| could not obtain the TOKEN from YaCy server, permissions problem maybe?' exit 2 fi echo 'I| token: '$TOKEN echo 'I| probing pattern for deletion...' DCOUNT=`get_mocked_deletion "$1" $TOKEN` if [[ "$DCOUNT" == '' ]]; then echo echo 'W| the given pattern did return 0 documents' exit 2 fi confirm=y if [[ "$2" == 'noconfirm' ]]; then echo 'I| confirmation skipped by "noconfirm" option' else echo echo '---- CONFIRMATION ----' read -p '* * engage deletion for '$DCOUNT' documents? (y/N): ' confirm fi echo if [[ "$confirm" == 'Y' || "$confirm" == 'y' ]]; then echo 'I| issuing real documents deletion...' do_real_deletion "$1" $TOKEN $DCOUNT else echo 'X| cowardly refusing to delete '$DCOUNT' documents' exit 0 echo not confirm fi