#!/bin/sh
# Script to automate Librassoc's installation
# See http://www.bxlug.be/librassoc for more details

# TODO: - replace dselect calls by aptitude
# Authors: Jerome Warnier <jwarnier@beeznest.net>
#	 : Eric Freyens <efreyens@bxlug.be>

URL=http://apt.bxlug.be/librassoc

usage()
{
    echo "Usage: ${0##*/} [OPTION]"
    echo "librassoc automate installation."
    echo
    cat <<EOF
      --games                install games packages
      --non-free             install non-free packages
      --full                 same as --games and --non-free mode
      --help                 display this help and exit
      --verbose              verbose mode
EOF
}


if [ $# != 0 ] ; then
	while true ; do
	case "$1" in
	--help)
		usage
		exit 0
		;;
	--full)
		games=true
		nonfree=true
		shift 1
		;;
	--games)
		games=true
		shift 1
		;;
	--non-free)
		nonfree=true
		shift 1
		;;
  	--verbose)
		verbose="-v"
		shift 1
		;;
	*)
		break
		;;
	esac
	done
fi

cd /etc/apt
mv /etc/apt/sources.list /etc/apt/sources.list.old
wget $verbose $URL/sources.list
wget $verbose $URL/sources.list.apt-proxy
wget $verbose $URL/dpkg.selections
[ $games ]   && wget $verbose $URL/dpkg.selections.games
[ $nonfree ] && wget $verbose $URL/dpkg.selections.non-free

# Update the lists of available packages
dselect update

# Set the list of packages to install/remove
dpkg --set-selections < dpkg.selections
[ $games ]   && dpkg --set-selections < dpkg.selections.games
[ $nonfree ] && dpkg --set-selections < dpkg.selections.non-free

# Install some packages beforehand, as their presence will speed up the install
apt-get -y install hdparm

# Install the whole packages selection
dselect install 

if [ ! `dmesg|grep -q "^ACPI disabled because your bios is from .* and too old"`]; then
	echo "Your BIOS is too old to use ACPI"
	echo "Forcing it anyway"
	sed -i -e '/^# kopt=/s/$/ acpi=force/' $GRUB_CONF
	/sbin/update-grub
fi

if [ `grep -q "^SecureSystemMenu=true" $GDM_CONF` ]; then
	echo "Allowing to shutdown and reboot from GDM without root password"
	sed -i -e '/^SecureSystemMenu=true/SecureSystemMenu=false/' $GDM_CONF
fi

