On Jan 3, 2008, at 10:05 AM, Jean-Marc Lasgouttes wrote:
Bennett Helm <[EMAIL PROTECTED]> writes:
That sounds good. Perhaps configure.py could launch this script after
it runs; wouldn't that be better than doing it after the user dir's
creation?
This is starting to give me second thoughts about whether linking
rather than copying to files is better. If LyX.app is moved, the
links break. I suppose we could assume LyX.app won't be moved while
it is running, but that would require running the script everytime
LyX is launched. Any thoughts about which is the best approach?
The script could have two functions:
OK -- I've modified and rearranged the script to fit these two
functions.
A few notes:
1. Both scripts need to know the location of the current LyX user's
directory, which on Mac is ~/Library/Application Support/LyX-x.y
(where x.y is the version number of LyX); hence the "NEWLYXSUFFIX".
2. The first script needs to know the previous version number of LyX
-- hence the "OLDLYXSUFFIX". The assumption here is that we should
attempt to copy the old user's directory into the new location and
patch the preference file only when the user upgrades from the
previous to the current version of LyX -- which can be from, say,
1.4.0 to 1.5.3. Attempting to upgrade from 1.3.0 to 1.5.3 is assumed
to be too fragile, so that this should not be attempted.
3. The first script assumes that it should attempt to upgrade the
user's directory only when the new user's directory does not exist.
So it should either be run before configure or use a different
mechanism to determine whether to upgrade or not.
4. The second script deletes the existing default templates,
examples, and tex files before it creates the links. This is because
the LyX/Mac installer currently copies these files rather than
creating links, so that the attempt to create a link will currently
fail without first deleting. (LyX/Mac users have been warned not to
modify files in these directories because they will be replaced by
future installers.)
I'm copying the scripts here so that it's clear what needs to be done
when translating to C++ or python. At this point I think I've done as
much as I can. Is someone else able to do the translation and
integrate it into the running of LyX?
- create new user directory and import old settings. This can be
invoked every time the userdir has to be created.
#!/bin/sh
# Script to copy old user's directory to new location and clean up other
# files, if necessary.
NEWLYXSUFFIX=-1.5
OLDLYXSUFFIX=-1.4
NEW_USER_LYXDIR="${HOME}/Library/Application Support/LyX${NEWLYXSUFFIX}"
# The following sed script will update the preference file by
changing all instances
# of OLDLYXSUFFIX to NEWLYXSUFFIX to accommodate the changed LyX
User's directory
# location.
UPDATEUSERDIR="[EMAIL PROTECTED]@\LyX$NEWLYXSUFFIX@"
# Check to see if new LyX user's directory exists. If not, try to copy
# old LyX user's directory to new location and update it.
test -d "${NEW_USER_LYXDIR}" && {
echo "Current LyX user's folder exists at ${NEW_USER_LYXDIR}." >&1
} || {
echo "No current LyX user's folder exists at $
{NEW_USER_LYXDIR}." >&1
OLD_USER_LYXDIR="${USER_SUPPORT}/LyX${OLDLYXSUFFIX}"
test -d "${OLD_USER_LYXDIR}" && {
echo "Old LyX user's folder exists at ${HOME}/Library/
Application Support/LyX$OLDLYXSUFFIX. Will try to copy ..." >&1
cp -R "${OLD_USER_LYXDIR}" "${NEW_USER_LYXDIR}" || echo "
failure."
test -e "${NEW_USER_LYXDIR}/preferences" && {
echo "Preferences file exists." >&1
mv "${NEW_USER_LYXDIR}/preferences" "${NEW_USER_LYXDIR}/
preferences.old"
sed $UPDATEUSERDIR "${NEW_USER_LYXDIR}/preferences.old"
> "${NEW_USER_LYXDIR}/preferences"
rm -rf "${NEW_USER_LYXDIR}/preferences.old"
echo "Preferences file updated." >&1
} || {
echo "Preferences file does not exist." >&1
}
} || {
echo "No old LyX user's folder exists at ${OLD_USER_LYXDIR}.
Now creating ${NEW_USER_LYXDIR}" >&1
mkdir -p "${NEW_USER_LYXDIR}"
}
}
# Remove old Start-Lyx.app if needed.
test -d /Applications/Start-Lyx.app && {
rm -rf /Applications/Start-Lyx.app
echo "Removed old Start-Lyx.app." >&1
}
# Remove old math font files from ${HOME}/Library/Fonts if needed
FONTFOLDER=${HOME}/Library/Fonts
test -e "${FONTFOLDER}/lyx-math" && {
echo "Found old math font files. Now deleting..." >&1
for FONTFILE in lyx-math cmex10.ttf luximr.ttf luxirr.ttf
luxisr.ttf cmmi10.ttf luximri.ttf luxirri.ttf luxisri.ttf cmr10.ttf
luximb.ttf luxirb.ttf luxisb.ttf msam10.ttf cmsy10.ttf luximbi.ttf
luxirbi.ttf luxisbi.ttf msbm10.ttf
do
rm "${FONTFOLDER}/${FONTFILE}" || echo " Could not remove
$FONTFILE." >&1
done
}
- make sure that examples and templates are correctly visible.
#!/bin/sh
# Script to link default example, template, and tex files to LyX user
directory
NEWLYXSUFFIX=-1.5
NEW_USER_LYXDIR="${HOME}/Library/Application Support/LyX${NEWLYXSUFFIX}"
# Find directory of this script
CURRENTDIR=`dirname "$0"`
# Now link default example files
mkdir -p "${NEW_USER_LYXDIR}/examples"
rm -rf "${NEW_USER_LYXDIR}/examples/default"
ln -sf "${CURRENTDIR}/../Resources/examples" "${NEW_USER_LYXDIR}/
examples/default"
# Now link default template files
mkdir -p "${NEW_USER_LYXDIR}/templates"
rm -rf "${NEW_USER_LYXDIR}/templates/default"
ln -sf "${CURRENTDIR}/../Resources/templates" "${NEW_USER_LYXDIR}/
templates/default"
# Now link LyX's tex files
mkdir -p "${HOME}/Library/texmf/tex/latex";
rm -rf "${HOME}/Library/texmf/tex/latex/lyx"
ln -sf "${CURRENTDIR}/../Resources/tex" "${HOME}/Library/texmf/tex/
latex/lyx"
Bennett