#!/bin/bash

#
# sync-hunspell-dictionaries
#
# Copyright (C) 2009-12 by RStudio, Inc.
#
# Unless you have received this program directly from RStudio pursuant
# to the terms of a commercial license agreement with RStudio, then
# this program is licensed to you under the terms of version 3 of the
# GNU Affero General Public License. This program is distributed WITHOUT
# ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
# AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
#
#

#
# This script creates a directory (hunspell_dictionaries) that contains the 
# latest hunspell dictionaries (and dic_delta files) from chromium. It also
# builds two archives (english-dictionaries.zip and all-dictionaries.zip) 
# that can be used as the basis for rstudio dictionaries. Note that after 
# this script is run by RStudio we upload the files to S3 for subsequent 
# download to dependencies/common/hunspell_dictionaries as part of the 
# install-dependencies script
#

set -e

# install dir
INSTALL_DIR=`pwd`

# get the latest dictionaries and switch to the dictionary directory
HUNSPELL_DICTIONARIES=hunspell_dictionaries
svn co https://src.chromium.org/svn/trunk/deps/third_party/hunspell_dictionaries/ $HUNSPELL_DICTIONARIES
cd $HUNSPELL_DICTIONARIES

# build the core archive
CORE_DICTIONARIES=core-dictionaries.zip
rm -f $CORE_DICTIONARIES
ls | egrep '^(en_US|en_GB|en_CA|en_AU)\..*$' | zip -@ $CORE_DICTIONARIES

# build the universal archive
ALL_DICTIONARIES=all-dictionaries.zip
rm -f $ALL_DICTIONARIES
ls | egrep '^(bg_BG|ca_ES|cs_CZ|da_DK|de_DE|de_DE_neu|el_GR|en_US|en_GB|en_CA|en_AU|es_ES|fr_FR|hr_HR|hu-HU|id_ID|it_IT|lt_LT|lv_LV|nb_NO|nl_NL|pl_PL|pt_BR|pt_PT|ro_RO|ru_RU|sh|sk_SK|sl_SI|sr|sv_SE|uk_UA|vi_VN)\..*$' | zip -@ $ALL_DICTIONARIES

# return to install dir
cd $INSTALL_DIR

