summaryrefslogtreecommitdiff
path: root/bin/pyunorc-update64.in
blob: d72417c4d797310c36016c57efcf86944ad8111a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash

#*****************************************************************************
# 
#  pyunorc-update64 - Utility to update pythonloader.unorc on x86_64
#
#  It extends PYTHONPATH and PYTHONHOME with various paths, so pyuno is able
#  to find 32-bit .so files even on 64-bit system and on the contrary
#  the 32-bit libraries are able to find .py and .pic files from the 64bit
#  package.
# 
#  Initial version by: Petr Mladek <pmladek@suse.cz>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License version 2, as
#  published by the Free Software Foundation.
# 
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
# 
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# 
#*****************************************************************************

# do the job just on x86_64
test `uname -i` = "x86_64" || exit 0;

PYUNORCFILE=@OOINSTBASE@/program/pythonloader.unorc

# try to detect the right path from the compat link
if test -L /usr/lib64/python ; then
    PYTHONHOME64=`readlink /usr/lib64/python`
    if test "${PYTHONHOME64#/*}" = "$PYTHONHOME64" ; then
	# relative path
	PYTHONHOME64="/usr/lib64/$PYTHONHOME64"
    fi
else
    # fall back to the current known python version
    PYTHONHOME64=/usr/lib64/python2.5
fi

# derive the path to 32-bit .so files from the 64-bit path
PYTHONHOME32=`echo $PYTHONHOME64 | sed -e "s|/usr/lib64|/usr/lib|"`

# the following paths must be mentioned in PYTHONPATH
# it includes two 32-bit paths, main python dir, and lots of paths printed by
# PYTHONPATH=/usr/lib64/python/ python -c 'import sys; print sys.path'
# , all are converted to URL
PYTHONPATH_COMPAT64="file://$PYTHONHOME32/lib-dynload \
file://$PYTHONHOME32/site-packages \
file:///usr/lib64/python \
file://$PYTHONHOME64 \
file://$PYTHONHOME64/plat-linux2 \
file://$PYTHONHOME64/lib-tk \
file://$PYTHONHOME64/lib-dynload \
file://$PYTHONHOME64/site-packages \
file://$PYTHONHOME64/site-packages/Numeric \
file://$PYTHONHOME64/site-packages/PIL \
file://$PYTHONHOME64/site-packages/SaX \
file://$PYTHONHOME64/site-packages/gst-0.10 \
file://$PYTHONHOME64/site-packages/gtk-2.0 \
file://$PYTHONHOME64/site-packages/wx-2.6-gtk2-unicode"

# check PYTHONPATH
sed_script=`mktemp /tmp/OpenOffice_org-pyunorc.sed.XXXXXXXX`
for path in $PYTHONPATH_COMPAT64 ; do
    if ! grep -q "PYTHONPATH=.*$path" $PYUNORCFILE ; then
        echo "s|^\([[:blank:]]*PYTHONPATH=.*\)$|\1 $path|" >>$sed_script
    fi
done	

# check PYTHONHOME; it must be set to PYTHONHOME32 on x86_64
if grep -q "^[[:blank:]]*PYTHONHOME=" $PYUNORCFILE ; then
    if ! grep -q "^[[:blank:]]*PYTHONHOME=file://$PYTHONHOME32" $PYUNORCFILE ; then
	# just fix the path
	echo "s|^\([[:blank:]]*PYTHONHOME=\).*$|\1file://$PYTHONHOME32|" >>$sed_script
    fi
else
    # the variable is missing at all
    echo "s|^\([[:blank:]]*PYTHONPATH=.*\)$|\1\nPYTHONHOME=file://$PYTHONHOME32|" >>$sed_script
fi	

# update the config file if any problem was found
if test -s $sed_script ; then
    mv -f $PYUNORCFILE $PYUNORCFILE.savedby.pyunorc-update64
    sed -f $sed_script $PYUNORCFILE.savedby.pyunorc-update64 >$PYUNORCFILE
fi

# remove the temporaty file
rm -rf $sed_script