#!/bin/sh

docker-compose down

mkdir -p /root/dj_multictrl_data/ntp
cp ./file/ntp/ntp.conf /root/dj_multictrl_data/ntp/

mkdir -p /root/dj_multictrl_data/pgsql/data
mkdir -p /root/dj_multictrl_data/pgsql/initdb.d
cp ./file/pgsql/init.sql /root/dj_multictrl_data/pgsql/initdb.d/

mkdir -p /data/dj_multictrl_data/minio/data
mkdir -p /data/dj_multictrl_data/minio/config
mkdir -p /data/dj_multictrl_data/minio/data/source-material
cp -r ./file/source-material/* /data/dj_multictrl_data/minio/data/source-material/

mkdir -p /root/dj_multictrl_data/nginx
mkdir -p /root/dj_multictrl_data/nginx/conf.d
mkdir -p /root/dj_multictrl_data/nginx/cert
mkdir -p /root/dj_multictrl_data/nginx/html
cp ./file/nginx/nginx.conf /root/dj_multictrl_data/nginx/nginx.conf
cp -r ./file/nginx/conf.d/* /root/dj_multictrl_data/nginx/conf.d/
cp -r ./file/nginx/cert/* /root/dj_multictrl_data/nginx/cert/
cp -r ./file/nginx/html/* /root/dj_multictrl_data/nginx/html/

mkdir -p /root/dj_multictrl_data/emqx/logs
mkdir -p /root/dj_multictrl_data/emqx/data
mkdir -p /root/dj_multictrl_data/emqx/etc
cp ./file/emqx/etc/emqx.conf /root/dj_multictrl_data/emqx/etc/emqx.conf
mkdir -p /root/dj_multictrl_data/emqx2/logs
mkdir -p /root/dj_multictrl_data/emqx2/data
mkdir -p /root/dj_multictrl_data/emqx2/etc
cp ./file/emqx2/etc/emqx.conf /root/dj_multictrl_data/emqx2/etc/emqx.conf

mkdir -p /root/dj_multictrl_data/srs/conf
mkdir -p /data/dj_multictrl_data/live_record
cp ./file/srs/docker.conf /root/dj_multictrl_data/srs/conf/

mkdir -p /root/dj_multictrl_data/influxdb/data

mkdir -p /root/dj_multictrl_data/ffmpeg
cp ./file/ffmpeg/ffmpeg /root/dj_multictrl_data/ffmpeg/

mkdir -p /root/dj_multictrl_data/api
mkdir -p /root/dj_multictrl_data/api/config
mkdir -p /root/dj_multictrl_data/api/temp
mkdir -p /root/dj_multictrl_data/api/logs
mkdir -p /root/dj_multictrl_data/api/tmp
cp  ./file/api/aros-yufeng.jar /root/dj_multictrl_data/api/
cp ./file/api/conf/application.yml /root/dj_multictrl_data/api/config/application.yml
cp ./file/api/conf/application-docker.yml /root/dj_multictrl_data/api/config/application-docker.yml

mkdir -p /root/dj_multictrl_data/wait
cp ./file/wait/wait-for-it.sh /root/dj_multictrl_data/wait/wait-for-it.sh

mkdir -p /root/dj_multictrl_data/mongodb/data

mkdir -p /root/dj_multictrl_data/script
mkdir -p /root/dj_multictrl_data/script/logs
cp ./file/script/cleanup_srs_record_videos.sh /root/dj_multictrl_data/script/
chmod +x /root/dj_multictrl_data/script/cleanup_srs_record_videos.sh
crontab -l > cron.cron
echo '*/30 * * * * /root/dj_multictrl_data/script/cleanup_srs_record_videos.sh' >> cron.cron
#echo '0 2 * * * /usr/bin/docker restart aros-api-srs' >> cron.cron
#echo '0 */1 * * * /usr/bin/pkill ffmpeg' >> cron.cron
crontab cron.cron

chmod -R 777 /root/dj_multictrl_data

docker-compose --compatibility up