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
|
#!/bin/bash
#
# Based upon Debian's locale-gen, fetched from glibc_2.3.6-7.diff.gz
#
unset POSIXLY_CORRECT
umask 022
argv0=${0##*/}
source /etc/init.d/functions.sh || {
echo "${argv0}: Could not source /etc/init.d/functions.sh!" 1>&2
exit 1
}
show_usage() {
cat <<-EOF
Usage: ${HILITE}${argv0}${NORMAL} ${GOOD}[options]${NORMAL}
Generate locales based upon the config file /etc/locale.gen.
${HILITE}Options:${NORMAL}
${GOOD}-k, --keep${NORMAL} Don't nuke existing locales
${GOOD}-d, --destdir <dir>${NORMAL} Use locale data in specified DESTDIR tree
${GOOD}-c, --config <config>${NORMAL} Use specified config instead of default locale.gen
${GOOD}-l, --list${NORMAL} List all the locales to be generated
${GOOD}-q, --quiet${NORMAL} Only show errors
${GOOD}-V, --version${NORMAL} Meaningless version information
${GOOD}-h, --help${NORMAL} Show this help cruft
For more info, see the ${HILITE}locale-gen${NORMAL}(1) and ${HILITE}locale.gen${NORMAL}(8) manpages.
EOF
[[ -z $@ ]] && exit 0
echo ""
eerror "Unknown option '$1'"
exit 1
}
show_version() {
local cvsver="$Header: /var/cvsroot/gentoo/src/patchsets/glibc/extra/locale/locale-gen,v 1.2 2006/04/17 16:48:56 vapier Exp $"
cvsver=${cvsver##*locale-gen-}
echo "locale-gen-${cvsver%%,v *}"
exit 0
}
KEEP=""
DESTDIR=""
CONFIG=""
JUST_LIST=""
QUIET=0
while [[ -n $1 ]] ; do
case $1 in
-k|--keep|--keep-existing) KEEP=$1;;
-d|--destdir) shift; DESTDIR=$1;;
-c|--config) shift; CONFIG=$1;;
-l|--list) JUST_LIST=$1;;
-q|--quiet) ((++QUIET));;
-V|--version) show_version;;
-h|--help) show_usage;;
*) show_usage $1;;
esac
shift
done
ROOT=${ROOT:-/}
[[ ${ROOT} != */ ]] && ROOT="${ROOT}/"
if [[ -n ${DESTDIR} ]] && [[ ${ROOT} != "/" ]] ; then
eerror "DESTDIR and ROOT are mutually exclusive options"
exit 1
fi
if [[ ${ROOT} != "/" ]] ; then
einfo "Using locale.gen from ROOT ${ROOT}etc/"
fi
if [[ -n ${DESTDIR} ]] ; then
einfo "Building locales in DESTDIR ${DESTDIR}"
else
DESTDIR=${ROOT}
fi
# XXX: should fix this ...
if [[ ${DESTDIR} != "/" || ${ROOT} != "/" ]] ; then
eerror "Sorry, but DESTDIR/ROOT support is incomplete at this time."
exit 0
fi
LOCALEGEN=${CONFIG:-${ROOT}etc/locale.gen}
LOCALES=${DESTDIR}usr/share/i18n/locales
CHARMAPS=${DESTDIR}usr/share/i18n/charmaps
SUPPORTED=${DESTDIR}usr/share/i18n/SUPPORTED
ALIAS=${DESTDIR}usr/share/locale/locale.alias
LOCALEDIR=${DESTDIR}$(localedef --help | sed -n -e '/locale path/{s|.* : ||;s|:.*||;p}')
[[ -s ${LOCALEGEN} ]] || exit 0
locales_to_generate=$(sed \
-e 's:#.*::' \
-e '/^[[:space:]]*$/d' \
"${LOCALEGEN}")
total=$(echo "${locales_to_generate}" | wc -l)
if [[ -z ${locales_to_generate} ]] ; then
[[ ${QUIET} -eq 0 ]] && [[ -z ${JUST_LIST} ]] && \
ewarn "No locales found"
exit 0
fi
mkdir -p "${LOCALEDIR}"
if [[ -z ${KEEP} ]] ; then
# Remove all old locale dir and locale-archive before generating new
# locale data.
rm -rf "${LOCALEDIR}"/* || true
fi
[[ ${QUIET} -eq 0 ]] && [[ -z ${JUST_LIST} ]] && \
einfo "Generating ${total} locales (this might take a while)"
ret=0
cnt=0
while read locale charmap ; do
((++cnt))
# XXX: if we wanted to, we could check existence of
# ${LOCALES}/${locale} and ${CHARMAPS}/${charmap}
# this would fail for things like "en_US.UTF8", but
# in that case we could fall back to checking the
# SUPPORTED file ... then again, the localedef
# below will abort nicely for us ...
if [[ -z ${locale} || -z ${charmap} ]] ; then
eerror "Bad entry in locale.gen: '${locale} ${charmap}'; skipping"
continue
fi
# These funky sed's are copied from the glibc localedata/Makefile
disp=$(echo ${locale} | sed 's/\([^.\@]*\).*/\1/')
disp=${disp}.${charmap}
disp=${disp}$(echo ${locale} | sed 's/\([^\@]*\)\(\@.*\)*/\2/')
if [[ -f ${LOCALES}/${locale} ]] ; then
input=${locale}
else
input=$(echo ${locale} | sed 's/\([^.]*\)[^@]*\(.*\)/\1\2/')
fi
if [[ -z ${JUST_LIST} ]] ; then
[[ ${QUIET} -eq 0 ]] && ebegin " (${cnt}/${total}) Generating ${disp}"
localedef --no-archive -c \
-i "${input}" \
-f "${charmap}" \
-A "${ALIAS}" \
"${locale}"
my_ret=$?
((ret+=my_ret))
[[ ${QUIET} -eq 0 ]] && eend ${my_ret}
else
echo "${disp}"
fi
done < <(echo "${locales_to_generate}")
[[ ${QUIET} -eq 0 ]] && [[ -z ${JUST_LIST} ]] && \
einfo "Generation complete"
exit ${ret}
|