File: refresh-unames.sh

package info (click to toggle)
uniutils 2.28-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,032 kB
  • sloc: ansic: 49,905; sh: 1,168; awk: 55; makefile: 18
file content (34 lines) | stat: -rw-r--r-- 1,160 bytes parent folder | download
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
#! /usr/bin/env bash
# Updates ./unames.c as per UnicodeData.txt, preserving original .c file
# Just a shell wrapper around Bill Poser's awk script in original source
# By gsr.bugs infernal-iceberg com for Debian

set -Eeuo pipefail  # bash, not all supported with (da)sh

DEBIAN_DFILE=/usr/share/unicode/UnicodeData.txt
USER_DFILE=${1:-"./UnicodeData.txt"}
if [ -f "$USER_DFILE" ] ; then
  echo "Using $USER_DFILE for ranges"
  DFILE="$USER_DFILE"
elif [ -f "$DEBIAN_DFILE" ] ; then
  echo "Using OS installed UnicodeData.txt as fallback for names"
  DFILE="$DEBIAN_DFILE"
else
  echo "Usage: $0 [path/to/new/UnicodeData.txt]"
  echo "Alternatively try 'sudo apt install unicode-data'"
  exit 1
fi

SOURCE="./unames.c"

if [ -f "${SOURCE}-orig" ] ; then
  echo "Backup ${SOURCE}-orig exists, writing new version to $SOURCE"
else
  echo "Backing up $SOURCE to ${SOURCE}-orig, then writing to $SOURCE"
  cp -a "$SOURCE" "${SOURCE}-orig" || { echo Problem with cp ; exit 2 ; }
fi

# We have a backup, so recreate in full with the awk script
awk -f genunames.awk < "${DFILE}" > "${SOURCE}"

echo "You may want to run 'diff -u ${SOURCE}-orig ${SOURCE}' to verify"