#!/bin/bash

# localization
. gettext.sh
export TEXTDOMAINDIR=/usr/share/locale
export TEXTDOMAIN="astra-video-driver-restore"

BACKUP_PATH=/usr/share/fly-admin-video-driver
XORG_CONF_D=/etc/X11/xorg.conf.d

if [ x"$EUID" != "x0" ]; then
    gettext "Please run this script as root or using sudo"; echo
    exit 1
fi

# clear custom configurations, if available
if find $XORG_CONF_D -mindepth 1 -maxdepth 1 | read; then
   rm -r $XORG_CONF_D/*
   gettext "Removed configs in "; echo $XORG_CONF_D;
fi

# check backup exists
if [ ! -d "$BACKUP_PATH" ]; then
  gettext "The backup directory is missing. The graphics driver changes were probably not made through fly-admin-video-driver"; echo
  exit 1
fi

set -e

cp -rf $BACKUP_PATH/xorg.conf.d /etc/X11
cp -rf $BACKUP_PATH/modprobe.d /etc

gettext "Backup completed successfully, please reboot system"; echo
