2
# check-locales: verify ufw with the existing locales. This is Ubuntu/Debian
5
# Copyright 2012 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License version 3,
9
# as published by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
`basename $0` [OPTIONS] [<directory with ufw mo files>]
24
-f force installation of locales
25
-d directory with ufw mo files
26
-p directory with ufw po files
27
-D directory with to place mo files after converting from po
33
$ sudo `basename $0` -l C
36
$ sudo `basename $0` -l en
38
# Run the sk tests, installing language-pack-sk* if needed
39
$ sudo `basename $0` -l sk -i
42
$ sudo `basename $0` -d /tmp/ufw-translations
44
# Run the all tests where we have translations, installing language-packs as
46
$ sudo `basename $0` -l sk -i
51
if id | egrep -q '^uid=0' ; then
58
local myloc=`echo "$1" | sed 's#_.*$##'`
59
langpack="language-pack-$myloc*"
60
if ! dpkg-query -l "$langpack" 2>&1 | egrep -q '^ii' ; then
61
echo "Installing '$langpack'"
62
apt-get install -y --force-yes "$langpack"
68
if locale -a | egrep -q "^${myloc}.utf8$" ; then
70
elif locale -a | egrep -q "^${myloc}_.*.utf8$" ; then
77
local myloc="${1}".UTF-8
78
echo "Running 'locale-gen $myloc'"
88
echo "Test ($myloc): $myargs"
90
if [ "$verbose" = "yes" ]; then
91
LC_ALL="$myloc" ufw $myargs || {
92
err_count=$((err_count+1))
96
LC_ALL="$myloc" ufw $myargs >/dev/null || {
97
err_count=$((err_count+1))
107
local locales="$myloc"
108
if [ "$myloc" != "C" ] && echo "$myloc" | grep -qv "_" ; then
109
locales="${myloc}.utf8 `locale -a | egrep "^${myloc}_.*.utf8$"`"
114
for loc in $locales ; do
115
runcmd "$loc" status || myerr="yes"
116
runcmd "$loc" allow 22/tcp || myerr="yes"
117
runcmd "$loc" --force enable || myerr="yes"
118
runcmd "$loc" allow 80 || myerr="yes"
119
runcmd "$loc" allow from 192.168.254.1 || myerr="yes"
121
runcmd "$loc" status || myerr="yes"
122
runcmd "$loc" status verbose || myerr="yes"
123
runcmd "$loc" status numbered || myerr="yes"
125
runcmd "$loc" delete allow from 192.168.254.1 || myerr="yes"
126
runcmd "$loc" delete allow 80 || myerr="yes"
127
runcmd "$loc" delete allow 22/tcp || myerr="yes"
130
runcmd "$loc" delete allow 23 || myerr="yes"
133
runcmd "$loc" disable || myerr="yes"
135
if [ "$myerr" = "yes" ]; then
146
echo "Must be root to run this script" >&2
151
ufw_locales="/usr/share/ufw/messages"
155
while getopts "hfid:l:v" opt
159
d) ufw_locales=`echo "$OPTARG" | sed 's#/\+$##'`;;
160
l) ufw_locale="$OPTARG";;
167
shift $(($OPTIND - 1))
169
if [ "$ufw_locale" != "*" ]; then
170
if [ "$ufw_locale" = "C" ]; then
172
elif ls -1 "$ufw_locales/$ufw_locale"*.mo >/dev/null 2>&1 ; then
173
ufw_locale="${ufw_locale}*"
176
if [ ! -d "$ufw_locales" ]; then
177
echo "'$ufw_locales' is not a directory" >&2
182
if [ "$force" != "yes" ]; then
183
echo "This script will alter your system by generating locales and running"
184
echo "various ufw commands. It will not clean up generated locales and may"
185
echo "alter your system in other ways. This should not be used on a"
186
echo -n "production system. Proceed (y|N)? "
188
if [ "$ans" != "y" ] && [ "$ans" != "Y" ]; then
194
if [ "$install" = "yes" ] && [ "$ufw_locale" != "C" ]; then
195
echo "Configuring locales..."
196
if ls -1 "$ufw_locales"/$ufw_locale.mo >/dev/null 2>&1 ; then
197
for i in `ls "$ufw_locales"/$ufw_locale.mo` ; do
198
loc=`basename $i | sed 's#\.mo$##'`
199
if ! install_langpack "$loc" ; then
200
echo "Could not install langpack for '$loc'. Skipping"
203
if ! has_locale "$loc" ; then
208
if ! install_langpack "$ufw_locale" ; then
209
echo "Could not install langpack for '$ufw_locale'. Skipping"
212
if ! has_locale "$ufw_locale" ; then
213
gen_locale "$ufw_locale"
216
echo "Done configuring locales"
221
if [ "$ufw_locale" = "C" ] || ! ls -1 "$ufw_locales"/$ufw_locale.mo >/dev/null 2>&1 ; then
222
run_tests "$ufw_locale" || echo FAIL
224
echo "Testing locales in '$ufw_locales'"
225
for i in `ls "$ufw_locales"/$ufw_locale.mo` ; do
226
loc=`basename $i | sed 's#\.mo$##'`
227
run_tests "$loc" || echo FAIL
232
echo "Test summary: $count tests, $err_count failures"
234
if [ $err_count -ne 0 ]; then