#!/bin/sh

SCRIPT=$(readlink -f "$0")
DISTRPATH=$(dirname "$SCRIPT")

mkdir -p /opt/VideoGrace/Server/
mkdir -p /opt/VideoGrace/Server/bin
mkdir -p /opt/VideoGrace/Server/img
mkdir -p /opt/VideoGrace/Server/template
mkdir -p /opt/VideoGrace/Server/js
mkdir -p /opt/VideoGrace/Server/db
mkdir -p /opt/VideoGrace/Server/doc
mkdir -p /opt/VideoGrace/Server/locale
cp -n $DISTRPATH/vgserver/vgserver.conf /opt/VideoGrace/Server/
cp $DISTRPATH/vgserver/VideoGraceServer /opt/VideoGrace/Server/
cp $DISTRPATH/vgserver/Consolidator /opt/VideoGrace/Server/
cp $DISTRPATH/vgserver/Recorder /opt/VideoGrace/Server/
chmod +x /opt/VideoGrace/Server/VideoGraceServer
chmod +x /opt/VideoGrace/Server/Consolidator
chmod +x /opt/VideoGrace/Server/Recorder
cp $DISTRPATH/vgserver/bin/* /opt/VideoGrace/Server/bin/
cp $DISTRPATH/vgserver/template/* /opt/VideoGrace/Server/template/
cp $DISTRPATH/vgserver/js/* /opt/VideoGrace/Server/js/
cp $DISTRPATH/vgserver/img/* /opt/VideoGrace/Server/img/
cp -n $DISTRPATH/vgserver/db/* /opt/VideoGrace/Server/db
cp $DISTRPATH/vgserver/doc/* /opt/VideoGrace/Server/doc/
cp $DISTRPATH/vgserver/locale/* /opt/VideoGrace/Server/locale/
chmod 777 /opt/VideoGrace/Server/db
chmod 777 /opt/VideoGrace/Server/db/main.db
mkdir -p /var/log/vgserver
chmod 777 /var/log/vgserver

cp $DISTRPATH/vgserver/vgserver.service /etc/systemd/system/
systemctl enable vgserver
systemctl start vgserver

echo "\033[1m\033[32mVideoGrace Server was installed and runned successfully\033[m"
echo "Check the web panel: \033[1m\033[36mhttp://localhost:8778\033[m\nDefault login and password are: \033[1m\033[31madmin / admin\033[m please change it now!"
echo "More information on the our site: \033[1m\033[36mhttps://videograce.com\033[m \033[1m\033[31m🤝\033[m"
