#!/bin/bash #The MIT License # #Copyright (c) 2007 Cappy #Permission is hereby granted, free of charge, to any person obtaining a copy #of this software and associated documentation files (the "Software"), to deal #in the Software without restriction, including without limitation the rights #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #copies of the Software, and to permit persons to whom the Software is #furnished to do so, subject to the following conditions: # #The above copyright notice and this permission notice shall be included in #all copies or substantial portions of the Software. # #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN #THE SOFTWARE. #--- #Author: Cappy of ubuntuforums.org #Website: http://ubuntuforums.org/showthread.php?t=474790 #Version: 2.06 #Purpose: Download and install native and non-native libraries #--- print_usage() { echo "\ Usage: getlibs /path/to/binary getlibs -l i386librarytoinstall.so getlibs -p i386packagename getlibs -w www.website.com/i386package.deb getlibs -i /home/$USER/i386package.deb See 'man getlibs' for more commands" clean_up_err } clean_up() { rm -rf $tempdir #Normal exit without errors } clean_up_err() { rm -rf $tempdir exit 1 #Exit code 1 } wget_fail() { echo "\ The mirrors do not have the requested file or there is no internet connection" #clean_up_err } #Trap exits trap clean_up_err 1 2 3 13 15 #Script error or interrupt trap clean_up 0 #Normal exit PATH="/usr/bin:/bin:/sbin:/usr/sbin:$PATH"; export PATH version="Getlibs version 2.06 - March 1st 2008" architecture=`uname -m` targetarch="x86" #Set 64-bit machines to download 32-bit if no options are set if [ "$architecture" != "x86_64" ] && [ "$architecture" != "ia64" ]; then architecture="x86" else architecture="x86_64" fi tempdir=`mktemp -d /tmp/getlibs.XXXXXXXXXX || echo "Unable to create temp directory in /tmp"; clean_up_err` shopt -s xpg_echo #Get distro and release distro=`lsb_release -i | cut -f2` if [ "$distro" = "Ubuntu" ]; then release=`lsb_release -c | cut -f2` #dapper, edgy, gutsy, etc. else if [ "$architecture" = "x86_64" ]; then if [ -d /emul/ia32-linux ]; then distro="Debian" else distro="Ubuntu"; release="gutsy"; fi else distro="Debian" fi fi #If 64-bit ubuntu and ia32-libs is not installed if [ "$architecture" = "x86_64" ] && [ "$distro" = "Ubuntu" ] && [ ! -e "/usr/lib32/libGLU.so.1" ]; then sudo apt-get install ia32-libs elif [ "$architecture" = "x86_64" ] && [ "$distro" = "Debian" ] && [ ! -d "/emul/ia32-linux" ]; then sudo apt-get install ia32-libs fi if [ $# -lt 1 ]; then print_usage fi set -- `getopt -u -a --longoptions="32: 64: binary: library: package: distro: release: file: link: mirror: ldconfig remove: help update version yes verbose apt-file extract build savebuild" "b: l: p: d: r: i: w: m: c r: u v h" "$@"` while [ $# -gt 0 ]; do case "$1" in --32) targetarch="x86";; --64) targetarch="x86_64";; --binary) binarypath="$2"; shift;; -b) binarypath="$2"; shift;; --library) library="true"; parameters="$parameters $2"; shift;; -l) library="true"; parameters="$parameters $2"; shift;; --package) package="true"; parameters="$parameters $2"; shift;; -p) package="true"; parameters="$parameters $2"; shift;; --distro) distro="$2"; shift;; -d) distro="$2"; shift;; --release) release="$2"; shift;; -r) release="$2"; shift;; --file) file="true"; parameters="$parameters $2"; shift;; -i) file="true"; parameters="$parameters $2"; shift;; --link) download="true"; parameters="$parameters $2"; shift;; -w) download="true"; parameters="$parameters $2"; shift;; --mirror) mirror2="$2"; parameters="$parameters $2"; shift;; -m) mirror2="$2"; parameters="$parameters $2"; shift;; --ldconfig) ldconfig="true";; -c) ldconfig="true";; --remove) remove="true"; parameters="$parameters $2"; shift;; -r) remove="true"; parameters="$parameters $2"; shift;; --update) update="true";; -u) update="true";; --version) echo "$version";; -v) echo "$version";; --yes) prompt="yes";; --verbose) verbose="true";; --apt-file) aptfile="true";; --extract) extract="true";; --build) build="true";; --savebuild) savebuild="true";; --help) print_usage;; -h) print_usage;; --) shift; break;; -*) print_usage; exit;; *) break;; esac shift done #If no parameters decide if it is a binary or a library if [ -n "$1" ] && [ -z "$library" ] && [ -z "$binarypath" ] && [ -z "$download" ] && [ -z "$package" ] && [ -z "$file" ]; then if [ -n "`echo "$1" | grep "\.so"`" ]; then library="true"; else #if [ -f "$1" ]; then binarypath="$1" #else #echo "$1 is not an existing file. Assuming this is a package name.\n" #package="true" #fi fi fi while [ $# -gt 0 ]; do if [ "$1" != "--" ]; then parameters="$parameters $1" fi shift done not_an_executable() { echo "\ Cannot determine the dependencies required by this program, it may be a script: If this program needs a 32-bit library use: getlibs -l i386librarytoinstall.so If this program needs a 64-bit library use: getlibs -64l amd64librarytoinstall.so" clean_up_err } #Find missing dependencies for a binary if [ -n "$binarypath" ]; then if [ ! -f "$binarypath" ]; then echo "The file \"$binarypath\" does not exist" print_usage elif [ ! -r "$binarypath" ]; then echo "The file \"$binarypath\" does not have read permissions" clean_up_err elif [ -z "`file "$binarypath" | grep ELF`" ]; then not_an_executable fi if [ -n "`file "$binarypath" | grep "32-bit"`" ]; then targetarch="x86" elif [ -n "`file "$binarypath" | grep "64-bit"`" ]; then targetarch="x86_64" else echo "Not a 32-bit or 64-bit binary"; echo `file "$binarypath"`; clean_up_err; fi cd `dirname "$binarypath" || echo "cd $binarypath failed"; clean_up_err` #Change to the program's directory binarypath=`basename "$binarypath"` dependencylist=`ldd "$binarypath" | grep "not found" | awk '{print $1}'` neededlocallibraries=`echo "$dependencylist" | grep "\./"` if [ -n "$neededlocallibraries" ]; then neededlocallibraries=`echo ${neededlocallibraries//\.\//}` echo "You need to be copy the following libraries to the same directory as the binary:" echo "$neededlocallibraries" dependencylist=`echo "$dependencylist" | grep -v "\./"` fi if [ -z "`echo "$dependencylist" | grep "[[:alpha:]]"`" ]; then echo "This application isn't missing any dependencies" exit fi parameters="$dependencylist" library="true" binarypath="`pwd`/`basename "$binarypath"`" fi #Determine how to install library if [ "$architecture" = "$targetarch" ]; then installtype="native" #apt-get elif [ "$architecture" = "x86" ]; then echo "Cannot install 64-bit libraries on a 32-bit system"; clean_up_err; else installtype="nonnative" #32-bit on 64-bit system fi while true; do #Loop for incase there are new dependencies created for binary returned="" stored_list() { stored=" libXss.so.1 libxss1 libdbus-1.so.2 libdbus-1.so.3 libdbus-1-3 libQtCore.so.4 libQtNetwork.so.4 libQtDBus.so.4 libqt4-core libQtGui.so.4 libqt4-gui libsigc-2.0.so.0 libsigc++-2.0-0c2a libasound_module_pcm_pulse.so libasound2-plugins libglitz-glx.so.1 libglitz-glx1 libglitz.so.1 libglitz1 librsvg-2.so.2 librsvg2-2 libcroco-0.6.so.3 libcroco3 libgsf-1.so.114 libgsf-1-114 libqt-mt.so.3 libqt3-mt libgtk-1.2.so.0 libgtk1.2 libgmodule-1.2.so.0 libglib1.2 libSDL-1.2.so.0 libsdl1.2debian-all libXxf86vm.so.1 libxxf86vm1 libXxf86dga.so.1 libxxf86dga1 libcurl.so.3 libcurl3 " found=`echo "$stored" | grep -m 1 "$1" | grep -o "[^ ]*$"` if [ -n "$found" ]; then echo "$found" fi } use_web_interface() { PACKAGE=`echo $1 | sed s/\+/%2B/g` if [ "$distro" = "Ubuntu" ]; then searchaddress="http://packages.ubuntu.com/search?searchon=contents&keywords=$PACKAGE&mode=exactfilename&suite=$release&arch=i386" else searchaddress="http://packages.ubuntu.com/search?searchon=contents&keywords=$PACKAGE&mode=exactfilename&suite=gutsy&arch=i386" fi packagenames=`wget --user-agent="getlibs" -q -O- "$searchaddress"` if [ -z "$packagenames" ]; then echo 'Not able to connect to http://packages.ubuntu.com to find the package name' fi packagenames=`echo "$packagenames" | sed -n '/