#!/bin/bash
########################################################################
# Gidenyol Bilisim - yesilsaha.net
# TEST MODU - Record interval 2 dakikaya (120s) düşürür
# Kullanim: bash test_mod.sh
########################################################################

OK='\033[0;32m'
WA='\033[1;33m'
NC='\033[0m'

NGINX_CONF="/usr/local/nginx/conf/nginx.conf"

clear
echo "################################################################"
echo "#   TEST MODU - Record interval 2 dakikaya indiriliyor        #"
echo "################################################################"
echo ""

# Config var mi?
if [ ! -f "$NGINX_CONF" ]; then
    printf "\033[0;31m[HATA] $NGINX_CONF bulunamadi!\033[0m\n"
    exit 1
fi

# Yedek al
cp "$NGINX_CONF" "${NGINX_CONF}.orijinal"
printf "${OK}[OK] Yedek alindi: ${NGINX_CONF}.orijinal${NC}\n"

# Tum record_interval degerlerini 120s yap
sed -i 's/record_interval [0-9]*s;/record_interval 120s;/g' "$NGINX_CONF"
printf "${OK}[OK] Tum kameralar -> record_interval 120s (2 dakika)${NC}\n"

# Nginx yeniden baslat
systemctl restart nginx 2>/dev/null || service nginx restart 2>/dev/null
printf "${OK}[OK] Nginx yeniden baslatildi${NC}\n"

# donustur.sh'deki kucuk dosya silme satirini devre disi birak
# (test videolari kucuk oldugundan rsync oncesi silinirdi)
for DPATH in /metmar/donustur.sh /gidenyol/donustur.sh; do
    if [ -f "$DPATH" ]; then
        sed -i 's|^\(find /usr/local/nginx/html/mp4/.*-delete\)|#TEST_DISABLED# \1|g' "$DPATH"
        printf "${OK}[OK] $DPATH kucuk dosya silme devre disi${NC}\n"
    fi
done

echo ""
printf "${WA}  Test modunda! Her 2 dakikada bir video kesilip gonderilecek.${NC}\n"
printf "${WA}  Geri almak icin: bash eski_hale_al.sh${NC}\n"
echo ""
