HiveBrain v1.2.0
Get Started
← Back to all entries
patternbashMinor

Symlinking shared libraries from a platform-specific directory

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
platformdirectorysharedsymlinkinglibrariesspecificfrom

Problem

We have a setup script for setting up a development environment, and setting up the image libraries is getting a bit messy:

# this is to get PNG and JPEG support working in PIL on Ubuntu
if [ -d /usr/lib/x86_64-linux-gnu ] ; then # 64 bit ubuntu
    sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib/
    sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/
    sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/
fi

if [ -d /usr/lib/i386-linux-gnu/ ] ; then # 32 bit ubuntu
    sudo ln -s /usr/lib/i386-linux-gnu/libfreetype.so /usr/lib/
    sudo ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib/
    sudo ln -s /usr/lib/i386-linux-gnu/libjpeg.so /usr/lib/
fi

if [ -d /usr/lib64/ ] ; then # Redhat
    sudo ln -s /usr/lib64/libjpeg.so /usr/lib/
    sudo ln -s /usr/lib64/libz.so /usr/lib/
    sudo ln -s /usr/lib64/libfreetype.so /usr/lib/
fi

Solution

Seems like you can do the if statement to set a variable to the first part of the path, then put all the file copies at the end after that.

(Warning: My bash is kind of bad. Haven't used it for a while. I think this is how it's done though... Might need quotes around the libpath assignments?)

# this is to get PNG and JPEG support working in PIL on Ubuntu
if [ -d /usr/lib/x86_64-linux-gnu ] ; then # 64 bit ubuntu
    libpath=/usr/lib/x86_64-linux-gnu
fi

if [ -d /usr/lib/i386-linux-gnu/ ] ; then # 32 bit ubuntu
    libpath=/usr/lib/i386-linux-gnu
fi

if [ -d /usr/lib64/ ] ; then # Redhat
    libpath=/usr/lib64
fi

sudo ln -s $libpath/libfreetype.so /usr/lib/
sudo ln -s $libpath/libz.so /usr/lib/
sudo ln -s $libpath/libjpeg.so /usr/lib/

Code Snippets

# this is to get PNG and JPEG support working in PIL on Ubuntu
if [ -d /usr/lib/x86_64-linux-gnu ] ; then # 64 bit ubuntu
    libpath=/usr/lib/x86_64-linux-gnu
fi

if [ -d /usr/lib/i386-linux-gnu/ ] ; then # 32 bit ubuntu
    libpath=/usr/lib/i386-linux-gnu
fi

if [ -d /usr/lib64/ ] ; then # Redhat
    libpath=/usr/lib64
fi

sudo ln -s $libpath/libfreetype.so /usr/lib/
sudo ln -s $libpath/libz.so /usr/lib/
sudo ln -s $libpath/libjpeg.so /usr/lib/

Context

StackExchange Code Review Q#8441, answer score: 3

Revisions (0)

No revisions yet.