Hello.

Today I finally took the time to figure out how to install groff fonts using
the shell script https://www.schaffter.ca/mom/bin/install-font.sh .

It was way easier than following the manual steps.

In doing so I made some changes to script that made it easier for me to
use.  I'm sending this e-mail so folks can look at the changes and see
if they would be useful in general.

I changed the documentation of the -l and -s options to refer to the
prefixes /usr/local/share/groff and /usr/share/groff respectively
because those are the directories they actually use.

I added a -P option that lets you specify the prefix to use.  I often
install software into places like /sw/versions/groff/git (so I can
have multiple versions of software installed), which means
that the I'd specify "-P /sw/versions/groff/git/share/groff".

I added a -n option that stops the source font file from being
installed anywhere.  This is useful if you don't have
/usr/local/share/fonts/truetype or /usr/local/share/fonts/opentype or
/usr/local/share/fonts/type1, which, if you didn't specify -C and
depending on the type of font file, is where the source file is copied
to.  (For instance, on my macOS laptop, I've usually already got the
source font file in ~/Library/Fonts, so I don't need to copy it
anywhere.)

I changed the script so it checks if has write access to the
prefix directory specified, rather than checking if it is running as
root, because if you've installed groff into a location you have
access to as a normal user it will be writable.  And if you are
running it as root it will also be writable.  I also moved the check
after the parsing of the command line options, so it uses the user
specified prefix directory, whether that was set with -l or -s.

I've attached the patch.

Also, wouldn't this script be useful to include in the groff
distribution?

diff -Naur old/install-font.sh new/install-font.sh
--- old/install-font.sh 2020-04-01 16:11:12.000000000 -0400
+++ new/install-font.sh 2020-04-27 22:27:09.204599228 -0400
@@ -33,7 +33,7 @@
   printf <<EOF \
 "USAGE:
 
-    install-font.sh [-hHlscp] [-C \033[4mdir\033[0m] [-F \033[4mfamily\033[0m] 
\
+    install-font.sh [-hHlscpn] [-P \033[4mdir\033[0m] [-C \033[4mdir\033[0m] 
[-F \033[4mfamily\033[0m] \
 [-f \033[4mgroff fontname\033[0m] file1 file2 ...
 
 DESCRIPTION:
@@ -79,9 +79,12 @@
 
     -H  Long help.
 
-    -l  Assume prefix /usr/local/ for all directories. (default)
+    -l  Assume prefix /usr/local/share/groff for all directories. (default)
 
-    -s  Assume prefix /usr/ for all directories.
+    -s  Assume prefix /usr/share/groff for all directories.
+
+    -P  \033[4mdir\033[0m
+        Assume prefix \033[4mdir\033[0m for all directories.
 
     -c  Copy file(s) named on the command line to a system-accessible
         location.  If neither -s nor -C is given, copy to the family
@@ -93,6 +96,9 @@
         If neither -c nor -C is given, a prompt asks whether to copy
         the file(s) named on the command line.
 
+    -n  Don't copy file(s) named on the command line to a system-accessible
+        location.
+
     -d  Make font available to gropdf.
 
     -D  Do not make font available to gropdf.
@@ -158,18 +164,6 @@
   ;;
 esac
 
-# need write access to /usr/ and /usr/local/
-
-if [ "$UID" -ne "$ROOT_UID" ] ; then
-  scriptname=`basename $0`
-  printf \
-"Superuser priviledges required.\nRerun as \
-'\033[33msudo ${scriptname} \033[4margs\033[0m' \
-or \
-'\033[33msu root -c \"${scriptname} \033[4margs\033[0m\033[33m\"\033[0m'\n"
-  exit 126
-fi
-
 # if fontforge not installed, no point going any further
 
 type fontforge > /dev/null 2>&1 || { 
@@ -471,7 +465,7 @@
   :
 }
 
-while getopts ":C:cdDF:f:hHlps" opt
+while getopts ":C:cndDF:f:hHlpP:s" opt
 do
   case "$opt" in
     c)
@@ -484,6 +478,9 @@
       copy_dir=${OPTARG}
       [ -d ${copy_dir} ] || error no_dir
     ;;
+    n)
+      dont_copy=yes
+    ;;
     d)
       install_in_devpdf=yes 
     ;;
@@ -520,6 +517,11 @@
     l)
       loc_or_sysdir=/usr/local/share/groff
     ;;
+    P)
+      option=P
+      check_optarg
+      loc_or_sysdir=${OPTARG}
+    ;;
     p)
       alias mv='mv -i'
       alias ln='ln -i'
@@ -550,6 +552,19 @@
   exit 1
 }
 
+if [ ! -w "$loc_or_sysdir" ] ; then
+  # need write access to $loc_or_sysdir
+
+  scriptname=`basename $0`
+  printf \
+"You don't have write access to ${loc_or_sysdir}
+Superuser priviledges required.\nRerun as \
+'\033[33msudo ${scriptname} \033[4margs\033[0m' \
+or \
+'\033[33msu root -c \"${scriptname} \033[4margs\033[0m\033[33m\"\033[0m'\n"
+  exit 126
+fi
+
 devps=${loc_or_sysdir}/${version}/font/devps
 devpdf=${loc_or_sysdir}/${version}/font/devpdf
 site_font_devps=${loc_or_sysdir}/site-font/devps
@@ -629,24 +644,25 @@
 
 # copy input file to a system or named directory
 
-  if [ ! "$copy_orig" ] ; then
-    printf \
-"Copy \033[36m${file}\033[0m to ${copy_dir}/${family}/?\n  (y/n; default = n) "
-    read copy_file
+  if [ ! "$dont_copy" ] ; then
+    if [ ! "$copy_orig" ] ; then
+      printf \
+        "Copy \033[36m${file}\033[0m to ${copy_dir}/${family}/?\n  (y/n; 
default = n) "
+      read copy_file
 
-    case "$copy_file" in
-      Y | y | YES | Yes | yes)
-        copy_file
-      ;;
-      * )
-        printf \
-"Install \033[36m${file}\033[0m manually to make it available system-wide.\n"
-      ;;
-    esac
-  else
-    copy_file
+      case "$copy_file" in
+        Y | y | YES | Yes | yes)
+          copy_file
+        ;;
+        * )
+          printf \
+  "Install \033[36m${file}\033[0m manually to make it available system-wide.\n"
+        ;;
+      esac
+    else
+      copy_file
+    fi
   fi
-
   unset append_style
   unset ext
   unset font
-- 
T. Kurt Bond, tkurtb...@gmail.com

Reply via email to