update-pot.sh 2.38 KB
Newer Older
1 2 3 4
#!/bin/bash

# Update .pot files

5
# this is expected to define DATA, SCRIPTS, DOCROOT
6 7 8 9 10 11 12
. /etc/mahara-langpacks.conf

if [ ! -w ${DATA} ]; then
    echo "${DATA} not writable"
    exit 1
fi

13 14 15 16 17
if [ ! -w ${DOCROOT} ]; then
    echo "${DOCROOT} not writable"
    exit 1
fi

18 19 20
WORK=${DATA}/templates
GITDIR=${WORK}/git
TEMP=${WORK}/temp
21
OUT=${DATA}/po
22 23 24 25

[ ! -d ${WORK} ] && mkdir ${WORK}
[ ! -d ${TEMP} ] && mkdir ${TEMP}
[ ! -d ${OUT} ] && mkdir ${OUT}
26
[ ! -d ${DOCROOT}/po ] && mkdir ${DOCROOT}/po
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

remote='git://gitorious.org/mahara/mahara.git'

if [ ! -d ${GITDIR} ]; then
    echo "git clone ${remote} ${GITDIR}"
    git clone --quiet ${remote} ${GITDIR}
fi

cd ${GITDIR}
git fetch --quiet origin

branches="1.2_STABLE 1.3_STABLE master"

for branch in ${branches} ; do
    branchexists=`git branch | grep "${branch}$"`
    if [ -z "${branchexists}" ]; then
        git checkout -b ${branch} origin/${branch}
    else
        git checkout --quiet ${branch}
        git reset --hard -q origin/${branch}
    fi

    remotecommit=`git log --pretty=format:"%H" | head -1`

    last=${WORK}/${branch}.last
    lastruncommit=z
    if [ -f ${last} ]; then
        lastruncommit=`cat ${last}`
    fi

    if [ "$remotecommit" = "$lastruncommit" ] ; then
        echo "${branch} is up to date"
    else
        echo "New commits on ${branch}"

        outputfile=${OUT}/${branch}.pot

        if [ ! -d ${GITDIR}/htdocs ] ; then
            echo "No htdocs directory in branch ${branch}; skipping."
            continue
        fi

        find htdocs -type f -path "*lang/en.utf8*" | xargs tar zcf ${TEMP}/${branch}.tar.gz

        if [ ! -f ${TEMP}/${branch}.tar.gz ] ; then
            echo "Missing archive ${TEMP}/${branch}.tar.gz; skipping."
            continue
        fi

        langpack=${TEMP}/${branch}
        [ ! -d ${langpack} ] && mkdir ${langpack}

        cd ${langpack}
        tar zxf ../${branch}.tar.gz
        cd ${GITDIR}

        if [ ! -d ${langpack}/htdocs ] ; then
            echo "No htdocs directory in langpack ${langpack}; skipping."
            continue
        fi

        echo "Updating ${outputfile}"

        [ -f ${outputfile} ] && rm ${outputfile}
        /usr/bin/php ${SCRIPTS}/php-po.php ${langpack} ${langpack} ${outputfile}

93 94 95 96 97
        if [ -f ${outputfile} ]; then
            chmod 755 ${outputfile}
            cp ${outputfile} ${DOCROOT}/po
        fi

98 99 100
        echo "${remotecommit}" > ${last}
    fi
done