#!/bin/zsh ############################################################################### # install_local.sh # # Adam Wolfe Gordon (adam.wolfegordon@gmail.com), 2010 # # # # Usage: install_local.sh [-p | -i ] -d # # # # Installs a Debian package in a user-specified prefix, fetching dependencies # # and the package itself from apt if neccessary. Handy for use with stow or # # other software management systems. # ############################################################################### # Get options while getopts "p:i:d:" ARG; do eval $ARG=$OPTARG; done; # Check for correct usage if [[ ( -n "$i" && -n "$p" ) || ( -z "$i" && -z "$p" ) || ( -z "$d" ) ]]; then echo "Usage: install_local.sh [-p | -i ] -d "; exit 1; fi; if [[ $d[1] == '/' ]]; then PREFIX=$d; else PREFIX=$PWD/$d; fi; unset d; # Go to a temporary directory ORIGDIR=$PWD; TMP=$(mktemp -d); cd $TMP; if [[ -n "$p" ]]; then # Find the dependencies of a remote package PKGNAME=$p; unset p; DEPS=$(apt-cache depends $PKGNAME | grep Depends | cut -f2 -d':' | tr -d ' ') echo -n "Downloading $PKGNAME ... "; aptitude download $PKGNAME >&/dev/null; echo "done."; else # Find the dependencies of a local package if [[ $i[1] == '/' ]]; then PKGNAME=$i; else PKGNAME=$ORIGDIR/$i; fi; unset i; cp $PKGNAME .; DEPS=$(dpkg-deb -f $PKGNAME 'Depends'|sed 's/,/\n/g'|awk -- '{print $1;}'); fi; # Check whether deps are installed, and fetch them if they aren't for DEP in ${(f)DEPS}; do echo -n "Checking for $DEP ... "; dpkg-query -f '${Status}' -s $DEP 2>&1 | grep 'install ok installed' >& /dev/null; if [ $? != 0 ]; then echo -n "not found, downloading ... "; aptitude download $DEP >&/dev/null; echo "done."; else echo "found."; fi; done; # Install all the debs we've fetched mkdir -p $PREFIX; mkdir tmp; for PKG in *.deb; do echo -n "Installing $PKG ... "; mv $PKG tmp/; cd tmp; ar x $PKG; FILES=$(tar -xvf data.tar* | cut -f2,3 -d'/' | grep -v 'usr\/$' | uniq); for file in ${(f)FILES}; do rsync -ar $file $PREFIX >&/dev/null; done; echo "done."; cd ..; rm -rf tmp/*; done; # Cleanup cd $ORIGDIR; rm -rf $TMP;