Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | read -r -p "Are you sure you want to reset learned hashes from Rspamd (fuzzy, bayes, neural)? [y/N] " response |
| 4 | response=${response,,} # tolower |
| 5 | if [[ "$response" =~ ^(yes|y)$ ]]; then |
| 6 | echo "Working, please wait..." |
| 7 | REDIS_ID=$(docker ps -qf name=redis-mailcow) |
| 8 | RSPAMD_ID=$(docker ps -qf name=rspamd-mailcow) |
| 9 | |
| 10 | if [ -z ${REDIS_ID} ] || [ -z ${RSPAMD_ID} ]; then |
| 11 | echo "Cannot determine Redis or Rspamd container ID" |
| 12 | exit 1 |
| 13 | else |
| 14 | echo "Stopping Rspamd container" |
| 15 | docker stop ${RSPAMD_ID} |
| 16 | echo "LUA will return nil when it succeeds or print a warning/error when it fails." |
| 17 | echo "Deleting all RS* keys - if any" |
| 18 | docker exec -it ${REDIS_ID} redis-cli EVAL "for _,k in ipairs(redis.call('keys', ARGV[1])) do redis.call('del', k) end" 0 'RS*' |
| 19 | echo "Deleting all BAYES* keys - if any" |
| 20 | docker exec -it ${REDIS_ID} redis-cli EVAL "for _,k in ipairs(redis.call('keys', ARGV[1])) do redis.call('del', k) end" 0 'BAYES*' |
| 21 | echo "Deleting all learned* keys - if any" |
| 22 | docker exec -it ${REDIS_ID} redis-cli EVAL "for _,k in ipairs(redis.call('keys', ARGV[1])) do redis.call('del', k) end" 0 'learned*' |
| 23 | echo "Deleting all fuzzy* keys - if any" |
| 24 | docker exec -it ${REDIS_ID} redis-cli EVAL "for _,k in ipairs(redis.call('keys', ARGV[1])) do redis.call('del', k) end" 0 'fuzzy*' |
| 25 | echo "Deleting all tRFANN* keys - if any" |
| 26 | docker exec -it ${REDIS_ID} redis-cli EVAL "for _,k in ipairs(redis.call('keys', ARGV[1])) do redis.call('del', k) end" 0 'tRFANN*' |
| 27 | echo "Starting Rspamd container" |
| 28 | docker start ${RSPAMD_ID} |
| 29 | fi |
| 30 | fi |