pootle-upgrade-extension 4.87 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash

set -o errtrace
set -o nounset

#  Trap non-normal exit signals: 1/HUP, 2/INT, 3/QUIT, 15/TERM, ERR
trap onexit 1 2 3 15

#--- onexit() -----------------------------------------------------
#  @param $1 integer  (optional) Exit status.  If not set, use `$?'
function onexit() {
	local exit_status=${1:-$?}
	if [ $exit_status -gt 0 ]; then
		echo Exiting $0 with $exit_status
	fi
	exit $exit_status
}

19
20
21
T3XUTILS=/var/www/vhosts/pootle.typo3.org/home/scripts/bin/t3xutils.phar
POOTLE_MANAGE=/var/www/vhosts/pootle.typo3.org/home/scripts/bin/pootle-manage

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# --- check_available_languages() ---------------------------------
# @param $1 string               Pootle Project Name
function check_available_languages() {
	local NEED_UPDATE=0
	local PROJECT_NAME=$1
        for LANGUAGE_KEY in $(ls /var/www/vhosts/pootle.typo3.org/home/templates); do
		local LANGUAGE_DIRECTORY="/var/www/vhosts/pootle.typo3.org/pootle/po/$PROJECT_NAME/$LANGUAGE_KEY"
                if [ "$PROJECT_NAME" != "" ] && [ -d /var/www/vhosts/pootle.typo3.org/pootle/po/$PROJECT_NAME ] && [ ! -d $LANGUAGE_DIRECTORY ]; then
                        mkdir -p $LANGUAGE_DIRECTORY
                        echo "[NOTICE] Add project language \"$LANGUAGE_KEY\""
			NEED_UPDATE=1
                fi
        done
	if [ $NEED_UPDATE == 1 ]; then
		echo "[NOTICE] Update translation project"
37
		$POOTLE_MANAGE update_translation_projects --project=$1 1>/dev/null 2>/dev/null
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
	fi
}

SAVEIFS=$IFS

XSL_LLXML2TEMPLATE="/var/www/vhosts/pootle.typo3.org/home/scripts/etc/xsl/llxml2template.xsl"
TEMP_DIRECTORY="/var/www/vhosts/pootle.typo3.org/home/tmp"

EXTENSION=$1
VERSION=$2

PROJECT_NAME="TYPO3.TYPO3.ext.$EXTENSION"
PROJECT_DIRECTORY="/var/www/vhosts/pootle.typo3.org/pootle/po/$PROJECT_NAME"
#
# Check if the project exist
if [ ! -d $PROJECT_DIRECTORY ]; then
	echo
	echo "[ERROR] Project $PROJECT_NAME doesn't exist in Pootle, please create it before using this script"
	echo "[ERROR] Please create directory: $PROJECT_DIRECTORY"
	onexit 1
fi

#
# Check if the templates directory exist
TEMPLATE_DIRECTORY="$PROJECT_DIRECTORY/templates"
if [ ! -d $TEMPLATE_DIRECTORY ]; then
        echo
        echo "[INFO] Templates directory for project $PROJECT_NAME doesn't exist in Pootle"
	echo "[NOTICE] Create the templates directory"
	mkdir -p $TEMPLATE_DIRECTORY
fi

cd $TEMP_DIRECTORY >/dev/null

echo "[INFO] Downloading $EXTENSION $VERSION from TER"

EXTENSION_T3X=$(echo "${EXTENSION}_${VERSION}.t3x" | tr '[:upper:]' '[:lower:]')

#
# Download t3x
rm -f $EXTENSION_T3X
wget -q http://typo3.org/fileadmin/ter/${EXTENSION_T3X:0:1}/${EXTENSION_T3X:1:1}/$EXTENSION_T3X

#
# Extract t3x
#extract-t3x $EXTENSION_T3X $EXTENSION > /dev/null
84
$T3XUTILS extract $EXTENSION_T3X $EXTENSION >/dev/null
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

IFS=$(echo -en "\n\b")

#
# Create directory structure for templates
for FILE in $(find $EXTENSION/ -name \*.xml); do
	grep "T3locallang" "$FILE" 1> /dev/null
	if [ $? == 0 ]; then
		mkdir -p $TEMP_DIRECTORY/TYPO3.TYPO3.ext.$(dirname $FILE);
		cp $FILE $TEMP_DIRECTORY/TYPO3.TYPO3.ext.$FILE;
	fi
done
for FILE in $(find $EXTENSION/ -name \*.xlf); do
	# Count number of dots in filename to skip e.g., de.locallang.xlf
	DOTS=$(echo -n $(basename $FILE) | sed 's/[^.]//g' | wc -c)
	if [ $DOTS -eq 1 ]; then
		mkdir -p $TEMP_DIRECTORY/TYPO3.TYPO3.ext.$(dirname $FILE);
		cp $FILE $TEMP_DIRECTORY/TYPO3.TYPO3.ext.$FILE;
	fi
done

cd $TEMP_DIRECTORY
for FILE in $(find TYPO3.TYPO3.ext.$EXTENSION -name \*.xml); do
	grep "T3locallang" "$FILE" 1> /dev/null
	if [ $? == 0 ]; then
		XLF_FILE=$(echo $FILE | sed s/.xml$/.xlf/)
		if [ ! -f $XLF_FILE ]; then
			echo "[INFO] Convert LLXML to XLIFF for file $FILE"
			if [ ! -f $XLF_FILE ]; then
				xsltproc --stringparam lang en \
					--stringparam extension $EXTENSION \
					--stringparam date "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" $XSL_LLXML2TEMPLATE $FILE | \
					xmlstarlet ed --insert "/xliff/file/body/trans-unit" --type attr -n xml:space -v preserve > $XLF_FILE
			fi
		fi
	fi
	rm -f $FILE
done

#
# Deploy new templates files
echo "[INFO] Deploy new templates to $TEMPLATE_DIRECTORY"
cd $TEMPLATE_DIRECTORY/../../ && \
	tar cfzp $TEMP_DIRECTORY/backup/$PROJECT_NAME-$(date +%Y%m%d).tar.gz $PROJECT_NAME && \
	cd - && \
	rm -Rf $TEMPLATE_DIRECTORY && \
	mkdir -p $TEMPLATE_DIRECTORY && \
	cp -a $TEMP_DIRECTORY/$PROJECT_NAME/* $TEMPLATE_DIRECTORY || \
		onexit 5

#
# Check project available language
check_available_languages $PROJECT_NAME

#
# Update project from templates
echo "[INFO] Update from templates"
142
$POOTLE_MANAGE update_from_templates --project=$PROJECT_NAME 1>/dev/null 2>/dev/null
143
144

echo "[INFO] Refresh statistics"
145
$POOTLE_MANAGE refresh_stats --project=$PROJECT_NAME 1>/dev/null 2>/dev/null
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

echo "[NOTICE] Register version $VERSION for EXT:$EXTENSION"
echo -n $VERSION > $PROJECT_DIRECTORY/.ter-version

#
# Cleanup
cd $TEMP_DIRECTORY
rm -f $EXTENSION_T3X
if [ -d $EXTENSION ]; then
	rm -rf $EXTENSION
	rm -rf TYPO3.TYPO3.ext.$EXTENSION
fi

IFS=$SAVEIFS

onexit