Skip to content

Commit

Permalink
Make winrpm.sh crawl package dependencies
Browse files Browse the repository at this point in the history
and no longer always cd to dist-extras

and explicitly check for its own dependencies
  • Loading branch information
tkelman committed Jun 16, 2015
1 parent 363678a commit acb3e68
Showing 1 changed file with 64 additions and 8 deletions.
72 changes: 64 additions & 8 deletions contrib/windows/winrpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@
set -e
url=$1
toinstall=$2
# run in dist-extras
mkdir -p $(dirname "$0")/../../dist-extras
cd $(dirname "$0")/../../dist-extras

for i in curl xmllint gunzip sort sha256sum 7z; do
if [ -z "$(which $i 2>/dev/null)" ]; then
echo "error: this script requires having $i installed" >&2
exit 1
fi
done

# there is a curl --retry flag but it wasn't working here for some reason
retry_curl() {
for i in $(seq 10); do
curl -fLsS $1 && return
#sleep 2
done
echo "failed to download $1" >&2
echo "error: failed to download $1" >&2
exit 1
}

Expand Down Expand Up @@ -75,17 +79,69 @@ rpm_select() {
[@ver='$maxver'][@rel='$maxrel']][1]" -
}

mkdir -p noarch
for i in $toinstall; do
pkgi=$(rpm_select $i)
# fail if no available candidates for requested packages
if [ -z "$pkgi" ]; then
if [ -z "$(rpm_select $i)" ]; then
exit 1
fi
done

# outputs package and dll names, e.g. mingw64(zlib1.dll)
rpm_requires() {
for i in $(rpm_select $1 | \
$xp "/package/format/requires/entry/@name" - 2>/dev/null); do
eval $i
echo $name
done
}

# outputs package name, warns if multiple providers with different names
rpm_provides() {
providers=$(echo $primary | $xp "//*[$loc'package'][./*[$loc'format'] \
/*[$loc'provides']/*[$loc'entry'][@name='$1']]/*[$loc'name']" - | \
sed -e 's|<name>||g' -e 's|</name>|\n|g' | sort -u)
if [ $(echo $providers | wc -w) -gt 1 ]; then
echo "warning: found multiple providers $providers for $1, adding all" >&2
fi
echo $providers
}

newpkgs=$toinstall
allrequires=""
while [ -n "$newpkgs" ]; do
newrequires=""
for i in $newpkgs; do
for j in $(rpm_requires $i); do
# leading and trailing spaces to ensure word match
case " $allrequires $newrequires " in
*" $j "*) # already on list
;;
*)
newrequires="$newrequires $j";;
esac
done
done
allrequires="$allrequires $newrequires"
newpkgs=""
for i in $newrequires; do
provides="$(rpm_provides $i)"
case " $toinstall $newpkgs " in
*" $provides "*) # already on list
;;
*)
newpkgs="$newpkgs $provides";;
esac
done
toinstall="$toinstall $newpkgs"
done

mkdir -p noarch
for i in $toinstall; do
pkgi=$(rpm_select $i)
checksum=$(echo $pkgi | $xp "/package/checksum/text()" -)
eval $(echo $pkgi | $xp "/package/location/@href" -)
echo "downloading $href"
../deps/jldownload $href $url/$href
$(dirname "$0")/../../deps/jldownload $href $url/$href
echo "$checksum *$href" | sha256sum -c
7z x -y $href
cpiofile=$(basename $href | sed 's/.rpm$/.cpio/')
Expand Down

0 comments on commit acb3e68

Please sign in to comment.