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.
34 printf "usage: %s NLSPATH main_exec [DESTDIR]\n" "$0" 1>&2
46 mkdir -p $(dirname "$_gencatfile_loc")
47 gencat "$_gencatfile_loc" "$_gencatfile_file" > /dev/null 2>&1
52 _localeexists_locales="$1"
55 _localeexists_locale="$1"
58 _localeexists_destdir="$1"
61 if [ "$_localeexists_destdir" != "" ]; then
62 _localeexists_char="@"
63 _localeexists_locale="${_localeexists_locale%%_localeexists_char*}"
64 _localeexists_char="."
65 _localeexists_locale="${_localeexists_locale##*$_localeexists_char}"
68 test ! -z "${_localeexists_locales##*$_localeexists_locale*}"
77 if [ "$_splitpath_path" = "${_splitpath_path#/}" ]; then
78 printf 'Must use absolute paths\n'
82 if [ "${_splitpath_path#\n*}" != "$_splitpath_path" ]; then
89 while [ "$_splitpath_path" != "/" ]; do
90 _splitpath_item=$(basename "$_splitpath_path")
91 _splitpath_list=$(printf '\n%s%s' "$_splitpath_item" "$_splitpath_list")
92 _splitpath_path=$(dirname "$_splitpath_path")
95 if [ "$_splitpath_list" != "/" ]; then
96 _splitpath_list="${_splitpath_list#?}"
99 printf '%s' "$_splitpath_list"
110 _relpath_nl=$(printf '\nx')
111 _relpath_nl="${_relpath_nl%x}"
113 _relpath_splitpath1=`splitpath "$_relpath_path1"`
114 _relpath_splitpath2=`splitpath "$_relpath_path2"`
117 _relpath_temp1="$_relpath_splitpath1"
121 for _relpath_part in $_relpath_temp1; do
123 _relpath_temp2="${_relpath_splitpath2#$_relpath_part$_relpath_nl}"
125 if [ "$_relpath_temp2" = "$_relpath_splitpath2" ]; then
129 _relpath_splitpath2="$_relpath_temp2"
130 _relpath_splitpath1="${_relpath_splitpath1#$_relpath_part$_relpath_nl}"
134 for _relpath_part in $_relpath_splitpath2; do
135 _relpath_path="../$_relpath_path"
138 _relpath_path="${_relpath_path%../}"
140 for _relpath_part in $_relpath_splitpath1; do
141 _relpath_path="$_relpath_path$_relpath_part/"
144 _relpath_path="${_relpath_path%/}"
148 printf '%s\n' "$_relpath_path"
152 scriptdir=$(dirname "$script")
154 . "$scriptdir/functions.sh"
158 while getopts "l" opt; do
161 l) all_locales=1 ; shift ;;
162 ?) usage "Invalid option $opt" ;;
167 test "$#" -ge 2 || usage
175 if [ "$#" -ge 1 ]; then
182 "$scriptdir/locale_uninstall.sh" "$nlspath" "$main_exec" "$destdir"
184 locales_dir="$scriptdir/locales"
186 # What this does is if installing to a package, it installs all locales that
187 # match supported charsets instead of installing all directly supported locales.
188 if [ "$destdir" = "" ]; then
194 for file in $locales_dir/*.msg; do
196 locale=$(basename "$file" ".msg")
198 if [ "$all_locales" -eq 0 ]; then
200 localeexists "$locales" "$locale" "$destdir"
203 if [ "$err" -eq 0 ]; then
208 if [ -L "$file" ]; then
212 loc=$(gen_nlspath "$destdir/$nlspath" "$locale" "$main_exec")
214 gencatfile "$loc" "$file"
218 for file in $locales_dir/*.msg; do
220 locale=$(basename "$file" ".msg")
222 if [ "$all_locales" -eq 0 ]; then
224 localeexists "$locales" "$locale" "$destdir"
227 if [ "$err" -eq 0 ]; then
232 loc=$(gen_nlspath "$destdir/$nlspath" "$locale" "$main_exec")
234 mkdir -p $(dirname "$loc")
236 if [ -L "$file" ]; then
238 link=$(readlink "$file")
239 linkdir=$(dirname "$file")
240 locale=$(basename "$link" .msg)
241 linksrc=$(gen_nlspath "$nlspath" "$locale" "$main_exec")
242 relloc="${loc##$destdir/}"
243 rel=$(relpath "$linksrc" "$relloc")
245 if [ ! -f "$destdir/$linksrc" ]; then
246 gencatfile "$destdir/$linksrc" "$linkdir/$link"