#! /bin/sh -e

# Set message
MENU_COMMAND0='whiptail --title "Set UTF-8 locales(0)" --msgbox 
"In the following dialog, you will be asked to select available locales.
\n
\n- You must select at least "en_US.UTF-8" .
\n
\n- Setting corresponding traditional and UTF-8 locales as a pair is 
strongly recommended.
\n
\n    e.g. fr_FR and fr_FR.UTF-8
"
23 78'
MENU_COMMAND1='whiptail --title "Set UTF-8 locales(1)" --yesno 
"en_US.UTF-8 locale is missing.
\n
\n- You must select at least "en_US.UTF-8" .
\n
\n- Setting corresponding traditional and UTF-8 locales as a pair is 
strongly recommended.
\n
\n    e.g. fr_FR and fr_FR.UTF-8
\n
\nDo you want to reset locales?
"
23 78'
MENU_COMMAND2='whiptail --title "Set UTF-8 locales(2)" --msgbox 
"UTF-8 locale is totally missing.
\n
\n- You must select at least some "*.UTF-8" .
\n
\nYou can do this later from root shell by:
\n
\n # dpkg-reconfigure locales
"
23 78'
eval $MENU_COMMAND0
dpkg-reconfigure locales
until grep -e '^en_US\.UTF-8' /etc/locale.gen 2>/dev/null >/dev/null 
do
  if eval $MENU_COMMAND1 ; then
    dpkg-reconfigure locales
  else
    break
  fi
done
if ! grep -e '^[^#]*\.UTF-8' /etc/locale.gen 2>/dev/null >/dev/null ; then
  eval $MENU_COMMAND2
fi
