#!/bin/bash
echo "execute post uninstall script"
GREEN='\033[32m'
NC="\033[0m"

if [ "$1" -eq 0 ] 2>/dev/null || [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
    clean_script="/var/lib/oceanbase/seekdb_clean.sh"

    # Ensure the directory exists
    mkdir -p /var/lib/oceanbase

    # Create the clean script file if it doesn't exist
    if [ ! -f "$clean_script" ]; then
        echo "#!/bin/bash" > "$clean_script"
        echo "# SeekDB cleanup script" >> "$clean_script"
        echo "# This script will clean all SeekDB configuration and data files" >> "$clean_script"
    fi

    echo "rm -rf /var/lib/oceanbase" >> "$clean_script"
    echo "echo OK" >> "$clean_script"

    # Make the script executable
    chmod +x "$clean_script"

    echo "Clean seekdb script can clean all configuration files and all data files."
    echo -e "${GREEN}To clean SeekDB${NC} : bash /var/lib/oceanbase/seekdb_clean.sh"
fi
