]> git.lyx.org Git - features.git/blob - development/MacOSX/inkscape
#11742 correct pre 1.0 inkscape wrapper script path
[features.git] / development / MacOSX / inkscape
1 #!/bin/bash
2
3 # \file inkscape
4 # wrapper start script for Inkscape.app on Mac
5 #
6 # This file is part of LyX, the document processor.
7 # Licence details can be found in the file COPYING.
8 #
9 # \author Stephan Witt
10 # Full author contact details are available in file CREDITS.
11
12 unset DISPLAY
13
14 # check for file arguments with relative path names
15 # convert them to absolute path names
16 # inkscape on Mac changes the working directory
17 # this invalidates relative path names
18 startinkscape() {
19         inkscape="$1" ; shift
20         pwd=$(pwd)
21         iparams=( "$@" )
22         oparams=()
23         # pre 1.0 application has cmd line utility in resources
24         # this utility needs the explicit option to suppress gui
25         # 1.0 don't have it and fails to start with it
26         case "${inkscape}" in
27         */Resources/*)
28                 wogui="--without-gui"
29                 ;;
30         esac
31         for i in ${!iparams[@]}; do
32                 # echo $i "=>" "${iparams[$i]}"
33                 case "${iparams[$i]}" in
34                 --file=/*|--export-pdf=/*|--export-eps=/*|--export-png=/*|--export-emf=/*|--export-wmf=/*|--export-ps=/*|--export-ps-level=/*|--export-pdf-version=/*)
35                         oparams+=( "${iparams[$i]}" )
36                         ;;
37                 --file=*|--export-pdf=*|--export-eps=*|--export-png=*|--export-emf=*|--export-wmf=*|--export-ps=*|--export-ps-level=*|--export-pdf-version=*)
38                         oparams+=( "${iparams[$i]//=/=${pwd}/}" )
39                         ;;
40                 --without-gui|-z)
41                         # ignore this argument - its provided below anyway
42                         ;;
43                 *)
44                         oparams+=( "${iparams[$i]}" )
45                         ;;
46                 esac
47         done
48         exec "${inkscape}" ${wogui} "${oparams[@]}"
49 }
50
51 # try to find the inkscape installation...
52 # at first try the well known location for Inkscape 1.0
53 RESDIR="/Applications/Inkscape.app/Contents/MacOS"
54 if [ -f "${RESDIR}"/inkscape -a -x "${RESDIR}"/inkscape ]; then
55         startinkscape "${RESDIR}"/inkscape "$@"
56         exit 0
57 fi
58 # this failed... so try PATH expansion to start the inkscape shell wrapper
59 # Now continue the check with pre 1.0 inkscape application and the PATH
60 IFS=":" read -ra DIRLIST <<< "${PATH}"
61 for BINDIR in "/Applications/Inkscape.app/Contents/Resources/bin" "${DIRLIST[@]}" ; do
62         RESDIR=$(dirname "${BINDIR}")
63         if [ -f "${RESDIR}"/bin/inkscape -a -x "${RESDIR}"/bin/inkscape ]; then
64                 startinkscape "${RESDIR}"/bin/inkscape "$@"
65                 exit 0
66         fi
67 done
68 # report error and exit with failure status
69 exec 1>&2
70 echo Could not find Inkscape binary.
71 exit 1