Georg Baum <[EMAIL PROTECTED]> writes:
> 
> Gunnar wrote:
> 
> > Hi.
> > If one would like to send a LyX file that contains many pictures to
> > another person, one has to send all files to that person. When we are
> > talking about users with moderate experience of compressed files/creating
> > archives etc. I can only see problem ahead, unfortunatly.
> > 
> > One idea then would be to create a new kind of LyX files: "LyX-zip" files
> > that
> > contains all files,  expands to a temp directory when opened, and goes
> > back to a LyX-zip file when closing LyX.
> > 
> > One problem is that the pictures can be updated, for example by external
> > programs, and one shouldn't have to include the pictures again.
> 
> This is an old wish. See http://bugzilla.lyx.org/show_bug.cgi?id=700 and add
> your thoughts there if not already coverd.

I recently improved a script posted here sometime ago
http://www.mail-archive.com/lyx-users@lists.lyx.org/msg27494.html

Hope this helps,
Enrico


#!/bin/sh
# This script creates a tar archive with a lyx file and all included files
# (graphics and so on). The tar archive can be compressed with bzip2 or gzip.
#
# Author: Marcin Bukat
# email : [EMAIL PROTECTED]
# This script is a FREE software
# Use at Your own risk
#
# Modified by Enrico Forestieri <[EMAIL PROTECTED]> to:
# - make it also work on solaris
# - recusively collect included files pulled in by \input{}
# - allow for spaces in path names (but not carets ;-)
# - account for multiple bibtex files
# - avoid duplicate inclusions
# - only collect files which are in the same subtree as the lyx file
#
# Note: to allow for a space in path names I had to disallow another char.
# By default this is the caret '^' but it can be changed through an option.

#Prints usage instructions
usage ()
{
    echo "Usage: `basename $0` [-c <char>] [-o <dir>] [-j|-z] path/to/file.lyx"
        echo "Options:"
        echo "    -c  specify the forbidden char in path names"
        echo "    -o  specify the output directory"
        echo "    -j  compress with bzip2"
        echo "    -z  compress with gzip"
        exit
}

#Recursively gather files
gatherFiles ()
{
LYXNAME=$1
DIRNAME=`dirname "$1"`

#Check if the bibtex .bst/.bib files are in the working directory to pack them
for file in `cat "$LYXNAME"|grep BibTeX|\
    sed 's/.*\[\(.*\)\].*{\(.*\)}.*/\1,\2/'|tr ', ' ' ,'`
do
    file=`echo $file|tr ',' ' '`
    if [ -f "$DIRNAME/$file.bst" -o  -f "$DIRNAME/$file.bib" ]; then
        cd "`eval dirname \\\"$DIRNAME/$file\\\"`"
        reldir=`pwd|sed -e "[EMAIL PROTECTED](.*\)@\1@" -e "[EMAIL 
PROTECTED]/\(.*\)@\1@"`
        if [ -n "$reldir" ]; then reldir=$reldir/; fi
        file=`basename "$file"`
        cd "$WORKDIR"
        if [ -f "$reldir$file.bst" ]; then
            INCFILES="\"$reldir$file.bst\"\\\\n$INCFILES"
        elif [ -f "$reldir$file.bib" ]; then
            INCFILES="\"$reldir$file.bib\"\\\\n$INCFILES"
        fi
    fi
done

# Gather figure files.
# Watch out for carriage returns and delete them (done by the last tr).
for file in `cat "$LYXNAME"|egrep "^[[:space:]]*filename "|\
    sed 's/.*filename *\(.*\)/\1/'|tr " " "$FC"|tr -d "\r"`
do
    file=`echo $file|tr "$FC" " "`
    if [ -f "$DIRNAME/$file" ]; then
        cd "`eval dirname \\\"$DIRNAME/$file\\\"`"
        reldir=`pwd|sed -e "[EMAIL PROTECTED](.*\)@\1@" -e "[EMAIL 
PROTECTED]/\(.*\)@\1@"`
        if [ -n "$reldir" ]; then reldir=$reldir/; fi
        file=`basename "$file"`
        cd "$WORKDIR"
        if [ -f "$reldir$file" ]; then
            INCFILES="\"$reldir$file\"\\\\n$INCFILES"
        fi
    fi
done

# Gather input files.
# If file.pstex_t is \input{}ed then add file.pstex to the list, too.
for file in `cat "$LYXNAME"|grep \\\\input\{|\
    sed 's/.*\\input{ *\(.*\) *}.*/\1/'|tr " " "$FC"`
do
    file=`echo $file|tr "$FC" " "`
    if [ -f "$DIRNAME/$file" ]; then
        cd "`eval dirname \\\"$DIRNAME/$file\\\"`"
        reldir=`pwd|sed -e "[EMAIL PROTECTED](.*\)@\1@" -e "[EMAIL 
PROTECTED]/\(.*\)@\1@"`
        if [ -n "$reldir" ]; then reldir=$reldir/; fi
        file=`basename "$file"`
        cd "$WORKDIR"
        if [ -f "$reldir$file" ]; then
            INCFILES="\"$reldir$file\"\\\\n$INCFILES"
            EXT=`echo $file | sed 's/.*\.\(.*\)/\1/'`
            if [ "x$EXT" = "xpstex_t" ]; then
                bname=`basename "$file" .pstex_t`
                INCFILES="\"$reldir$bname.pstex\"\\\\n$INCFILES"
            elif [ "x$EXT" = "xlyx" ]; then
                bname=`basename "$file"`
                gatherFiles "$reldir$file"
            fi
        fi
    fi
done
}

