#!/bin/bash

# WebSocket SSH Tools Clean Script
# Clean script for removing build artifacts from WebSocket SSH tools
#
# Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

# Remove PyInstaller build artifacts
rm -rf build/
rm -rf dist/
rm -f *.spec

# Remove C version build artifacts
if [ -d "wssshtools" ]; then
    cd wssshtools
    make clean 2>/dev/null || true
    rm -f Makefile
    rm -f configure.sh.stamp
    rm -f man/*.1.gz 2>/dev/null || true
    cd ..
fi

# Remove Debian packaging artifacts
# wsssh-server packages
rm -f dist/wsssh-server*.deb
rm -f dist/wsssh-server*.dsc
rm -f dist/wsssh-server*.tar.gz
rm -f dist/wsssh-server*.changes
rm -f dist/wsssh-server*.buildinfo
rm -f wsssh-server*.deb
rm -f wsssh-server*.dsc
rm -f wsssh-server*.tar.gz
rm -f wsssh-server*.changes
rm -f wsssh-server*.buildinfo

# wsssh-tools packages
rm -f dist/wsssh-tools*.deb
rm -f dist/wsssh-tools*.dsc
rm -f dist/wsssh-tools*.tar.gz
rm -f dist/wsssh-tools*.changes
rm -f dist/wsssh-tools*.buildinfo
rm -f wsssh-tools*.deb
rm -f wsssh-tools*.dsc
rm -f wsssh-tools*.tar.gz
rm -f wsssh-tools*.changes
rm -f wsssh-tools*.buildinfo

# Remove Debian build directory and artifacts
if [ -d "wsssh-server" ]; then
    rm -rf wsssh-server/debian/wsssh-server/
    rm -f wsssh-server/debian/files
    rm -f wsssh-server/debian/*.debhelper*
    rm -f wsssh-server/debian/*.substvars
    rm -f wsssh-server/debian/debhelper-build-stamp
fi

if [ -d "wssshtools" ]; then
    rm -rf wssshtools/debian/wsssh-tools/
    rm -f wssshtools/debian/files
    rm -f wssshtools/debian/*.debhelper*
    rm -f wssshtools/debian/*.substvars
    rm -f wssshtools/debian/debhelper-build-stamp
fi

# Optionally remove SSL certificates (uncomment if needed)
# rm -f cert.pem key.pem

echo "Clean complete. Build artifacts removed."
echo "Note: SSL certificates (cert.pem, key.pem) preserved. Uncomment lines in clean.sh to remove them."