#!/bin/sh

systemctl stop vgserver

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

mkdir -p /opt/VideoGrace/Server/doc
mkdir -p /opt/VideoGrace/Server/content

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/doc/* /opt/VideoGrace/Server/doc/
if [ -d "$DISTRPATH/vgserver/content" ]; then
    rm -rf /opt/VideoGrace/Server/content/*
    cp -R $DISTRPATH/vgserver/content/. /opt/VideoGrace/Server/content/
fi
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"
