#!/bin/bash
# Under the terms of the 'COPYRIGHT.TXT' file.

# Chequeo de sanidad:
[[ ! -x /mnt/usr/bin/locale ]] && exit;

# Crea el men para luego conformarlo:
cat << EOF > ${TMP}/show_locales
dialog \\
 --backtitle "Selection of locales" \\
 --title "LOCALIZATION" \\
 --default-item "en_US" \\
 --menu \\
"Select the locale that you want:" 20 37 13 \\
EOF

chroot /mnt /usr/bin/locale -a | while read line ; do
  echo "\"${line}\" \"\" \\" >> ${TMP}/show_locales
done
echo " 2> \${TMP}/return-locales" >> ${TMP}/show_locales

# Chequeo de sanidad para mostrar el men (si hay elementos):
if (( $(sed -n '$=' ${TMP}/show_services) < 7 )); then
  exit;
fi

. ${TMP}/show_locales

if [[ -s ${TMP}/return-locales ]]; then
  LOCALE=$(cat ${TMP}/return-locales)
  cat << EOF > /mnt/etc/profile.d/language
#!/bin/sh
# Set default international language:
#
# Type "locale -a" to see the locales supported.

# Traditional sorting order according to ASCII values (LC_COLLATE=C):
LC_COLLATE=C

# Default locale (en_US):
LANG=$LOCALE

export LC_COLLATE LANG

EOF
  chmod 755 /mnt/etc/profile.d/language
fi

