#!/bin/sh
###########################################################################
# Installs some package lists on the server.
#
# Copyright (C) 2010 Alkis Georgopoulos <alkisg@gmail.com>
#
# 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 3 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.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# On Debian GNU/Linux systems, the complete text of the GNU General
# Public License can be found in `/usr/share/common-licenses/GPL'.
###########################################################################

# Source the sch-scripts common functions and variables.
if [ ! -f ./scripts/common/common.sh ]; then
    cd /usr/share/sch-scripts
fi
. ./scripts/common/common.sh

PACKAGE_LISTS="$@"
APT_GET_OPTS="--yes"

confirm "Πρόκειται να εγκατασταθούν οι παρακάτω λίστες προγραμμάτων:
  $PACKAGE_LISTS
Θέλετε σίγουρα να προχωρήσετε [Y/N]; "

apt-get update
for list in $PACKAGE_LISTS; do
    if [ ! -f "$list" ]; then
        die "ERROR: Package list file '$list' does not exist."
    fi
    # Sanitize the list, removing comments and commas.
    packages=$(sed -e 's/#.*//g' -e 's/,//g' "$list")
    # Consolidate spaces.
    packages=$(echo $packages)
    echo "Installing package list '$list'"

    if ! apt-get $APT_GET_OPTS install $packages; then
        die "ERROR while installing package list $list."
    fi
done
