Warning, file /education/gcompris-data/voices/generate_voices_rcc.sh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 #!/bin/bash
0002 #
0003 # generate_voices_rcc.sh
0004 #
0005 # Copyright (C) 2014 Holger Kaelberer
0006 #
0007 # Generates Qt binary resource files (.rcc) for voices locales.
0008 #
0009 # Results will be written to $PWD/.rcc/ which is supposed be synced to the
0010 # upstream location.
0011 #
0012 
0013 [ $# -ne 1 ] && {
0014     echo "Usage: generate_voices_rcc.sh ogg|aac|ac3|mp3"
0015     exit 1
0016 }
0017 
0018 # Compressed Audio Format
0019 CA=$1
0020 
0021 QRC_DIR="."
0022 RCC_DIR=".rcc"
0023 #RCC_DEFAULT=`which rcc 2>/dev/null`   # default, better take /usr/bin/rcc?
0024 RCC_DEFAULT=$Qt5_DIR/bin/rcc
0025 CONTENTS_FILE=Contents
0026 MD5SUM=/usr/bin/md5sum
0027 
0028 [ -z "${RCC}" ] && RCC=${RCC_DEFAULT}
0029 
0030 [ -z "${RCC}" ] && {
0031     echo "No rcc command in PATH, can't continue. Try to set specify RCC in environment:"
0032     echo "RCC=/path/to/qt/bin/rcc $0"
0033     exit 1
0034 }
0035 
0036 WORDS_NAME=words-webp
0037 WORDS_DIR=../../words/${WORDS_NAME}
0038 [ ! -d "${WORDS_DIR}" ] && {
0039     echo "Words dir ${WORDS_DIR} not found"
0040     exit 1
0041 }
0042 [ -d ${WORDS_NAME} ] && rm -rf ${WORDS_NAME}
0043 ln -s ${WORDS_DIR} ${WORDS_NAME}
0044 
0045 # Duplicate for old words (in png, not webp)
0046 OLD_WORDS_NAME=words
0047 OLD_WORDS_DIR=../../words/${OLD_WORDS_NAME}
0048 [ ! -d "${OLD_WORDS_DIR}" ] && {
0049     echo "Words dir ${OLD_WORDS_DIR} not found"
0050     exit 1
0051 }
0052 [ -d ${OLD_WORDS_NAME} ] && rm -rf ${OLD_WORDS_NAME}
0053 ln -s ${OLD_WORDS_DIR} ${OLD_WORDS_NAME}
0054 
0055 function generate_rcc {
0056     # Generate RCC 
0057     echo -n "$2 ... "
0058     mkdir -p ${2%/*}
0059     ${RCC} -binary $1 -o $2
0060 
0061     echo "md5sum ... "
0062     cd ${2%/*}
0063     ${MD5SUM}  ${2##*/}>> ${CONTENTS_FILE}
0064     cd - &>/dev/null
0065 }
0066 
0067 function generate_words_rcc {
0068     header_rcc "${QRC_DIR}/$1.qrc"
0069     for i in `find $1/ -not -type d | sort`; do
0070         echo "    <file>${i#${2}}</file>" >> "${QRC_DIR}/$1.qrc"
0071     done
0072     footer_rcc "${QRC_DIR}/$1.qrc"
0073     echo -n "  $1: "${QRC_DIR}/$1.qrc" ... "
0074     generate_rcc "${QRC_DIR}/$1.qrc" "${RCC_DIR}/words/$1.rcc"
0075 }
0076 
0077 function header_rcc {
0078 (cat <<EOHEADER
0079 <!DOCTYPE RCC><RCC version="1.0">
0080 <qresource prefix="/gcompris/data">
0081 EOHEADER
0082 ) > $1
0083 }
0084 
0085 function footer_rcc {
0086 (cat <<EOFOOTER
0087 </qresource>
0088 </RCC>
0089 EOFOOTER
0090 ) >> $1
0091 }
0092 
0093 echo "Generating binary resource files in ${RCC_DIR}/ folder:"
0094 
0095 [ -d ${RCC_DIR} ] && rm -rf ${RCC_DIR}
0096 mkdir  ${RCC_DIR}
0097 
0098 #header of the global qrc (all the langs)
0099 QRC_FULL_FILE="${QRC_DIR}/full-${CA}.qrc"
0100 RCC_FULL_FILE="${RCC_DIR}/full-${CA}.rcc"
0101 header_rcc $QRC_FULL_FILE
0102 
0103 # Create the voices directory that will contains links to locales dir
0104 VOICE_DIR="voices-${CA}"
0105 [ -d ${RCC_DIR} ] && rm -rf ${RCC_DIR}
0106 rm -rf ${VOICE_DIR}
0107 mkdir -p ${VOICE_DIR}
0108 
0109 for LANG in `find . -maxdepth 1 -regextype posix-egrep -type d -regex "\./[a-z]{2,3}(_[A-Z]{2,3})?" -follow | sort`; do
0110     QRC_FILE="${QRC_DIR}/voices-${LANG#./}.qrc"
0111     RCC_FILE="${RCC_DIR}/${VOICE_DIR}/voices-${LANG#./}.rcc"
0112 
0113     # Populate the voices backlinks
0114     ln -s -t ${VOICE_DIR} ../$LANG
0115 
0116     # Generate QRC:
0117     echo -n "  ${LANG#./}: ${QRC_FILE} ... "
0118     # check for junk in the voices dirs:
0119     if [[ -d .git && ! -z "`git status --porcelain ${LANG} | grep '^??'`" ]]; then
0120         echo "Warning, found untracked files in your git checkout below ${LANG}. Better "git clean -f" it first!";
0121     fi
0122     [ -e ${QRC_FILE} ] && rm ${QRC_FILE}
0123 
0124     header_rcc $QRC_FILE
0125     for i in `find ${LANG}/ -not -type d | sort`; do
0126         # For the lang file
0127         echo "    <file>${VOICE_DIR}/${i#./}</file>" >> $QRC_FILE
0128         # For the all lang file
0129         echo "    <file>${VOICE_DIR}/${i#./}</file>" >> $QRC_FULL_FILE
0130     done
0131     footer_rcc $QRC_FILE
0132     generate_rcc ${QRC_FILE} ${RCC_FILE}
0133 
0134 done
0135 
0136 # Word images for the full qrc
0137 for i in `find ${WORDS_NAME}/ -not -type d | sort`; do
0138     echo "    <file>${i#${WORDS_DIR}}</file>" >> $QRC_FULL_FILE
0139 done
0140 
0141 #footer of the global qrc (all the langs)
0142 footer_rcc $QRC_FULL_FILE
0143 
0144 echo -n "  full: ${QRC_FULL_FILE} ... "
0145 generate_rcc ${QRC_FULL_FILE} ${RCC_FULL_FILE}
0146 
0147 # Word images standalone rcc
0148 # This is generated only when the script is called to generate ogg files
0149 # as this is our reference and images does not depends on the audio codec
0150 if [[ $CA == ogg ]]
0151 then
0152     generate_words_rcc ${WORDS_NAME} ${WORDS_DIR}
0153     generate_words_rcc ${OLD_WORDS_NAME} ${OLD_WORDS_DIR}
0154 fi
0155 
0156 #cleanup:
0157 #rm -f *.qrc
0158 #rm ${WORDS_NAME}
0159 #rm -rf ${VOICE_DIR}
0160 
0161 echo "Finished!"
0162 echo ""
0163 echo "Consolidate .rcc/Contents in a master ${RCC_DIR}"
0164 echo "containing all the encoded content."
0165 echo ""
0166 echo "Then do something like:"
0167 echo "rsync -avx ${RCC_DIR}/  gcompris.net:/var/www/data2/"
0168 #EOF