6
\$\begingroup\$

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
200_success
145k22 gold badges190 silver badges478 bronze badges
asked Jan 30, 2012 at 4:38
\$\endgroup\$

3 Answers 3

3
\$\begingroup\$

I'm not quite sure if your script should consist of elifs instead of ifs. I'm going to assume that it should be elifs since you don't want to be overwriting your links. If not just remove break or reverse the order of the directories.

for dir in /usr/lib{/x86_64-linux-gnu,/i386-linux-gnu,64}; do
 if [[ -d $dir ]]; then
 sudo ln -s $dir/{libfreetype,libz,libjpeg}.so /usr/lib
 break
 fi
done
answered Dec 11, 2015 at 17:35
\$\endgroup\$
3
\$\begingroup\$

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/
glenn jackman
2,57112 silver badges13 bronze badges
answered Jan 30, 2012 at 5:16
\$\endgroup\$
1
  • 4
    \$\begingroup\$ This looks good, you can use elif for the last two if statements as only 1 option should be chosen. \$\endgroup\$ Commented Jan 30, 2012 at 8:15
1
\$\begingroup\$

In the interests of dryness, and invoking as small number of commands as possible.

for dir in /usr/lib{/x86_64-linux-gnu,/i386-linux-gnu,64}; do
 [ -d $dir ] && echo $dir
done | {read dir;
for lib in {libfreetype,libz,libjpeg}.so; do
 echo ln -s $dir/$lib /usr/lib/
done} | sudo bash
answered Apr 22, 2012 at 4:48
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.