#!/bin/bash

. gettext.sh
export TEXTDOMAIN="bumblebee-add-groups"

if [[ `id -u` -ne 0 ]]; then
    for group in bumblebee; do
	if ! groups $USER | grep -q " : .*\bbumblebee\b"; then
	    missing_groups="bumblebee"
	fi
    done
    
    if [[ -n $missing_groups ]] && zenity --title="$(eval_gettext 'Bumblebee groups check')" --window-icon=/usr/share/icons/hicolor/16x16/apps/arduino.png --question --text "$(eval_gettext 'You need to be a member of the following groups to start bumblebee: $missing_groups')" --ok-label="$(eval_gettext 'Add')" --cancel-label="$(eval_gettext 'Ignore')"; then
	pkexec /usr/bin/bumblebee-add-groups \
	    && zenity --title="$(gettext 'Bumblebee groups check')" --window-icon=/usr/share/icons/hicolor/16x16/apps/arduino.png --info --text "$(eval_gettext 'You must restart you system before any changes will take effect.')"
    fi
fi

/usr/bin/optirun-bin $@
