#!/bin/bash

SCRNAME=`basename $(pwd)`

screen -wipe $SCRNAME > /dev/null 2>&1

SCR=`screen -ls | grep "^\s" | grep "\.\$SCRNAME\s"`;

if [ "$SCR" != "" ]; then
    if [ "$1" = "--smooth" ]; then
        screen -S $SCRNAME -p 0 -X eval 'stuff "stop smooth\r"';
        echo "Гладкая остановка через /stop smooth";
    else
        screen -S $SCRNAME -p 0 -X eval 'stuff "stop 0\r"';
        echo "Мягкая остановка через /stop...";
    fi
fi

echo "Сервер $SCRNAME остановлен";
