Monday, June 19, 2017

PATH building

Throughout UNIX configuration activities is not uncommon to have to set up environment variables for a variety of reasons, most notably for several variants of PATH searches, such as PATH, LD_LIBRARY_PATH, PKG_CONFIG_PATH and many others. In order to generalize and simplify the process it's not also uncommon to take advantage of shell scripts and in doing so the process can also be made more flexible and dynamic in terms of building these PATHs by testing for a particular system support condition.

NOTE
In building PATHs that support multiple components, between every two components there's a certain delimiter character which may vary according to different usage conventions. Sometimes the delimiter may be a ':', other times it may be a ';', but it's not necessarily restricted to these two.
For instance, let's say that on a developer system one needs to set PKG_CONFIG_PATH according to some previously known "packages" (for instance, libffi and sqlite), but constrained to the availability of these "packages" on that particular system. The essential idea of a shell script excerpt to address this scenario could be:

PKG=/opt/libffi-3.2/gnu32
if [[ -d "$PKG" ]] ; 

then

  CFG=$PKG/lib/pkgconfig
  PCP=${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
  ! [[ "$PCP" =~ "$PKG" ]] && \
    export PKG_CONFIG_PATH=$CFG$PCP


fi

PKG=/opt/sqlite-3.19.3/gnu32
if [[ -d "$PKG" ]] ; 

then

  CFG=$PKG/bin
  ! [[ "$PATH" =~
"$PKG" ]] && \
    export PATH=$CFG:$PATH

  CFG=$PKG/lib/pkgconfig
  PCP=${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
  ! [[ "$PCP" =~ "$PKG" ]] && \
    export PKG_CONFIG_PATH=$CFG$PCP


fi


In the above code, note the following points:
  
  • I'm assuming BASH as it may have been readily apparent.
      
  • I test beforehand for the existence of each "package" directory.
    ( if [[ -d ... ]] ; )
      
  • I test if the path component has already been previously set.
    ( ! [[ "$PKG_CONFIG_PATH" =~ ... ]] && ... )
      
  • If PKG_CONFIG_PATH isn't set or is empty, don't add the delimiter ':'.
    I could have done this each time to avoid future copy/paste "bugs".
    ( ${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH} )

NOTE
By the way, the above "packages" are just two out of a bunch more prerequisites to build a more recent Firefox version under a Solaris 11.3 GA / Release :-D
NOTE
In particular, the kind of the above script is typically not executable and is intended to be run as an argument to the source command in order to integrate the settings to an existing session. As such, on this kind of script, case needed, use return instead of exit.
A slightly more elaborated and fully woking example of this technique can be found on another post I've written about GNU - Build preparation.
   

Wednesday, June 7, 2017

TeX - Installation

Everybody should know about TeX, but in case you do not, perhaps you could learn more at the TeX Users Group and AMS TeX Resources | Freeware and find out that you should be looking for TeX Live after all.

You may need TeX for various reasons, from willing to write articles, papers and so on... to ultimately manually building the latest version of GCC.

A quick install document is provided, but I felt it was just partially helpful as you may agree (to some extent) by looking at my personal notes that follow.

The most convenient installation method, although very time-consuming (perhaps about 6 to 8 hours) on a severely slow or limited connection, is over the net by downloading a "bootstrap" installation script written in Perl with an optional more user-friendly GUI interface in Tcl / Tk. As such, before anything else you need to make sure you have the right Perl and Tcl / Tk packages already installed on your system. They are:
 
  • tcl-8
  • tk-8 
  • perl-512
  • perl-tk-512

Among them, the last one is not installed by default:

$ pkg info -r perl-tk-512
          Name: library/perl5/perl-tk-512
       Summary: CPAN Perl Tk module
   Description: perl-tk provides ... (GUI) widgets ...
                develop desktop applications such as buttons,
                menu, canvas, text, frame, label etc.
      Category: Development/Perl
         State: Not installed
     Publisher: solaris
       Version: 804.31
 Build Release: 5.11
        Branch: 0.175.3.0.0.30.0
Packaging Date: August 21, 2015 04:57:26 PM
          Size: 8.30 MB
          FMRI: .../perl-tk-512@804.31,...


Thus, install it:

# pkg install perl-tk-512
           Packages to install:  1
       Create boot environment: No
Create backup boot environment: No

DOWNLOAD     PKGS      FILES    XFER (MB)   SPEED
Completed     1/1    763/763      2.7/2.7  166k/s

PHASE                                          ITEMS
Installing new actions                       781/781
Updating package state database                 Done
Updating package cache                           0/0
Updating image state                            Done
Creating fast lookup database                   Done
Reading search index                            Done
Updating search index                            1/1
Updating package cache                           2/2


By the way, you may need to know that the man pages are not integrated by default, so in case you decide you need them, even without integrating them into the man system, you can explicitly specify their path; for instance:

$ man -M /usr/perl5/5.12/man Tk::Photo

As an alternative you may also consider manually building newer versions of Perl and Tcl / Tk, which can help avoid some issues as I shall present soon.

Now you should look for a suitable TeXLive download mirror, but you'd better check if a given mirror offers the release you're insterest on. The mirror autodirection feature fails to do so, probably assuming that eventually all mirrors would be in sync when they actually aren't. For instance, today, June 2017, there are mirrors still offering the old 2016 release, instead of the more updated 2017 one. Unfortunately, this requires a manual verification, which may be tedious until you manually find the right one. Visit the mirrors list page, pick a reasonable candidate and access it for manual verification. Once there, go to:
systems/texlive/tlnet
Then download to /tmp the bootstrap installation script for Unix:
install-tl-unx.tar.gz
Extract it and check its version:

$ cd /tmp
$ tar xf install-tl-unx.tar.gz
$ cd install-tl-...
$ head -1 release-texlive.txt
TeX Live (http://tug.org/texlive) version 2017

In the above example I was lucky to have found what I was looking for right at the first shot, but, as said, that may not be the case if you are on a "far abroad region"...

Assuming I have picked out the right mirror by verifying the downloaded bootstrap installation script from it, the next step is to fix a small but annoying bug in the GUI version of it.

In the tar.gz-extracted directory-tree pay attention to the following files:

$ pwd
/tmp/install-tl-...

$ ll tlpkg/installer
total ...
-rw-r--r--  ...  tl-tray-menu.ini
-rwxr-xr-x  ...  tl-cmd.bat
-rw-r--r--  ...  install-tl.html
-rw-r--r--  ...  COPYING.MinGW-runtime.txt
-rw-r--r--  ...  texlive.png
-rw-r--r--  ...  installer-options.txt
-rw-r--r--  ...  install-menu-wizard.pl
-rw-r--r--  ...  install-menu-perltk.pl
-rw-r--r--  ...  ctan-mirrors.pl
-rw-r--r--  ...  install-menu-text.pl
-rw-r--r--  ...  tracked-install.pl
-rwxr-xr-x  ...  config.guess
drwxr-xr-x  ...  xz
drwxr-xr-x  ...  wget


Fixing the GUI

You must create a copy of texlive.png converted to a supported BMP version (the default version 4 isn't supported!), because neither the PNG, nor the JPG options are in fact supported by the installed Tcl/Tk versions available under Solaris, unfortunately. Check the ImageMagick suite homepage for more detail, in particular, the supported types (formats).

$ convert texlive.png bmp3:texlive.bmp

Next you need to change the below highlighted portions of the indicated source lines of the install-menu-perltk.pl. You must comment out (#) the initial requirement for the PNG module and substitute references to "png" for "bmp" instead.

$ grep -n -i png install-menu-perltk.pl
24:require Tk::PNG;
206:  my $img = $fl->Photo(-format => 'png',
207:  -file => "$::installerdir/tlpkg/installer/texlive.png");


Upon completing the fix you'll have:

$ grep -n -i png install-menu-perltk.pl
24:#require Tk::PNG;
206:  my $img = $fl->Photo(-format => 'bmp',
207:  -file => "$::installerdir/tlpkg/installer/texlive.bmp");


Next you need to setup a a site-wide (local) installation directory. By default this is /usr/local but under Solaris this translates to /opt. The newly created /opt subdirectory should intially be given a mode and group to which the (non-root) regular user performing the installation belongs to and be granted write access, of course.

# mkdir -m 775 /opt/texlive
# chgrp staff /opt/texlive

Another detail to pay attention to at this point is the umask setting. One should consider if it's Ok or not the default 0022 mask. Perhaps some other mask value would be more appropriate, for instance, 002, which you would keep granting write access to the group (staff as in the above example) previously set on /opt/textlive:

$ umask 002

Now you should finally be ready to start an installation attempt:
(again, note that I don't do it as root for trying to reduce risks)
(note that mirror-url must end with /systems/texlive/tlnet)

$ cd /tmp/install-tl-...
$ ./install-tl --location ...mirror-url... -gui=perltk

You should see something similar to:


You should select the desired Binary system(s):


Then you should select the desired Installation collection(s):
(suggestion: English, French, German and your native language)


Then you should select the previously created /opt/texlive directory as the TEXTDIR (the main TeX directory) and accept all other defaults, except perhaps for the Default paper size, and then click on Install TeX Live button. Make sure your system won't sleep or hybernate after a while and take your time in doing other amazing things! :-)

NOTE
In case, the installation fails, my personal experience isn't reassuring. My attempts to resume from a failed install never succeed in picking up from where the failure last happened. I had always to painfully start over from the scratch!

Upon a successful installation the last messages you'll see in the download dialog as in the below image will show the duration and the a few post-installation instructions:


 The post-installation instructions are:
Welcome to TeX Live!

Documentation links: /opt/texlive/2017/index.html
The TeX Live web site (https://tug.org/texlive/)
contains updates and corrections.

TeX Live is a joint project of the TeX user groups around the world;
please consider supporting it by joining the group best for you.
The list of groups is on the web at https://tug.org/usergroups.html.

Add /opt/texlive/2017/texmf-dist/doc/man to MANPATH.
Add /opt/texlive/2017/texmf-dist/doc/info to INFOPATH.
Most importantly, add /opt/texlive/2017/bin/i386-solaris
to your PATH for current and future sessions.
NOTE
You should repeat the previously described "Fixing the GUI" procedure on the contents of /opt/texlive/2017/tlpkg/installer to make sure it will work correctly as needed.
You should now put the desired binary, man and info path in their respective PATHs as needed and if you didn't follow my previous suggestions, then you may attempt to manually adjust ownership and mode troughout the entire /opt/texlive directory-tree.

$ export PATH=/opt/texlive/2017/bin/x86_64-solaris/:$PATH

Now, the Testing the Installation documentation topic may be useful. It can be found at file:///opt/texlive/2017/texmf-dist/doc/texlive/texlive-en/texlive-en.html#x1-380003.5.

$ tex --version
TeX 3.14159265 (TeX Live 2017)
kpathsea version 6.2.3
Copyright 2017 D.E. Knuth.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the TeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the TeX source.
Primary author of TeX: D.E. Knuth.


LaTeX

$ latex sample2e.tex
... pdfTeX ... (TeX Live 2017) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
(/.../2017/texmf-dist/tex/latex/base/sample2e.tex
LaTeX2e <2017-04-15>
Babel <3 .10=""> and hyphenation patterns ... loaded.
(/.../2017/texmf-dist/tex/latex/base/article.cls
Doc... Class: article 2014/09/29 v1.4h Std LaTeX ...
(/.../2017/texmf-dist/tex/latex/base/size10.clo))
No file sample2e.aux.
(/.../2017/texmf-dist/tex/latex/base/omscmr.fd) [1] [2] [3]
(./sample2e.aux) )
Output written on sample2e.dvi (3 pages, 7484 bytes).
Transcript written on sample2e.log.


Now there's a small caveat: Solaris provides a more updated library libXaw.so.7 than the hard-coded libXaw.so.5 required by xdvi script which ultimately invokes the xdvi-xaw binary.

$ file /opt/texlive/2017/bin/x86_64-solaris/xdvi-xaw
/.../2017/bin/x86_64-solaris/xdvi-xaw: ELF 64-bit ... AMD64


$ ldd /opt/texlive/2017/bin/x86_64-solaris/xdvi-xaw
    libXaw.so.5 =>     (file not found)
    libXmu.so.4 =>     /usr/lib/64/libXmu.so.4
    ...

    libc.so.1 =>     /lib/64/libc.so.1
    libxcb.so.1 =>     /usr/lib/amd64/libxcb.so.1
    ...

    libXau.so.6 =>     /usr/lib/64/libXau.so.6
    libXdmcp.so.6 =>     /usr/lib/64/libXdmcp.so.6
    ...

    libXevie.so.1 =>     /usr/lib/64/libXevie.so.1
    libXss.so.1 =>     /usr/lib/64/libXss.so.1


If not amended, this will cause the following issue:

$ xdvi sample2e.dvi
ld.so.1: xdvi-xaw: fatal: libXaw.so.5: open failed:
No such file or directory
Killed


The more updated available libraries are found on:

$ file /usr/lib/libXaw.so.7
/usr/lib/libXaw.so.7: ELF 32-bit ... 80386 ...


$ file /usr/lib/64/libXaw.so.7
/usr/lib/64/libXaw.so.7: ELF 64-bit ... AMD64 ...


You may notice that there are symbolic links to them, perhaps in an attempt to prevent issues such as the above. But, in this case, they are not sufficient. Unfortunately, for now I'm not aware of any adjust other than the following somewhat crude work-around:

# cd /usr/lib
# ln -s libXaw.so libXaw.so.5

# cd /usr/lib/64
# ln -s libXaw.so libXaw.so.5

Now I can continue with the post-installation verifications:
(in spite of all File|... menu options of xdvik exhibit failure)

$ xdvi sample2e.dvi
Warning: Missing charsets in String to FontSet conversion



PDFLaTeX

$ pdflatex sample2e.tex
... pdfTeX ... (TeX Live 2017) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
...
Output written on sample2e.pdf (3 pages, 136717 bytes).
Transcript written on sample2e.log.


$ evince sample2e.pdf &


$ gs -r96 sample2e.pdf -c quit


XeTeX

# d1=/.../2017/texmf-var/fonts/conf/texlive-fontconfig.conf
# d2=/etc/fonts/conf.d/09-texlive.conf
# ln -s $d1 $d2

# fc-cache -fsv
...
/var/cache/fontconfig: cleaning cache directory
fc-cache: succeeded


$ xetex opentype-info.tex
... XeTeX ... (TeX Live 2017) (preloaded format=xetex)
 restricted \write18 enabled.
entering extended mode
...
Output written on opentype-info.pdf (2 pages).
Transcript written on opentype-info.log.