update-pot.sh 2.76 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}/pot ] && mkdir ${DOCROOT}/pot
27 28 29 30 31 32 33 34 35 36 37

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

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

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

74 75 76
        # 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

77 78 79 80 81 82 83 84 85 86 87 88
        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

89 90 91 92 93
        [ ! -d ${OUT}/${branch} ] && mkdir ${OUT}/${branch}
        outputdir=${OUT}/${branch}/mahara
        [ ! -d ${outputdir} ] && mkdir ${outputdir}
        outputfile=${outputdir}/mahara.pot

94 95 96 97 98
        echo "Updating ${outputfile}"

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

99
        if [ -f ${outputfile} ]; then
100 101 102
            cd ${OUT}/${branch}
            tar zcf ${DOCROOT}/pot/${branch}.tar.gz mahara/mahara.pot
            cd ${GITDIR}
103 104
        fi

105 106 107
        echo "${remotecommit}" > ${last}
    fi
done