diff options
Diffstat (limited to 'home/bin/zypper-download')
-rwxr-xr-x | home/bin/zypper-download | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/home/bin/zypper-download b/home/bin/zypper-download new file mode 100755 index 0000000..92a02db --- /dev/null +++ b/home/bin/zypper-download @@ -0,0 +1,88 @@ +#!/bin/bash +#### +# Copyright (c) 2011 Nokia Corporation +# +# 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. +#### + +BASENAME=$(basename $0) +ARCH=${BASENAME##*-} +filetype="package" +usage="$(basename $0) [-s] [-a ARCH] [-r reponame]+ PACKAGE+" +REPOLIST="" +while getopts "a:r:hs" opt ; do + case $opt in + a) ARCH="$OPTARG";; + r) REPOLIST="$REPOLIST --repo=$OPTARG";; + h) echo $usage; exit 0;; + s) filetype="srcpackage";; + \?) echo "Bad option"; exit 1;; + esac +done +shift $(($OPTIND-1)) + +VARCACHE="/var/cache/zypp/packages" +ZYPP_CONF="/etc/zypp/zypp.conf" +ZYPPER="zypper" + +if [ "$ARCH" != "download" ] ; then + SYSROOT=/usr/${ARCH}-redhat-linux-gnueabi/sys-root + ZYPP_CONF="${SYSROOT}${ZYPP_CONF}" + VARCACHE="${SYSROOT}${VARCACHE}" + ZYPPER="ZYPP_CONF=${ZYPP_CONF} zypper -R ${SYSROOT}" +fi + +for i in "$*" ; do + echo "Searching for $filetype $i" + tmpfile=$(mktemp) + sudo $ZYPPER -n install --force -d $REPOLIST -t $filetype $i > $tmpfile + pkgname=$(awk -F\' '/Forcing installation/ {print $2}' $tmpfile) + reponame=$(awk -F\' '/Forcing installation/ {print $4}' $tmpfile) + rm $tmpfile + if [ "$pkgname" ] ; then + echo "Found package name $pkgname in repo '$reponame'" + awkprog='BEGIN {FS=" *\\| *"} {if ($3=="'$reponame'") print $2}' + repovalue=$(sudo $ZYPPER repos | awk "$awkprog") + filename="${VARCACHE}/${repovalue}/${pkgname}" + if [ "$filetype" = "package" ] ; then + filename="${filename}.rpm" + else + filename="${filename%.noarch}.src.rpm" + fi + if [ -f "$filename" ] ; then + echo "Copying $filename to local directory" + cp $filename $(basename $filename) + else + # epochs in files really really suck for zypper... + # for epoch 6, frex, they add a 6: before the version + # in the rpm data but not in the filename + filename=`echo $filename | sed -e "s/[0-9]*://"` + if [ -f "$filename" ] ; then + echo "Copying $filename to local directory" + cp $filename $(basename $filename) + else + echo "Package '$filename' isn't where I thought it should be!" + fi + fi + fi +done + + + |