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
3 Answers 3
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
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/
-
4\$\begingroup\$ This looks good, you can use
elif
for the last two if statements as only 1 option should be chosen. \$\endgroup\$Paul– Paul2012年01月30日 08:15:08 +00:00Commented Jan 30, 2012 at 8:15
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