#!/bin/sh

LANGCODE="${LANG%%_*}"
LANGCODE="${LANGCODE%%.*}"
LANGCODE="${LANGCODE%%@*}"

MAYBE_PKGS="language-support-$LANGCODE language-pack-$LANGCODE language-pack-gnome-$LANGCODE language-pack-kde-$LANGCODE"
PKGS=""

# Make sure the packages are in the apt cache.  If we try to install one that
# isn't, the apt-get line will fail.  So we filter here.
for pkg in $MAYBE_PKGS; do
  # It would be nice if apt-cache returned an error code, but this will do
  if [ "`apt-cache search "^$pkg$"`" != "" ]; then
    PKGS="$PKGS $pkg"
  fi
done

apt-get install -y --force-yes --ignore-missing $PKGS

mv /etc/apt/sources.list.bak /etc/apt/sources.list
rm -rf /archive

exit 0
