From b38973f94901dc34ae109587c1eed80014e0d8c9 Mon Sep 17 00:00:00 2001 From: Bastard Operator Date: Tue, 22 Dec 2020 00:00:20 +0100 Subject: [PATCH] Fixed purge-by-lang script --- purge-by-lang.sh | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/purge-by-lang.sh b/purge-by-lang.sh index a8b8ccf..aba8f8a 100755 --- a/purge-by-lang.sh +++ b/purge-by-lang.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash ################ ### ¡CONFIGURE TO YOUR NEEDS! @@ -7,14 +7,12 @@ SOLR_COLLECTION_NAME=collection1 -get_mocked_deletion () -{ - curl 'http://localhost:8090/IndexDeletion_p.html' --compressed -H 'Content-Type: multipart/form-data; boundary=---------------------------39511578039498704693434182866' --data-binary $'-----------------------------39511578039498704693434182866\r\nContent-Disposition: form-data; name="transactionToken"\r\n\r\n'$2$'\r\n-----------------------------39511578039498704693434182866\r\nContent-Disposition: form-data; name="core"\r\n\r\n'$SOLR_COLLECTION_NAME$'\r\n-----------------------------39511578039498704693434182866\r\nContent-Disposition: form-data; name="querydelete"\r\n\r\nlanguage_s:'$1$'\r\n-----------------------------39511578039498704693434182866\r\nContent-Disposition: form-data; name="simulate-querydelete"\r\n\r\nSimulate Deletion\r\n-----------------------------39511578039498704693434182866\r\nContent-Disposition: form-data; name="count"\r\n\r\n227\r\n-----------------------------39511578039498704693434182866--\r\n' 2>/dev/null | grep -i 'documents for deletion' | grep -io 'value=".*"' | cut -f2 -d'"' +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' } -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 +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!' @@ -28,18 +26,19 @@ do_real_deletion () fi } -get_transaction_token () { - curl -I -L 'http://localhost:8090/IndexDeletion_p.html' 2>/dev/null | grep -i X-YaCy-Transaction-Token | awk '{print $2}' +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 + +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 +if [[ "$TOKEN" == '' ]]; then echo echo 'E| could not obtain the TOKEN from YaCy server, permissions problem maybe?' exit 2 @@ -49,14 +48,14 @@ echo 'I| token: '$TOKEN echo 'I| probing pattern for deletion...' DCOUNT=`get_mocked_deletion "$1" $TOKEN` -if [ "$DCOUNT" == '' ]; then +if [[ "$DCOUNT" == '' ]]; then echo echo 'W| the given pattern did return 0 documents' exit 2 fi confirm=y -if [ "$2" == 'noconfirm' ]; then +if [[ "$2" == 'noconfirm' ]]; then echo 'I| confirmation skipped by "noconfirm" option' else echo