#!/bin/sh
set -e

if [ -d "/var/lib/ocsinventory-frontend-update" ]
then
    echo "Restore ocsinventory-frontend configuration files"
    if [ -d "/var/lib/ocsinventory-frontend-update/app" ] && [ "$(ls -A /var/lib/ocsinventory-frontend-update/app)" ]; then
        cp -r /var/lib/ocsinventory-frontend-update/app/* /usr/share/ocsinventory-frontend
    fi
    rm -rf /var/lib/ocsinventory-frontend-update
fi

echo "Create ocsinventory-frontend log folder"
mkdir -p /var/log/ocsinventory-frontend

echo "Enable ocsinventory-frontend"
ln -sf /etc/nginx/sites-available/ocsinventory-frontend /etc/nginx/sites-enabled/ocsinventory-frontend
echo "Set nginx rights on ocsinventory-frontend"
chown -R www-data: /usr/share/ocsinventory-frontend
echo "Restart nginx"
systemctl restart nginx

exit 0
