-
Notifications
You must be signed in to change notification settings - Fork 1
/
translation.sh
executable file
·182 lines (154 loc) · 4.3 KB
/
translation.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/sh
# i-MSCP - internet Multi Server Control Panel
# Copyright (C) 2010-2014 by internet Multi Server Control Panel
#
# @author Laurent Declercq <l.declercq@nuxwin.com>
# @link http://i-mscp.net
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
# IMPORTANT:
# You must have write access to the i-MSCP git repository (just import your ssh key if needed)
# Usage example: ./translation.sh -b 1.2.x -t 'username:password' -d
set -e
clear
# Get current working directory
CWD=$(pwd)
# Command line options
usage() {
NAME=`basename $0`
echo "Usage: bash $NAME -b <BRANCH> -t <TRANSIFEX_CREDENTIALS> [OPTIONS] ..."
echo "Release new i-MSCP version on github and sourceforge"
echo ""
echo "Options:"
echo " -b Git branch onto operate."
echo " -t Transifex credentials provided as 'username:password'."
echo " -s Whether or not use sudo for the restricted commands."
echo " -d Do everything except actually send the updates on both Transifex and Github."
echo " -h Show this help."
exit 1
}
# Set default option values
RELEASEMANAGER="Laurent Declercq"
TRANSIFEX=""
SUDO=""
DRYRUN=""
BRANCH=""
# Parse command line options
if [ "$#" -eq "1" -a "$1" = "-h" ]; then usage; fi
while getopts ":b:t:sd" option;
do
case ${option} in
b)
BRANCH=$OPTARG
;;
t)
TRANSIFEX=$OPTARG
TRANSIFEXUSER=$(echo "${TRANSIFEX}" | cut -s -d ":" -f 1 | sed 's/ //g')
TRANSIFEXPWD=$(echo "${TRANSIFEX}" | cut -s -d ":" -f 2 | sed 's/ //g')
;;
s)
SUDO="sudo"
;;
d)
DRYRUN="--dry-run"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
if [ -z "${BRANCH}" ]; then
echo "-b option is missing" >&2
usage
elif [ -z "${TRANSIFEX}" ]; then
echo "-t option is missing" >&2
usage
elif [ -z "${TRANSIFEXUSER}" ] || [ -z "${TRANSIFEXPWD}" ]; then
echo "-t option require an username and password provided as 'username:password'" >&2
usage
fi
# Variables
GITFOLDER="imscpgit"
GITHUBURL="git@github.com:i-MSCP/imscp.git"
#
## Packages installation
#
${SUDO} apt-get update
${SUDO} apt-get install perl git-core gettext python-setuptools
${SUDO} easy_install --upgrade transifex-client
#
## Setup working environment
#
if [ ! -d "${CWD}/${GITFOLDER}" ]; then
# Clone repository
git clone ${GITHUBURL} ${GITFOLDER}
fi
cd ${CWD}/${GITFOLDER}
# Cleanup current branch
git checkout .
git clean -f -d
# Update remote references
git fetch
# Switch to the selected branch
git checkout ${BRANCH}
# Remove any local change
while git status | grep -q "ahead"; do
git reset --hard HEAD^
done
# Pull changes from remote repository
git pull
#
## Update translation files
#
# Create Transifex configuration file
if [ -f "$HOME/.transifexrc" ]; then
rm $HOME/.transifexrc
fi
touch $HOME/.transifexrc
printf "%b\n" "[https://www.transifex.com]" >> $HOME/.transifexrc
printf "%b\n" "hostname = https://www.transifex.com" >> $HOME/.transifexrc
printf "%b\n" "password = ${TRANSIFEXPWD}" >> $HOME/.transifexrc
printf "%b\n" "token = " >> $HOME/.transifexrc
printf "%b\n" "username = ${TRANSIFEXUSER}" >> $HOME/.transifexrc
# Update pot file by extracting translation string from source code
cd ${CWD}/${GITFOLDER}/i18n/tools
sh makemsgs
if [ -z "$DRYRUN" ]; then
# Push translation resource file on Transifex
cd ${CWD}/${GITFOLDER}/i18n
tx push -s
fi
# Pull po files from Transifex
cd ${CWD}/${GITFOLDER}/i18n
tx pull -af
# Compile mo file
cd ${CWD}/${GITFOLDER}/i18n/tools
sh compilePo
#
## Commit changes on Github
#
if [ -z "$DRYRUN" ]; then
cd ${CWD}/${GITFOLDER}
git add .
git commit -a -m "Updated: Translation files (synced with Transifex)"
git push origin ${BRANCH}:${BRANCH} ${DRYRUN}
fi
exit