File indexing completed on 2024-12-01 09:38:08

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 BG_MUSIC_NAME=backgroundMusic
0046 BG_MUSIC_DIR=../../background-music/${CA}/backgroundMusic
0047 [ ! -d "${BG_MUSIC_DIR}" ] && {
0048     echo "Background music must be generated before generating full rcc"
0049     exit 1
0050 }
0051 [ -d ${BG_MUSIC_NAME} ] && rm -rf ${BG_MUSIC_NAME}
0052 ln -s ${BG_MUSIC_DIR} ${BG_MUSIC_NAME}
0053 
0054 # We need to use --format-version 2 option for rcc to be retro-compatible with all our GCompris versions
0055 function generate_rcc {
0056     # Generate RCC 
0057     echo -n "$2 ... "
0058     mkdir -p ${2%/*}
0059     ${RCC} --format-version 2 --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     LAST_UPDATE_DATE=$(git log -n 1 --pretty=format:%cd --date=format:"%Y-%m-%d-%H-%M-%S" ${WORDS_DIR})
0075     generate_rcc "${QRC_DIR}/$1.qrc" "${RCC_DIR}/words/$1-${LAST_UPDATE_DATE}.rcc"
0076 }
0077 
0078 function header_rcc {
0079 (cat <<EOHEADER
0080 <!DOCTYPE RCC><RCC version="1.0">
0081 <qresource prefix="/gcompris/data">
0082 EOHEADER
0083 ) > $1
0084 }
0085 
0086 function footer_rcc {
0087 (cat <<EOFOOTER
0088 </qresource>
0089 </RCC>
0090 EOFOOTER
0091 ) >> $1
0092 }
0093 
0094 echo "Generating binary resource files in ${RCC_DIR}/ folder:"
0095 
0096 [ -d ${RCC_DIR} ] && rm -rf ${RCC_DIR}
0097 mkdir  ${RCC_DIR}
0098 
0099 #header of the global qrc (all the langs)
0100 QRC_FULL_FILE="${QRC_DIR}/full-${CA}.qrc"
0101 LAST_UPDATE_DATE=$(git log -n 1 --pretty=format:%cd --date=format:"%Y-%m-%d-%H-%M-%S" ../../)
0102 RCC_FULL_FILE="${RCC_DIR}/full-${CA}-${LAST_UPDATE_DATE}.rcc"
0103 header_rcc $QRC_FULL_FILE
0104 
0105 # Create the voices directory that will contains links to locales dir
0106 VOICE_DIR="voices-${CA}"
0107 [ -d ${RCC_DIR} ] && rm -rf ${RCC_DIR}
0108 rm -rf ${VOICE_DIR}
0109 mkdir -p ${VOICE_DIR}
0110 
0111 for LANG in `find . -maxdepth 1 -regextype posix-egrep -type d -regex "\./[a-z]{2,3}(_[A-Z]{2,3})?" -follow | sort`; do
0112     LAST_UPDATE_DATE=$(git log -n 1 --pretty=format:%cd --date=format:"%Y-%m-%d-%H-%M-%S" ../$LANG)
0113     QRC_FILE="${QRC_DIR}/voices-${LANG#./}.qrc"
0114     RCC_FILE="${RCC_DIR}/${VOICE_DIR}/voices-${LANG#./}-${LAST_UPDATE_DATE}.rcc"
0115 
0116     # Populate the voices backlinks
0117     ln -s -t ${VOICE_DIR} ../$LANG
0118 
0119     # Generate QRC:
0120     echo -n "  ${LANG#./}: ${QRC_FILE} ... "
0121     # check for junk in the voices dirs:
0122     if [[ -d .git && ! -z "`git status --porcelain ${LANG} | grep '^??'`" ]]; then
0123         echo "Warning, found untracked files in your git checkout below ${LANG}. Better "git clean -f" it first!";
0124     fi
0125     [ -e ${QRC_FILE} ] && rm ${QRC_FILE}
0126 
0127     header_rcc $QRC_FILE
0128     for i in `find ${LANG}/ -not -type d | sort`; do
0129         # For the lang file
0130         echo "    <file>${VOICE_DIR}/${i#./}</file>" >> $QRC_FILE
0131         # For the all lang file
0132         echo "    <file>${VOICE_DIR}/${i#./}</file>" >> $QRC_FULL_FILE
0133     done
0134     footer_rcc $QRC_FILE
0135     generate_rcc ${QRC_FILE} ${RCC_FILE}
0136 
0137 done
0138 # Word images for the full qrc
0139 for i in `find ${WORDS_NAME}/ -not -type d | sort`; do
0140     echo "    <file>${i#${WORDS_DIR}}</file>" >> $QRC_FULL_FILE
0141 done
0142 
0143 # BackgroundMusic for the full qrc
0144 for i in `find ${BG_MUSIC_NAME}/ -not -type d -name "*.${CA}" | sort`; do
0145     echo "    <file>${i#${BG_MUSIC_DIR}}</file>" >> $QRC_FULL_FILE
0146 done
0147 
0148 #footer of the global qrc (all the langs)
0149 footer_rcc $QRC_FULL_FILE
0150 
0151 echo -n "  full: ${QRC_FULL_FILE} ... "
0152 generate_rcc ${QRC_FULL_FILE} ${RCC_FULL_FILE}
0153 
0154 # Word images standalone rcc
0155 # This is generated only when the script is called to generate ogg files
0156 # as this is our reference and images does not depends on the audio codec
0157 if [[ $CA == ogg ]]
0158 then
0159     generate_words_rcc ${WORDS_NAME} ${WORDS_DIR}
0160 fi
0161 
0162 #cleanup:
0163 #rm -f *.qrc
0164 #rm ${WORDS_NAME}
0165 #rm -rf ${VOICE_DIR}
0166 
0167 echo "Finished!"
0168 echo ""
0169 echo "Consolidate .rcc/Contents in a master ${RCC_DIR}"
0170 echo "containing all the encoded content."
0171 echo ""
0172 echo "Then do something like:"
0173 echo "rsync -avx ${RCC_DIR}/  gcompris.net:/var/www/data3/"
0174 #EOF