blob: dfe7fe3e5ea518b30287523738eaa39e4018198e [file] [log] [blame]
Gavin Howard50080252019-02-20 15:27:43 -07001#! /bin/sh
2#
Gavin Howard7345cb92019-04-08 14:13:43 -06003# Copyright (c) 2018-2019 Gavin D. Howard and contributors.
Gavin Howard50080252019-02-20 15:27:43 -07004#
Gavin Howard7345cb92019-04-08 14:13:43 -06005# All rights reserved.
Gavin Howard50080252019-02-20 15:27:43 -07006#
Gavin Howard7345cb92019-04-08 14:13:43 -06007# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are met:
9#
10# * Redistributions of source code must retain the above copyright notice, this
11# list of conditions and the following disclaimer.
12#
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.
16#
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.
Gavin Howard50080252019-02-20 15:27:43 -070028#
29
30usage() {
Gavin Howardaea5bdb2019-04-09 09:01:15 -060031 printf "usage: %s NLSPATH main_exec\n" "$0" 1>&2
Gavin Howard50080252019-02-20 15:27:43 -070032 exit 1
33}
34
Gavin Howardd31b5682019-04-09 17:22:37 -060035gencatfile() {
36
37 local loc="$1"
38 shift
39
40 local file="$1"
41 shift
42
43 mkdir -p $(dirname "$loc")
44 gencat "$loc" "$file" > /dev/null 2>&1
45}
46
Gavin Howard50080252019-02-20 15:27:43 -070047script="$0"
48scriptdir=$(dirname "$script")
49
Gavin Howard6e70f552019-04-01 14:09:39 -060050. "$scriptdir/functions.sh"
Gavin Howard50080252019-02-20 15:27:43 -070051
Gavin Howardf680e352019-04-01 13:28:48 -060052test "$#" -ge 2 || usage
Gavin Howard50080252019-02-20 15:27:43 -070053
Gavin Howardaea5bdb2019-04-09 09:01:15 -060054nlspath="$1"
Gavin Howard50080252019-02-20 15:27:43 -070055shift
56
Gavin Howardf680e352019-04-01 13:28:48 -060057main_exec="$1"
58shift
Gavin Howard50080252019-02-20 15:27:43 -070059
Gavin Howard00382e92019-04-11 12:56:02 -060060"$scriptdir/locale_uninstall.sh" "$nlspath" "$main_exec"
61
Gavin Howard5d0d10e2019-04-05 13:53:50 -060062locales_dir="$scriptdir/locales"
Gavin Howard50080252019-02-20 15:27:43 -070063
Gavin Howardaea5bdb2019-04-09 09:01:15 -060064locales=$(locale -a)
65
Gavin Howard5d0d10e2019-04-05 13:53:50 -060066for file in $locales_dir/*.msg; do
Gavin Howard50080252019-02-20 15:27:43 -070067
Gavin Howard80ba7c92019-04-09 17:22:53 -060068 locale=$(basename "$file" ".msg")
Gavin Howardaea5bdb2019-04-09 09:01:15 -060069 loc=$(gen_nlspath "$nlspath" "$locale" "$main_exec")
Gavin Howardf680e352019-04-01 13:28:48 -060070
Gavin Howardaea5bdb2019-04-09 09:01:15 -060071 if [ ! -z "${locales##*$locale*}" ]; then
Gavin Howardaea5bdb2019-04-09 09:01:15 -060072 continue
73 fi
74
Gavin Howard50080252019-02-20 15:27:43 -070075 if [ -L "$file" ]; then
Stefan Esserc6e18142019-04-09 23:39:30 +020076 continue
Gavin Howardaea5bdb2019-04-09 09:01:15 -060077 fi
78
Gavin Howardd31b5682019-04-09 17:22:37 -060079 gencatfile "$loc" "$file"
Gavin Howard50080252019-02-20 15:27:43 -070080
81done
Stefan Esserc6e18142019-04-09 23:39:30 +020082
83for file in $locales_dir/*.msg; do
84
Gavin Howard80ba7c92019-04-09 17:22:53 -060085 locale=$(basename "$file" ".msg")
Stefan Esserc6e18142019-04-09 23:39:30 +020086 loc=$(gen_nlspath "$nlspath" "$locale" "$main_exec")
87
88 if [ ! -z "${locales##*$locale*}" ]; then
89 continue
90 fi
91
92 mkdir -p $(dirname "$loc")
93
94 if [ -L "$file" ]; then
Gavin Howardd31b5682019-04-09 17:22:37 -060095
Stefan Esserc6e18142019-04-09 23:39:30 +020096 link=$(readlink "$file")
97 locale=$(basename "$link" .msg)
Gavin Howardd31b5682019-04-09 17:22:37 -060098 linksrc=$(gen_nlspath "$nlspath" "$locale" "$main_exec")
99
Gavin Howard862d3a12019-04-09 17:32:24 -0600100 if [ ! -f "$linksrc" ]; then
Gavin Howardd31b5682019-04-09 17:22:37 -0600101 gencatfile "$linksrc" "$link"
102 fi
Stefan Esserc6e18142019-04-09 23:39:30 +0200103
104 ln "$linksrc" "$loc"
105 fi
106
107done