3 # SPDX-License-Identifier: BSD-2-Clause
5 # Copyright (c) 2018-2020 Gavin D. Howard and contributors.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
10 # * Redistributions of source code must retain the above copyright notice, this
11 # list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
31 printf "usage: %s NLSPATH main_exec [DESTDIR]\n" "$0" 1>&2
43 mkdir -p $(dirname "$_gencatfile_loc")
44 gencat "$_gencatfile_loc" "$_gencatfile_file" > /dev/null 2>&1
49 _localeexists_locales="$1"
52 _localeexists_locale="$1"
55 _localeexists_destdir="$1"
58 if [ "$_localeexists_destdir" != "" ]; then
59 _localeexists_char="@"
60 _localeexists_locale="${_localeexists_locale%%_localeexists_char*}"
61 _localeexists_char="."
62 _localeexists_locale="${_localeexists_locale##*$_localeexists_char}"
65 test ! -z "${_localeexists_locales##*$_localeexists_locale*}"
74 if [ "$_splitpath_path" = "${_splitpath_path#/}" ]; then
75 printf 'Must use absolute paths\n'
79 if [ "${_splitpath_path#\n*}" != "$_splitpath_path" ]; then
86 while [ "$_splitpath_path" != "/" ]; do
87 _splitpath_item=$(basename "$_splitpath_path")
88 _splitpath_list=$(printf '\n%s%s' "$_splitpath_item" "$_splitpath_list")
89 _splitpath_path=$(dirname "$_splitpath_path")
92 if [ "$_splitpath_list" != "/" ]; then
93 _splitpath_list="${_splitpath_list#?}"
96 printf '%s' "$_splitpath_list"
107 _relpath_nl=$(printf '\nx')
108 _relpath_nl="${_relpath_nl%x}"
110 _relpath_splitpath1=`splitpath "$_relpath_path1"`
111 _relpath_splitpath2=`splitpath "$_relpath_path2"`
114 _relpath_temp1="$_relpath_splitpath1"
118 for _relpath_part in $_relpath_temp1; do
120 _relpath_temp2="${_relpath_splitpath2#$_relpath_part$_relpath_nl}"
122 if [ "$_relpath_temp2" = "$_relpath_splitpath2" ]; then
126 _relpath_splitpath2="$_relpath_temp2"
127 _relpath_splitpath1="${_relpath_splitpath1#$_relpath_part$_relpath_nl}"
131 for _relpath_part in $_relpath_splitpath2; do
132 _relpath_path="../$_relpath_path"
135 _relpath_path="${_relpath_path%../}"
137 for _relpath_part in $_relpath_splitpath1; do
138 _relpath_path="$_relpath_path$_relpath_part/"
141 _relpath_path="${_relpath_path%/}"
145 printf '%s\n' "$_relpath_path"
149 scriptdir=$(dirname "$script")
151 . "$scriptdir/functions.sh"
153 test "$#" -ge 2 || usage
161 if [ "$#" -ge 1 ]; then
168 "$scriptdir/locale_uninstall.sh" "$nlspath" "$main_exec" "$destdir"
170 locales_dir="$scriptdir/locales"
172 # What this does is if installing to a package, it installs all locales that
173 # match supported charsets instead of installing all directly supported locales.
174 if [ "$destdir" = "" ]; then
180 for file in $locales_dir/*.msg; do
182 locale=$(basename "$file" ".msg")
183 loc=$(gen_nlspath "$destdir/$nlspath" "$locale" "$main_exec")
185 localeexists "$locales" "$locale" "$destdir"
188 if [ "$err" -eq 0 ]; then
192 if [ -L "$file" ]; then
196 gencatfile "$loc" "$file"
200 for file in $locales_dir/*.msg; do
202 locale=$(basename "$file" ".msg")
203 loc=$(gen_nlspath "$destdir/$nlspath" "$locale" "$main_exec")
205 localeexists "$locales" "$locale" "$destdir"
208 if [ "$err" -eq 0 ]; then
212 mkdir -p $(dirname "$loc")
214 if [ -L "$file" ]; then
216 link=$(readlink "$file")
217 linkdir=$(dirname "$file")
218 locale=$(basename "$link" .msg)
219 linksrc=$(gen_nlspath "$nlspath" "$locale" "$main_exec")
220 relloc="${loc##$destdir/}"
221 rel=$(relpath "$linksrc" "$relloc")
223 if [ ! -f "$destdir/$linksrc" ]; then
224 gencatfile "$destdir/$linksrc" "$linkdir/$link"