\documentclass[11pt, oneside]{amsart}
\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper}                   % ... or a4paper or a5paper or ... 
%\geometry{landscape}                % Activate for for rotated page geometry
\usepackage[parfill]{parskip}    % Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{epstopdf}
\usepackage{url}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}

\title{TUG-FixMacTeX2013}
\author{Richard Koch}
\date{\today}                                           % Activate to display a given date or no date

\begin{document}
\maketitle
\section{FixMacTeX2013}

\section{Important Warnings}

This section contains lessons learned in 2013. The material here is important for all packages made with the new
PackageMaker.

Folders in which packages are built should live on the hard disk rather than an external
disk. Building constructs subfolders named ``root'' which contain copies of material to be installed. This root folder and its
contents are usually owned by root. But material on an external drive is owned by the user instead, so owners will be
incorrect after installing.

The final MacTeX template refers to  root folders of the various sub projects. In the template, each sub project
is listed in the left column; clicking on an arrow there reveals a panel in which the root folder is determined and configured.

This root item must be reconfigured if the contents of the corresponding root are changed. Remove the item
on the left listing the root (for example, /Applications/TeX) by selecting it and pushing "Delete". Then drag a new copy of the root folder to this spot.
Wait until PackageMaker has digested the new comments by watching a spinning cursor. Then reconfigure
that root material. Each project contains {\em two} copies of the template to make this easy. Copy the configuration
material from the "copy" of the template to the "active" template.

Configuration of a root folder is governed by a panel with four tabs: Configuration, Contents, Components, and Scripts.
The material in the first and last tabs is important and should be entered carefully. The second Contents tab allows owners, groups, and
permissions of individual files in the folder to be set. This task is impossible for a huge root folder like TeXLive, but luckily
Apple provides a button "Apply Recommedations" which does it automatically following Apple's "best practices policy."
Always click this button.

For binary files like texlive/2013/bin/universal-darwin, the recommendations are unexpected. Actual binaries have owner root
and group wheel, but symbolic links have owner an individual user and group wheel. Permissions are -rwxr-xr-x. Experiments
and email conversations show that these choices work well.

For the GUI-package, the third tab, "Components", is very important. It lists actual apps and offers to relocate them. {\em Turn this off}.
Otherwise the installer won't upgrade programs in /Applications/TeX, but instead will search the disk for a copy to update.
Always check that these items are off. 

\section{Contents} 

MacTeX-2011 and BasicTeX-2011 originally shipped with Build 151 of the TeX Dist Preference Pane.
This version was seriously broken. It wrote incorrect ``texbin'' links into Contents/Programs.
When users switched to an earlier distribution, or changed from 64 bit binaries to 32 bit binaries,
the Pane appeared to make the change. But after that, /usr/texbin didn't point to a folder containing
binaries.

This short install package fixes the problem by reverting the Preference Pane to build 150, and fixing
the broken links created by build 151. It also reinstalls TeX in /etc/paths.d and /etc/manpaths.d,
fixing a bug created when users install TeX and then upgrade their system. Finally, if users install
MacTeX-2013 and then later install an earlier version, say MacTeX-2010, they get an old version
of the Preference Pane. This package fixes that problem by upgrading to Build 150 of the Pane.

Some users install MacTeX and then discover that their front end cannot access any of the
binaries to typeset. That is because /usr/local has incorrect permissions. This is also fixed by
FixMacTeX2013.

\section{Details}

A clean package file will contain
\begin{itemize}
\item Files ``buildPackage.sh''
\item Files ``background.jpg'', ``License.rtf'', ``ReadMe.rtf'', ``Welcome.rtf''
\item scripts folder containing files ``Description.rtf'', ``postinstall'', ``texdist'', ``TeXDist-description.rtf'', ``TeXDistVersion'', ``TeXManPath'', ``TeXPath''
and a folder named PrefPane containing ``Info.plist'' and the ``TeX Distribution'' preference pane
\item FixMacTeXBuild, a project file for Packagemaker
\item ``TUG'' folder with this document
\end{itemize}

It is easy to create the root file from which the Package is built.
Simply
\begin{verbatim}
     sudo sh buildPackage.sh
\end{verbatim}


\section{Building the Final Install Package with Packagemaker}

Now edit FixMacTeXBuild, the Packagemaker project file, using the GUI interface, as follows.

\begin{enumerate}
\item Click the top item on the left. The right side will change to a view with three tabs. First select
the Configuration tab. Edit so
\begin{enumerate}
\item Title: FixMacTeX2013
\item User Sees: Easy Install Only
\item Install Destination: System volume
\item Certificate: Leave this blank. You might think that putting a certificate name here would correctly sign
the package, but experiments show that it does not. The package needs to be signed after it is constructed.
\item Description: Empty
\end{enumerate}
\item The Requirements and Actions tab entries for the top item can be left blank
item Click the entry FixMacTeX2013 in the Contents section on the left. The right side will change to a view with two tabs.
Select the Configuration tab. Edit so
\begin{enumerate}
\item Choice Name: FixMacTeX2013
\item Identifier: choice1
\item Initial State: Selected and Enabled
\item Destiination: Leave Blank
\item Tooltip: Leave Blank
\item Description: Leave Blank
\end{enumerate}
\item The Requirements tab entries for this contents item can be left blank
\item Open the FixMacTeX2013  entry in the bottom left column. This item should show a ``/usr/local' directory,
obtained by dragging root/user/local to the left column. The right side will change to a view with four tabs.
The item under the Components tab can be left blank. It is not necessary to edit the
items under the Contents tab. The items under the
Configuration tab should be edited as follows:
\begin{enumerate}
\item Install: root/usr/local (The item on the right should have selected ``Relative To Project'')
\item Destination: /usr/local (The item on the right should have selected ``Relative To Project'')
\item Do not check ``Allow custom location''
\item Patch: No patch root selected
\item Package Identifier: org.tug.mactex.fixmactex2013
\item Package Version: 1.0
\item Restart Action: None
\item Check ``Require admin authentication''
\item PackageLocation: Self-Contained
\end{enumerate}
The items under the Scripts tab should be edited to read
\begin{enumerate}
\item Scripts directory: scripts (The item on the right should have selected ``Relative To Project'')
\item Preinstall: Leave Blank
\item Postinstall: scripts/postinstall (The item on the right should have selected ``Relative To Project'')
\end{enumerate}

\end{enumerate}

After verifying all these items, build the install package by clicking the ``Build'' icon. When asked to select
a name, choose ``FixMacTeX2013-Temp''. 
After the package has been made, sign it by executing the following line in Terminal:
\begin{verbatim}
     sh signPackage.sh
\end{verbatim}
This script simply calls
\begin{verbatim}
     productsign --sign "Developer ID Installer: Richard Koch" old-name new-name
\end{verbatim}
where ``old-name'' is FixMacTeX2013-Temp.pkg and ``new-name'' is FixMacTeX2013.pkg.


Packagemaker will report one warning. The warning is an incorrect permission on a link, and I believe
the permission is correct, since it matches permissions set for links when TeX Live is compiled.









\end{document}  