#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

BLUETOOTH=0
WWAN=0

[ "$(uname -r)" = "2.6.28.10-vaioz" ] && reboot

[ -x /etc/init.d/kdm ] && DM="service kdm start" || DM="service gdm start"

#if [ "$(uname -r)" = "2.6.35-rc6-vaioz" -o "$(uname -r)" = "2.6.35-vaioz" -o "$(uname -r)" = "2.6.36-rc3-vaioz" -o "$(uname -r)" = "2.6.36-0-vaioz" -o "$(uname -r)" = "2.6.37-6-vaioz" -o "$(uname -r)" = "2.6.38-7-generic" ]
if [ -e /sys/devices/platform/sony-laptop/speed_stamina ]
then
	if [ "$(cat /sys/devices/platform/sony-laptop/speed_stamina)" = "stamina" ]
	then
		if [ -f /etc/X11/xorg.conf ]
		then
			if grep "\<nvidia\>" /etc/X11/xorg.conf 2>/dev/null >/dev/null
			then
				[ ! -f /etc/X11/xorg.conf.nvidia ] && mv /etc/X11/xorg.conf /etc/X11/xorg.conf.nvidia || rm /etc/X11/xorg.conf
			fi
			eval $DM restart
		fi
		sleep 3
		echo 52 >/proc/acpi/video/GFX0/LCD/brightness 
	else
		[ ! -f "/etc/X11/xorg.conf" -a -f "/etc/X11/xorg.conf.nvidia" ] && cp /etc/X11/xorg.conf.nvidia /etc/X11/xorg.conf && eval $DM restart
	fi
fi

for i in /sys/class/rfkill/*
do
	grep bluetooth $i/name 2>/dev/null >/dev/null && echo $BLUETOOTH >$i/state
	grep wwan $i/name 2>/dev/null >/dev/null && echo $WWAN >$i/state
done


exit 0
