#!/bin/sh
#VESAme - Shell script to select system resolution

Op=`alert --warn "Do you want to change your system resolution?" "Yes" "No"`
if [ "$Op" = "No" ]
	then exit
fi

#Select kind of resolution screen:
#It's splitted into two blocs (Low and High) because the alert command only accepts 3 parametres

SelectRes=`alert --info "What kind of resolution do you want to try?

Low Resolution:
	- 640x400	
	- 640x480
	- 800x600
High Resolution:
	- 1024x768
	- 1280x1024
	- 1600x1200
" "High Resolution" "Low Resolution"`

#Select final resolution screen:
#Lets choose between 3 different resolutions depending on the previous option.

if [ "$SelectRes" = "High Resolution" ]
	then ResInfo=`alert --info "Select High Resolution:" "1600x1200" "1280x1024" "1024x768"`
		case "$ResInfo" in 
			1024x768  ) Res="1024 768";;
			1280x1024  ) Res="1280 1024";;
			1600x1200  ) Res="1600 1200";;
		esac
	else ResInfo=`alert --info "Select Low Resolution:" "640x400" "640x480" "800x600"`
		case "$ResInfo" in
			640x400 ) Res="640 400";;
			640x480 ) Res="640 480";;
			800x600 ) Res="800 600";,
		esac
fi

Depth=`alert --info "Select the color depth" "8 Bits" "16 Bits"`
if [ "$Depth" = "8 Bits" ]
	then Depth=8
	else Depth=16
fi

#File verification

VesaFile=/boot/home/config/settings/kernel/drivers/vesa
if [ -f $VesaFile ]
	then
	Over=`alert --stop "File already exists, Are you sure you want overwrite it?" "Yes" "No"`
	if [ "$Over" = "Yes" ]
		then rm $VesaFile
		else alert "No resolution changes done" "Exit" 
		exit
	fi
fi

#Writing the 'mode' sentence

VideoMode="mode $Res $Depth"
echo $VideoMode > $VesaFile


Final=`alert --info "System Resolution has been set.
Possible changes will take effect at rebooting the machine" "Reboot Now" "Later"`

if [ "$Final" = "Reboot Now" ]
	then shutdown -r
fi