#!/bin/sh

systemctl stop vgserver

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

mkdir -p /opt/VideoGrace/Server/doc
mkdir -p /opt/VideoGrace/Server/template
mkdir -p /opt/VideoGrace/Server/js

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/img/* /opt/VideoGrace/Server/img/
cp $DISTRPATH/vgserver/doc/* /opt/VideoGrace/Server/doc/
cp $DISTRPATH/vgserver/template/* /opt/VideoGrace/Server/template/
cp $DISTRPATH/vgserver/js/* /opt/VideoGrace/Server/js/
cp $DISTRPATH/vgserver/locale/* /opt/VideoGrace/Server/locale/
cp $DISTRPATH/vgserver/vgserver.service /etc/systemd/system/

systemctl daemon-reload

systemctl start vgserver

echo "\033[1m\033[32mVideoGrace Server has been succefully updated\033[m"
echo "More news at: \033[1m\033[36mhttps://videograce.com\033[m \033[1m\033[31m👍\033[m"
