64 lines
3.1 KiB
Bash
64 lines
3.1 KiB
Bash
|
#!/bin/sh
|
||
|
|
||
|
get_mocked_deletion ()
|
||
|
{
|
||
|
curl 'http://localhost:8090/IndexDeletion_p.html' --compressed -H 'Content-Type: multipart/form-data; boundary=---------------------------36244091493792000931527589319' --data-binary $'-----------------------------36244091493792000931527589319\r\nContent-Disposition: form-data; name="transactionToken"\r\n\r\n'$2$'\r\n-----------------------------36244091493792000931527589319\r\nContent-Disposition: form-data; name="urldelete"\r\n\r\nhttps?:\/\/[^\/]*'$1$'.*\r\n-----------------------------36244091493792000931527589319\r\nContent-Disposition: form-data; name="urldelete-mm"\r\n\r\nregexp\r\n-----------------------------36244091493792000931527589319\r\nContent-Disposition: form-data; name="simulate-urldelete"\r\n\r\nSimulate Deletion\r\n-----------------------------36244091493792000931527589319--\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=---------------------------418460500723610169542263241681' --data-binary $'-----------------------------418460500723610169542263241681\r\nContent-Disposition: form-data; name="transactionToken"\r\n\r\n'$2$'\r\n-----------------------------418460500723610169542263241681\r\nContent-Disposition: form-data; name="urldelete"\r\n\r\nhttps?:\/\/[^\/]*'$1$'.*\r\n-----------------------------418460500723610169542263241681\r\nContent-Disposition: form-data; name="urldelete-mm"\r\n\r\nregexp\r\n-----------------------------418460500723610169542263241681\r\nContent-Disposition: form-data; name="engage-urldelete"\r\n\r\nEngage Deletion\r\n-----------------------------418460500723610169542263241681\r\nContent-Disposition: form-data; name="count"\r\n\r\n'$3$'\r\n-----------------------------418460500723610169542263241681--\r\n' >/dev/null 2>&1
|
||
|
|
||
|
if [ "$?" == 0 ]; then
|
||
|
echo 'I| done!'
|
||
|
echo
|
||
|
echo '---- SUMMARY ----'
|
||
|
echo 'I| term regex : https?:\/\/[^\/]*'$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
|
||
|
|
||
|
echo
|
||
|
echo '---- CONFIRMATION ----'
|
||
|
read -p '* * engage deletion for '$DCOUNT' documents? (y/N): ' confirm
|
||
|
|
||
|
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
|