#Creates archive
archive ()
{
ARCHNAME=`basename "$LYXFILENAME" lyx`tar
case "$1" in
    -j)
        COMPRESS="bzip2"
        ARCHNAME="$ARCHNAME.bz2"
        ;;
    -z)
        COMPRESS="gzip"
        ARCHNAME="$ARCHNAME.gz"
        ;;
     *)
        COMPRESS="cat"
esac

cd "$WORKDIR"
WORKDIR=`pwd`

gatherFiles "$LYXFILENAME"

INCFILES=`eval printf $INCFILES | sort | uniq | xargs -i%s echo "\"%s\" "`
eval tar cv \"$LYXFILENAME\" $INCFILES | $COMPRESS > $OUTDIR$ARCHNAME

if [ $? -eq 0 ]; then
    echo "Lyx archive \"$OUTDIR$ARCHNAME\" created successfully"
else
    exit 1
fi
}

#Main part starts here

#Check if there is any parameter
if [ $# -eq 0 ]; then
    usage
else
    LYXFILENAME=""
    OUTDIR=""
    PARAM="-"
    FC="^"
    while [ $# -gt 0 ]
    do
        case "$1" in
            -c) if [ $# -gt 1 ]; then FC=$2; else usage; fi
                shift 2
                ;;
            -c*)
                FC=`echo $1|sed 's/-c//'`
                shift
                ;;
            -o) if [ $# -gt 1 ]; then OUTDIR=$2; else usage; fi
                shift 2
                ;;
            -o*)
                OUTDIR=`echo $1|sed 's/-o//'`
                shift
                ;;
            -j|-z)
                PARAM=$1
                shift
                ;;
            *)
                if [ -n "$LYXFILENAME" ]; then usage; fi
                LYXFILENAME=`basename "$1"`
                WORKDIR=`dirname "$1"`
                shift
        esac
    done
fi

if [ -f "$WORKDIR/$LYXFILENAME" ]; then
    if [ -n "`echo $FC|sed 's/^.\(.*\)/\1/'`" ]; then usage; fi
    if [ -n "$OUTDIR" ]; then OUTDIR=$OUTDIR/; fi
    #parameters are correct so make archive
    archive $PARAM
else
    echo "`basename $0`: cannot find \"$WORKDIR/$LYXFILENAME\""
    exit 1
fi



Reply via email to