#!/bin/sh #---------------------------------------------------------------------------------- # /var/install/bin/espeak-download-mbrola-files - download mbrola files # # Copyright (c) 2012-2019 The Eisfair Team, team(at)eisfair(dot)org # # Creation: 2012-10-27 jed # Last Update: $Id$ # # 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 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------------- # include eislib etc. . /var/install/include/eislib # debug mode: true/false #debug=true if ${debug:-false} then exec 2>/tmp/$(basename ${0})-trace$$.log set -x ask_debug=true export ask_debug fi mbrola_bin=/usr/bin/mbrola mbrola_dir=/usr/share/espeak-data/mbrola mbrola_license_file='/usr/share/doc/espeak/mbrola_licenses.txt' mbrola_urls_file='/usr/share/doc/espeak/mbrola_urls.txt' mbrola_filelist=/usr/share/doc/espeak/mbrola-files.txt tmpdir=/tmp/mbtmp startdir=`pwd` if [ "${startdir}" = "${tmpdir}" ] then startdir=/tmp fi #---------------------------------------------------------------------------------- # print header line #---------------------------------------------------------------------------------- print_header () { clrhome echo mecho --info "MBROLA file download" echo } #---------------------------------------------------------------------------------- # print MBROLA license information #---------------------------------------------------------------------------------- print_mbrola_license_info () { mecho --warn "The MBROLA files are provided under a non-GPL license." mecho --warn "Press ENTER to show the license text on the screen." echo } #---------------------------------------------------------------------------------- # install MBROLA program binary #---------------------------------------------------------------------------------- install_mbrola_binary () { if [ -f ${mbrola_bin} ] then mecho --info "The MBROLA binary '${mbrola_bin}' already exists." grep -q "${mbrola_bin}" ${mbrola_filelist} if [ $? -ne 0 ] then echo "${mbrola_bin}" >> ${mbrola_filelist} fi else mkdir -p ${tmpdir} mbrola_bin_url="${mbrola_base_url}`grep "^binary:" ${mbrola_urls_file} | cut -d: -f2`" echo "Downloading MBROLA binary ..." /usr/bin/wget.sh ${mbrola_bin_url} -O ${tmpdir}/mbrola-bin.zip if [ $? -eq 0 ] then # download successful mime_type=`file --mime-type -b ${tmpdir}/mbrola-bin.zip` case ${mime_type} in 'application/zip'|'application/x-zip' ) unzip -d ${tmpdir}/ -o -q ${tmpdir}/mbrola-bin.zip if [ $? -eq 0 ] then # unzip successful echo "Installing MBROLA binary..." mv -v ${tmpdir}/mbrola-linux-i386 ${mbrola_bin} chown root: ${mbrola_bin} chmod 0755 ${mbrola_bin} grep -q "${mbrola_bin}" ${mbrola_filelist} if [ $? -ne 0 ] then echo "${mbrola_bin}" >> ${mbrola_filelist} fi echo "done." else mecho --error "Unable to extract MBROLA binary from archive!" fi # remove temporary directory cd ${startdir} rm -rf ${tmpdir} ;; * ) mecho --warn "Unknown MIME type '${mime_type}' used for MBROLA binary archive!" ;; esac else mecho --error "Unable to download file '${mbrola_bin_url}'!" fi fi } #---------------------------------------------------------------------------------- # install MBROLA voice files # $1 - language #---------------------------------------------------------------------------------- install_mbrola_voice_files () { lang="$1" # make sure the destination directory exists if [ ! -d ${mbrola_dir} ] then mkdir -p ${mbrola_dir} fi grep "^voice:${lang}:" ${mbrola_urls_file} | while read line do mkdir -p ${tmpdir} mbrola_voice_url="${mbrola_base_url}`echo "${line}" | cut -d: -f3`" echo "Downloading MBROLA voice files ..." /usr/bin/wget.sh ${mbrola_voice_url} -O ${tmpdir}/mbrola-voice.zip if [ $? -eq 0 ] then # download successful mime_type=`file --mime-type -b ${tmpdir}/mbrola-voice.zip` case ${mime_type} in 'application/zip'|'application/x-zip' ) # extract files from archive unzip -d ${tmpdir}/ -o -q ${tmpdir}/mbrola-voice.zip if [ $? -eq 0 ] then # unzip successful echo "Installing MBROLA voice file ..." cd ${tmpdir} # cd to temporary directory cd ${lang}* 2>/dev/null # if possible, cd to sub directory curr_dir=`pwd` lang_prefix=`find . -name "${lang}[0-9]" | sed 's#.\/##'` for FNAME in `find . -maxdepth 1 -type f -name "*[[:alpha:]]*" -not -name "*zip" | sed 's#.\/##'` do echo ${FNAME} | grep -q "license" if [ $? -eq 0 ] then # move and rename license file mv -v ${curr_dir}/${FNAME} ${mbrola_dir}/${lang_prefix}-${FNAME} chown root: ${mbrola_dir}/${lang_prefix}-${FNAME} chmod 0644 ${mbrola_dir}/${lang_prefix}-${FNAME} grep -q "${mbrola_dir}/${lang_prefix}-${FNAME}" ${mbrola_filelist} if [ $? -ne 0 ] then echo "${mbrola_dir}/${lang_prefix}-${FNAME}" >> ${mbrola_filelist} fi else # move files mv -v ${curr_dir}/${FNAME} ${mbrola_dir}/ chown root: ${mbrola_dir}/${FNAME} chmod 0644 ${mbrola_dir}/${FNAME} grep -q "${mbrola_dir}/${FNAME}" ${mbrola_filelist} if [ $? -ne 0 ] then echo "${mbrola_dir}/${FNAME}" >> ${mbrola_filelist} fi fi done echo "done." else mecho --error "Unable to extract MBROLA voice file from archive!" fi # remove temporary directory cd ${startdir} rm -rf ${tmpdir} ;; *) mecho --warn "Unknown MIME type '${mime_type}' used for MBROLA voice file archive!" ;; esac else mecho --error "Unable to download file '${mbrola_voice_url}'!" fi done } #================================================================================== # main #================================================================================== print_header print_mbrola_license_info anykey # check display environment color='' frame='' if $(grep -qE "^MENU=['\"]/var/install/bin/show-menu['\"]" /etc/config.d/setup) then color='--nocolor' frame='--noframe' fi # show MBROLA license terms /var/install/bin/show-doc.cui ${color} ${frame} --title ${mbrola_license_file} "${mbrola_license_file}" print_header print_mbrola_license_info echo "[The license terms have been displayed]" echo if /var/install/bin/ask "Have you read the license terms and want to continue the installation" "n" then # license terms have been read, continue ... mbrola_base_url="`grep "^baseurl|" ${mbrola_urls_file} | cut -d'|' -f2`" # select voice language clrhome echo mecho --info "Select MBROLA voice language" echo techo --begin '2 3r 2 20*' grep "^language:" ${mbrola_urls_file} | while read line do lang_id=`echo "${line}" | cut -d: -f2` lang_desc=`echo "${line}" | cut -d: -f3` techo --row "" "${lang_id}" "-" "${lang_desc}" done techo --end echo lang_select="`grep "^language:" ${mbrola_urls_file} | cut -d: -f2 | tr '\n' ' '` q=quit" lang_exit=0 until [ ${lang_exit} -eq 1 ] do /var/install/bin/ask "For which language do you want to install voice files" "q" ${lang_select} > /tmp/ask.$$ rc=$? lang_choice=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then exit 1 fi case ${lang_choice} in q ) # quit lang_exit=1 ;; * ) # install MBROLA voice files ... if [ ! -f ${mbrola_filelist} ] then touch ${mbrola_filelist} fi install_mbrola_binary install_mbrola_voice_files "${lang_choice}" ;; esac done # remove temporary directory cd ${startdir} rm -rf ${tmpdir} else echo "Installation aborted." fi exit 0