Commit e1cb9f53 authored by Diego Pasqualin's avatar Diego Pasqualin

Copy update_mirror.sh from LE5 repository

this version of the script fix many issues and allow to see the diff between
two packages before updating them.
Signed-off-by: 's avatarDiego Pasqualin <dpasqualin@c3sl.ufpr.br>
parent 35217ff1
......@@ -26,8 +26,9 @@
# it.
TMPDIR=$(mktemp -d --tmpdir=/tmp)
PUBLISHSCRIPT="$(dirname $0)/le-publish.sh"
HOST="http://windu.c3sl.ufpr.br/le"
PUBLISHSCRIPT="$(dirname $0)/le_publish.sh"
PROJECT="le"
HOST="http://windu.c3sl.ufpr.br/$PROJECT"
function clean() {
rm -rf $TMPDIR
......@@ -39,20 +40,25 @@ trap "clean" SIGINT SIGTERM
# Build the URL for the Packages file
function buildURL() {
local status="$1"
echo "http://windu.c3sl.ufpr.br/le/dists/le-$status/main/binary-i386/Packages"
echo "$HOST/dists/$PROJECT-$status/main/binary-i386/Packages"
}
# Return a string containing the tuple package:version with all packages
# from $repoFile
function getPackagesAndVersions() {
local repoFile=$1
local repoFile="$1"
local pkgsToCopy="$2"
local pkgAndVersion=""
local version=""
for pkg in $(grep '^Package:' $repoFile | awk '{print $2}'); do
version=$(awk "/^Package: ${pkg}$/,/^$/" $repoFile |
grep "^Version:" | awk '{print $2}')
pkgAndVersion="$pkgAndVersion $pkg:$version"
#FIXME: For some reason, grep -w doesn't work
if test -z "$pkgsToCopy" || sed 's/ /\n/g' <<< $pkgsToCopy |
grep -xq "$pkg"; then
version=$(awk "/^Package: ${pkg}$/,/^$/" $repoFile |
grep "^Version:" | awk '{print $2}')
pkgAndVersion="$pkgAndVersion $pkg:$version"
fi
done
echo "$pkgAndVersion"
}
......@@ -64,7 +70,7 @@ function askUpdate() {
local pkg=$2
local vFrom=$3
local vTo=$4
read -p "Update mirror le-$repo, $pkg ($vTo -> $vFrom) (y/N)? " yn
read -p "Update mirror $PROJECT-$repo, $pkg ($vTo -> $vFrom) (y/N)? " yn
test "$yn" = "y" || test "$yn" = "s"
}
......@@ -74,16 +80,17 @@ function askInclude() {
local repo=$1
local pkg=$2
local version=$3
read -p "$pkg:$version doesn't exist on le-$repo, include it (y/N)? " yn
read -p "$pkg:$version doesn't exist on $PROJECT-$repo, include it (y/N)? " yn
test "$yn" = "y" || test "$yn" = "s"
}
# Return the link to download the package $pkg
function getDownloadLink() {
local pkg=$1
local repo=$2
local link=""
link=$(grep -m1 "Filename:.*${pkg}/${pkg}_" $FROMREPOFILE | awk '{print $2}')
link=$(grep -m1 "Filename:.*/${pkg}_.*.deb" $repo | awk '{print $2}')
echo "$HOST/$link"
}
......@@ -93,12 +100,12 @@ function doUpdate() {
local pkg="$1"
local pkgFile="$TMPDIR/$pkg.deb"
wget -q $(getDownloadLink $pkg) -O "$pkgFile"
wget -q $(getDownloadLink $pkg $FROMREPOFILE) -O "$pkgFile"
echo "---------------------------------------------"
echo "Updating $pkg..."
$PUBLISHSCRIPT le-$TOREPO "$pkgFile"
$PUBLISHSCRIPT $PROJECT-$TOREPO "$pkgFile"
if test $? -ne 0; then
echo "ERROR updating $pkg."
......@@ -114,9 +121,13 @@ function doUpdate() {
rm -f "$pkgFile"
}
################################################################################
# Parser arguments
################################################################################
# Sanity check
if test $# -ne 2; then
echo "$0 <from> <to>"
if test $# -lt 2; then
echo "$0 <from> <to> [--diff] [package...]"
exit 1
elif ! test -f "$PUBLISHSCRIPT"; then
echo "Error finding $PUBLISHSCRIPT"
......@@ -126,16 +137,47 @@ fi
FROMREPO=$1
TOREPO=$2
DIFF=false
if test "$3" = "--diff"; then
DIFF=true
shift 3
else
shift 2
fi
PKGSTOCOPY=""
if test $# -gt 0; then
PKGSTOCOPY="$@"
fi
################################################################################
# End of Parser arguments
################################################################################
FROMREPOFILE="$TMPDIR/$FROMREPO"
TOREPOFILE="$TMPDIR/$TOREPO"
# Download the Packages file, which contains information about all the
# packages that are part of the repository
wget -q $(buildURL $FROMREPO) -O $FROMREPOFILE || exit 1
wget -q $(buildURL $TOREPO) -O $TOREPOFILE || exit 1
if ! wget -q $(buildURL $FROMREPO) -O $FROMREPOFILE; then
echo "Error downloading Packages file $FROMREPO"
exit 1
fi
if ! wget -q $(buildURL $TOREPO) -O $TOREPOFILE; then
echo "Error downloading Packages file $TOREPO"
exit 1
fi
fromPkgAndVersion="$(getPackagesAndVersions $FROMREPOFILE)"
toPkgAndVersion="$(getPackagesAndVersions $TOREPOFILE)"
# Sanity check for packages to copy
for pkg in $PKGSTOCOPY; do
if ! grep -q "^Package: ${pkg}$" $FROMREPOFILE; then
echo "WARNING: $pkg not found on repository $FROMREPO"
fi
done
fromPkgAndVersion="$(getPackagesAndVersions $FROMREPOFILE "$PKGSTOCOPY")"
toPkgAndVersion="$(getPackagesAndVersions $TOREPOFILE "$PKGSTOCOPY")"
# Iterate over all packages from the base repository $FROMREPO and check
# whether the destination repository has a different version of it, or if
......@@ -150,23 +192,49 @@ for pkgVersionFrom in $fromPkgAndVersion; do
versionTo=$(echo $pkgVersionTo | cut -d: -f2)
found=true
if dpkg --compare-versions $versionFrom gt $versionTo; then
# Show package diff
if $DIFF; then
linkFrom="$(getDownloadLink $pkgFrom $FROMREPOFILE)"
linkTo="$(getDownloadLink $pkgTo $TOREPOFILE)"
pkgFromDeb="$TMPDIR/${pkgFrom}_${versionFrom}.deb"
pkgToDeb="$TMPDIR/${pkgTo}_${versionTo}.deb"
echo "Downloading $linkFrom to $pkgFromDeb"
wget -q "$linkFrom" -O "$pkgFromDeb"
wget -q "$linkTo" -O "$pkgToDeb"
dpkg -x "$pkgFromDeb" "${pkgFromDeb}_diff"
dpkg -e "$pkgFromDeb" "${pkgFromDeb}_diff/DEBIAN"
dpkg -x "$pkgToDeb" "${pkgToDeb}_diff"
dpkg -e "$pkgToDeb" "${pkgToDeb}_diff/DEBIAN"
diff -urN "${pkgToDeb}_diff" "${pkgFromDeb}_diff" | less
fi
if askUpdate $TOREPO $pkgTo $versionFrom $versionTo; then
doUpdate $pkgTo
fi
elif dpkg --compare-versions $versionFrom gt $versionTo; then
elif dpkg --compare-versions $versionFrom lt $versionTo; then
# It's very weird to have a newer version of the package on
# the destination repository, let's have the user to know about
# it
echo -n "WARNING: $pkgFrom($versionFrom) in $FROMREPO is"
echo " greater than $pkgTo($versionTo) in $TOREPO."
echo " older than $pkgTo($versionTo) in $TOREPO."
elif test -n "$PKGSTOCOPY"; then
echo -n "INFO: Package $pkgFrom: same version ($versionFrom)"
echo " on $FROMREPO and $TOREPO."
fi
break
fi
done
# We didn't find this package on the destionation repository, maybe the
# user wants to add it. Let's ask him
if ! $found && askInclude $TOREPO $pkgFrom $versionFrom; then
doUpdate $pkgTo
doUpdate $pkgFrom
fi
done
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment