#!/bin/bash


count=`dpkg -l | grep nginx- | wc -l`
if [[ $count > 0 ]]
then
    echo "remove nginx now"
    if [[ -d "/etc/nginx/" ]]
    then
        cp /etc/nginx -rf /etc/nginx_bak_rf
    fi
    dpkg --purge nginx
    apt-get remove nginx-core nginx-common -y
    dpkg --purge nginx-common
    dpkg --purge nginx-core
    if [[ `dpkg -l | grep libnginx | wc -l` > 0 ]]
    then
        apt-get remove --purge libnginx-* -y
    fi
    echo "remove nginx success"
fi

count=`dpkg -l | grep libidste-vlc-dev | wc -l`
if [[ $count > 0 ]]
then
    echo "remove libidste-vlc-dev now"
    dpkg --purge libidste-vlc-dev
    echo "remove libidste-vlc-dev success"
fi

count=`dpkg -l | grep libidste-vlc | grep -v libidste-vlc-player | wc -l`
if [[ $count > 0 ]]
then
    echo "remove libidste-vlc now"
    dpkg --purge libidste-vlc
    echo "remove libidste-vlc success"
fi

if [[ -d /var/log/mosquitto/ ]]
then
    owner=`stat -c "%U" /var/log/mosquitto/`
    if [[ ${owner} != "mosquitto" ]]
    then
        rm -rf  /var/log/mosquitto/
        echo "rm /var/log/mosquitto success"
    fi
fi

if [[ -f /var/log/mosquitto_su ]]
then
    owner=`stat -c "%U" /var/log/mosquitto_su/`
    if [[ ${owner} != "mosquitto" ]]
    then
        rm -f /var/log/mosquitto_su
        echo "rm /var/log/mosquitto_su success"
    fi
fi

count=`dpkg -l | grep vsftpd | wc -l`
if [[ $count > 0 ]]
then
    echo "remove vsftpd now"
    dpkg --purge vsftpd
    echo "remove vsftpd success"
fi


count=`dpkg -l | grep idste-srs | wc -l`
if [[ $count > 0 ]]
then
    echo "remove idste-srs now"
    dpkg --purge idste-srs
    echo "remove idste-srs success"
fi

