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

# Update .pot files

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

8 9 10
echo -n "Checking for changes to strings "
date "+%Y-%m-%d %H:%M:%S"

11 12 13 14 15
if [ ! -w ${DATA} ]; then
    echo "${DATA} not writable"
    exit 1
fi

16 17 18 19 20
if [ ! -w ${DOCROOT} ]; then
    echo "${DOCROOT} not writable"
    exit 1
fi

21 22 23 24 25 26
WORK=${DATA}/templates
GITDIR=${WORK}/git
TEMP=${WORK}/temp

[ ! -d ${WORK} ] && mkdir ${WORK}
[ ! -d ${TEMP} ] && mkdir ${TEMP}
27
[ ! -d ${DOCROOT}/pot ] && mkdir ${DOCROOT}/pot
28

29
mahararemote='git://gitorious.org/mahara/mahara.git'
30 31

if [ ! -d ${GITDIR} ]; then
32 33
    echo "git clone ${mahararemote} ${GITDIR}"
    git clone --quiet ${mahararemote} ${GITDIR}
34 35
fi

36 37 38 39
[ ! -d "${WORK}/mahara-lang-bzr" ] && bzr init-repo ${WORK}/mahara-lang-bzr

BZR=${WORK}/mahara-lang-bzr

40 41 42
cd ${GITDIR}
git fetch --quiet origin

43
branches="1.2_STABLE 1.3_STABLE 1.4_STABLE master"
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

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}"

        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

79 80 81
        # While we have an up-to-date en tarball handy, dump a copy of it in the main tarball directory
        cp ${TEMP}/${branch}.tar.gz ${DOCROOT}/en-${branch}.tar.gz

82 83 84 85 86 87 88 89 90 91 92 93
        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

94
        # Output into a copy of the launchpad mahara-lang repo
95 96 97 98 99 100 101 102
        if [ ! -d ${BZR}/${branch} ]; then
            bzr branch lp:~mahara-lang/mahara-lang/${branch} ${BZR}/${branch}
        else
            cd ${BZR}/${branch}
            bzr pull
            cd ${GITDIR}
        fi

103
        outputdir=${BZR}/${branch}/mahara
104 105 106
        [ ! -d ${outputdir} ] && mkdir ${outputdir}
        outputfile=${outputdir}/mahara.pot

107 108 109
        echo "Updating ${outputfile}"

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

112
        if [ -f ${outputfile} ]; then
113 114 115 116 117 118 119 120 121
            cd ${BZR}/${branch}

            diffs=`bzr diff mahara/mahara.pot`

            if [ ! -z "${diffs}" ]; then

                # Update copy of template in webroot
                tar zcf ${DOCROOT}/pot/${branch}.tar.gz mahara/mahara.pot

122
                # Update template
123 124 125
                bzr add mahara/mahara.pot
                bzr commit -m "Update template to ${remotecommit}"

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
                # Update all the .po files from the export repo to avoid unnecessary invalidation
                # of existing translations
                exportbranch=${branch}-export
                if [ ! -d ${BZR}/${exportbranch} ]; then
                    bzr branch lp:~mahara-lang/mahara-lang/${exportbranch} ${BZR}/${exportbranch}
                else
                    cd ${BZR}/${exportbranch}
                    bzr pull
                fi

                for po in `ls ${BZR}/${exportbranch}/mahara/*.po`; do
                    pobase=${po##*/}
                    /usr/bin/perl ${SCRIPTS}/update-po-from-pot.pl $po mahara/mahara.pot mahara/$pobase
                done

                podiffs=`bzr diff mahara`

                if [ ! -z "$podiffs" ] ; then
                    bzr add mahara
                    bzr commit -m "Update translations to ${remotecommit}"
                fi

                # Push everything to lp:mahara-lang
                bzr push lp:~mahara-lang/mahara-lang/${branch}
150 151
            fi

152
            cd ${GITDIR}
153 154
        fi

155 156 157
        echo "${remotecommit}" > ${last}
    fi
done