update-pot.sh 3.32 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 21 22 23
WORK=${DATA}/templates
GITDIR=${WORK}/git
TEMP=${WORK}/temp

[ ! -d ${WORK} ] && mkdir ${WORK}
[ ! -d ${TEMP} ] && mkdir ${TEMP}
24
[ ! -d ${DOCROOT}/pot ] && mkdir ${DOCROOT}/pot
25

26
mahararemote='git://gitorious.org/mahara/mahara.git'
27 28

if [ ! -d ${GITDIR} ]; then
29 30
    echo "git clone ${mahararemote} ${GITDIR}"
    git clone --quiet ${mahararemote} ${GITDIR}
31 32
fi

33 34 35 36
[ ! -d "${WORK}/mahara-lang-bzr" ] && bzr init-repo ${WORK}/mahara-lang-bzr

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

37 38 39
cd ${GITDIR}
git fetch --quiet origin

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

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

76 77 78
        # 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

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

91
        # Output into a copy of the launchpad mahara-lang repo
92
        [ ! -d ${BZR}/${branch} ] && bzr branch lp:~mahara-lang/mahara-lang/${branch} ${BZR}/${branch}
93
        outputdir=${BZR}/${branch}/mahara
94 95 96
        [ ! -d ${outputdir} ] && mkdir ${outputdir}
        outputfile=${outputdir}/mahara.pot

97 98 99 100 101
        echo "Updating ${outputfile}"

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

102
        if [ -f ${outputfile} ]; then
103 104 105 106 107 108 109 110 111 112 113 114
            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

                # Push template to lp:mahara-lang
                bzr add mahara/mahara.pot
                bzr commit -m "Update template to ${remotecommit}"
115
                bzr push lp:~mahara-lang/mahara-lang/${branch}
116 117 118

            fi

119
            cd ${GITDIR}
120 121
        fi

122 123 124
        echo "${remotecommit}" > ${last}
    fi
done