#!/bin/sh #Author: Cappy of ubuntuforums.org #Version: 1.00 #Make sure there is 1 and only 1 argument to the program if [ $# -ne 1 ]; then echo "Usage: getlibs /path/to/binary" exit 127 fi #Replaces a path with "~/" with "/home/username/" binaryfile=`echo $1 | sed 's/^~/$HOME/'` #Checks to see if a path begins with "/" currentdirtest=`echo $binaryfile | grep -c ^/` #If the path does not begin with "/".. if [ $currentdirtest -eq 0 ]; then #Add the current working directory onto the file path binaryfile=`echo $PWD/$binaryfile` fi #Check to see if the binary is 32-bit or 64-bit isit32bit=`file $binaryfile | grep -c "32-bit"` architecture=`arch` if [ "x86_64" = "$architecture" ]; then if [ $isit32bit -eq 1 ]; then #Must download the 32-bit library download=1 else #use apt-get download=2 fi elif [ "amd64" = "$architecture" ] then if [ $isit32bit -eq 1 ]; then #Must download the 32-bit library download=1 else #use apt-get download=2 fi else if [ $isit32bit -eq 1 ]; then #use apt-get download=2 else echo "This isn't a 32-bit application:" echo `file $binaryfile` exit 127 fi fi #print program dependencies | find the ones missing | get only the library names | get rid of the ones starting with "./" dependencylist=`ldd $binaryfile | grep "not found" | awk '{print $1}' | grep -v \./` #get the first missing library out of the list | replace "+" with %2B lib1=`echo $dependencylist | awk '{print $1}' | sed s/\+/%2B/g` if [ "$lib1" = "" ]; then echo "This application isn't missing any dependencies!" exit 127 fi if [ $download -eq 1 ]; then cd /tmp #If folder "/tmp/getlibs" exists .. if [ -d "/tmp/getlibs" ]; then sudo rm -rf /tmp/getlibs fi sudo mkdir getlibs cd getlibs #Look up library name | look for packages that are in usr/lib and no subdirectories | pull text out between double quotes (other than color:red) | get rid of double quotes address1=`wget -q -O- http://packages.ubuntu.com/cgi-bin/search_contents.pl?word=$lib1 | grep usr/lib/[^/]*[\s]*\< | grep -o \"[^\<]*\" | grep -v "color:" | sed s/\"//g` #Get the first package that matched address11=`echo $address1 | awk '{print $1}'` if [ "$address11" = "" ]; then echo "No match found for $lib1" sudo rm -rf /tmp/getlibs exit 127 fi echo "Matched library $lib1 to $address11" #Find the link to the i386 download page for the library address2=`wget -q -O- http://packages.ubuntu.com$address11 | grep i386 | grep download.pl | grep -o \".*\" | sed s/\"//g` #Find the link for the i386 .deb file address3=`wget -q -O- http://packages.ubuntu.com$address2 | grep mirrors.kernel.org | grep -o http.*\.deb` echo "Downloading library .." sudo wget -q $address3 #Get the filename of the deb filename=`echo $address3 | grep -o [^/]*\.deb` echo "File $filename downloaded!" #Extract the debian sudo dpkg -x $filename extracted promptfiles=`ls extracted/usr/lib/` echo "The following i386 libraries will be installed:" echo "$promptfiles" echo "Continue? (y/n)" read prompt case $prompt in y|Y) ;; [yY][eE][sS]) ;; n|N) sudo rm -rf /tmp/getlibs; exit 127 ;; [nN][oO]) sudo rm -rf /tmp/getlibs; exit 127 ;; *) echo "Not understood. Aborting."; sudo rm -rf /tmp/getlibs; exit 127 esac sudo cp /tmp/getlibs/extracted/usr/lib/* /usr/lib32/ cd /tmp sudo rm -rf /tmp/getlibs #Call this script again getlibs $binaryfile fi if [ $download -eq 2 ]; then #Look up library name | look for packages that are in usr/lib and no subdirectories | pull text out between double quotes (other than color:red) | get rid of double quotes address1=`wget -q -O- http://packages.ubuntu.com/cgi-bin/search_contents.pl?word=$lib1 | grep usr/lib/[^/]*[\s]*\< | grep -o \"[^\<]*\" | grep -v "color:" | sed s/\"//g` #Get the first package that matched address11=`echo $address1 | awk '{print $1}'` #Get the filename of the deb filename=`echo $address11 | grep -o [^/]*$` if [ "$filename" = "" ]; then echo "No match found for $lib1" exit 127 fi echo "Matched library $lib1 to $filename" echo "Installing missing library.." sudo apt-get install $filename #Call this script again getlibs $binaryfile fi