#!/bin/sh
set -e

case "$1" in
    remove)
        # Remove logs
        rm -rf /var/log/elasticsearch
        
        # remove **only** empty data dir
        rmdir -p --ignore-fail-on-non-empty /var/lib/elasticsearch
    ;;

    purge)
    	# Remove service
        update-rc.d elasticsearch remove >/dev/null || true
    
        # Remove logs and data
        rm -rf /var/log/elasticsearch /var/lib/elasticsearch

        # Remove user/group
        deluser elasticsearch || true
        delgroup elasticsearch || true
    ;;

    upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
        # Nothing to do here
    ;;

    *)
        echo "$0 called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac
