#!/bin/bash
# vbox-guestadditions
#
# Copyright (C) 2021 PCLinuxOS
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#
# define dialog title, icon, etc.
#=================================================
WICON='/usr/share/pixmaps/guestadditions.png'
TITLE="Virtualbox Guest Additions installer"
ZEN2="/usr/bin/zenity --no-wrap --width=450 --window-icon="$WICON

# test if we are root
if [ "$UID" != "0" ]; then
  MSG="Please run this script as root. \n\nExiting..."
  $ZEN2 --title="$TITLE" --error --text "$MSG"
  exit 0
fi

# test if we are running in VBox, if not exit
  Vname=$(cat /sys/class/dmi/id/product_name)
  if [ "$Vname" != "VirtualBox" ]; then
  MSG="This script can only be run from within Virtualbox. \n\nExiting..."
  $ZEN2 --title="$TITLE" --error --text "$MSG"
  exit 0
fi

# ok, we are set, now do the installation
MSG="Attempting to install Virtualbox Guest additions."
$ZEN2 --title="$TITLE" --timeout=5 --info --text "$MSG"
xterm -e /usr/bin/VBoxLinuxAdditions.run

MSG="The Guest additions have been installed successfully."
$ZEN2 --title="$TITLE" --timeout=10 --info --text "$MSG"

exit 0
