#!/bin/sh
set -e

# The client's files live in meshbay-common's venv, whose own cleanup runs only
# after this package is gone: the bytecode compiled next to them is removed
# here, or dpkg cannot remove the directories it sits in.
case "$1" in
    remove|upgrade|deconfigure)
        site=$(echo /opt/meshbay-common/venv/lib/python3.*/site-packages)
        while IFS= read -r entry; do
            [ -n "$entry" ] && [ -d "$site/$entry" ] || continue
            find "$site/$entry" -depth -type d -name __pycache__ \
                -exec rm -rf {} + 2>/dev/null || true
        done < /opt/meshbay-cli/site-packages.list
        ;;
esac

#DEBHELPER#
