76 lines
3.5 KiB
Bash
76 lines
3.5 KiB
Bash
|
#!/bin/sh
|
||
|
|
||
|
################
|
||
|
### ¡CONFIGURE TO YOUR NEEDS!
|
||
|
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'"'
|
||
|
}
|
||
|
|
||
|
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
|
||
|
|
||
|
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
|
||
|
}
|
||
|
|
||
|
get_transaction_token () {
|
||
|
curl -I -L 'http://localhost:8090/IndexDeletion_p.html' 2>/dev/null | grep -i X-YaCy-Transaction-Token | awk '{print $2}'
|
||
|
}
|
||
|
|
||
|
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
|