Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | # |
Gavin Howard | 7345cb9 | 2019-04-08 14:13:43 -0600 | [diff] [blame] | 3 | # Copyright (c) 2018-2019 Gavin D. Howard and contributors. |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 4 | # |
Gavin Howard | 7345cb9 | 2019-04-08 14:13:43 -0600 | [diff] [blame] | 5 | # All rights reserved. |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 6 | # |
Gavin Howard | 7345cb9 | 2019-04-08 14:13:43 -0600 | [diff] [blame] | 7 | # 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 Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 28 | # |
| 29 | |
| 30 | usage() { |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 31 | printf "usage: %s NLSPATH main_exec\n" "$0" 1>&2 |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 32 | exit 1 |
| 33 | } |
| 34 | |
Gavin Howard | d31b568 | 2019-04-09 17:22:37 -0600 | [diff] [blame] | 35 | gencatfile() { |
| 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 Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 47 | script="$0" |
| 48 | scriptdir=$(dirname "$script") |
| 49 | |
Gavin Howard | 6e70f55 | 2019-04-01 14:09:39 -0600 | [diff] [blame] | 50 | . "$scriptdir/functions.sh" |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 51 | |
Gavin Howard | f680e35 | 2019-04-01 13:28:48 -0600 | [diff] [blame] | 52 | test "$#" -ge 2 || usage |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 53 | |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 54 | nlspath="$1" |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 55 | shift |
| 56 | |
Gavin Howard | f680e35 | 2019-04-01 13:28:48 -0600 | [diff] [blame] | 57 | main_exec="$1" |
| 58 | shift |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 59 | |
Gavin Howard | 00382e9 | 2019-04-11 12:56:02 -0600 | [diff] [blame] | 60 | "$scriptdir/locale_uninstall.sh" "$nlspath" "$main_exec" |
| 61 | |
Gavin Howard | 5d0d10e | 2019-04-05 13:53:50 -0600 | [diff] [blame] | 62 | locales_dir="$scriptdir/locales" |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 63 | |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 64 | locales=$(locale -a) |
| 65 | |
Gavin Howard | 5d0d10e | 2019-04-05 13:53:50 -0600 | [diff] [blame] | 66 | for file in $locales_dir/*.msg; do |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 67 | |
Gavin Howard | 80ba7c9 | 2019-04-09 17:22:53 -0600 | [diff] [blame] | 68 | locale=$(basename "$file" ".msg") |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 69 | loc=$(gen_nlspath "$nlspath" "$locale" "$main_exec") |
Gavin Howard | f680e35 | 2019-04-01 13:28:48 -0600 | [diff] [blame] | 70 | |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 71 | if [ ! -z "${locales##*$locale*}" ]; then |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 72 | continue |
| 73 | fi |
| 74 | |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 75 | if [ -L "$file" ]; then |
Stefan Esser | c6e1814 | 2019-04-09 23:39:30 +0200 | [diff] [blame] | 76 | continue |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 77 | fi |
| 78 | |
Gavin Howard | d31b568 | 2019-04-09 17:22:37 -0600 | [diff] [blame] | 79 | gencatfile "$loc" "$file" |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 80 | |
| 81 | done |
Stefan Esser | c6e1814 | 2019-04-09 23:39:30 +0200 | [diff] [blame] | 82 | |
| 83 | for file in $locales_dir/*.msg; do |
| 84 | |
Gavin Howard | 80ba7c9 | 2019-04-09 17:22:53 -0600 | [diff] [blame] | 85 | locale=$(basename "$file" ".msg") |
Stefan Esser | c6e1814 | 2019-04-09 23:39:30 +0200 | [diff] [blame] | 86 | 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 Howard | d31b568 | 2019-04-09 17:22:37 -0600 | [diff] [blame] | 95 | |
Stefan Esser | c6e1814 | 2019-04-09 23:39:30 +0200 | [diff] [blame] | 96 | link=$(readlink "$file") |
| 97 | locale=$(basename "$link" .msg) |
Gavin Howard | d31b568 | 2019-04-09 17:22:37 -0600 | [diff] [blame] | 98 | linksrc=$(gen_nlspath "$nlspath" "$locale" "$main_exec") |
| 99 | |
Gavin Howard | 862d3a1 | 2019-04-09 17:32:24 -0600 | [diff] [blame] | 100 | if [ ! -f "$linksrc" ]; then |
Gavin Howard | d31b568 | 2019-04-09 17:22:37 -0600 | [diff] [blame] | 101 | gencatfile "$linksrc" "$link" |
| 102 | fi |
Stefan Esser | c6e1814 | 2019-04-09 23:39:30 +0200 | [diff] [blame] | 103 | |
| 104 | ln "$linksrc" "$loc" |
| 105 | fi |
| 106 | |
| 107 | done |