Commit 053c0efe authored by Diego Pasqualin's avatar Diego Pasqualin
Browse files

update_mirror.sh: Add comments to the script


Signed-off-by: default avatarDiego Pasqualin <dpasqualin@c3sl.ufpr.br>
parent 188ad581
......@@ -36,11 +36,14 @@ function clean() {
trap "clean" SIGINT SIGTERM
# Build the URL for the Packages file
function buildURL() {
local status="$1"
echo "http://windu.c3sl.ufpr.br/le5/dists/le5-$status/main/binary-i386/Packages"
}
# Return a string containing the tuple package:version with all packages
# from $repoFile
function getPackagesAndVersions() {
local repoFile=$1
local pkgAndVersion=""
......@@ -54,6 +57,8 @@ function getPackagesAndVersions() {
echo "$pkgAndVersion"
}
# Ask the user whether he wants to update the package, return true if the
# user answer Yes and false otherwise
function askUpdate() {
local repo=$1
local pkg=$2
......@@ -63,6 +68,8 @@ function askUpdate() {
test "$yn" = "y" || test "$yn" = "s"
}
# Ask whether the user wants to include the package into the repository,
# return true if the user answer Yes ans false otherwise
function askInclude() {
local repo=$1
local pkg=$2
......@@ -71,6 +78,7 @@ function askInclude() {
test "$yn" = "y" || test "$yn" = "s"
}
# Return the link to download the package $pkg
function getDownloadLink() {
local pkg=$1
local link=""
......@@ -80,6 +88,7 @@ function getDownloadLink() {
echo "$HOST/$link"
}
# Perform the update of package $pkg on the repository
function doUpdate() {
local pkg="$1"
local pkgFile="$TMPDIR/$pkg.deb"
......@@ -105,6 +114,7 @@ function doUpdate() {
rm -f "$pkgFile"
}
# Sanity check
if test $# -ne 2; then
echo "$0 <from> <to>"
exit 1
......@@ -119,12 +129,17 @@ TOREPO=$2
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
fromPkgAndVersion="$(getPackagesAndVersions $FROMREPOFILE)"
toPkgAndVersion="$(getPackagesAndVersions $TOREPOFILE)"
# Iterate over all packages from the base repository $FROMREPO and check
# whether the destination repository has a different version of it, or if
# it doesn't have the package at all
for pkgVersionFrom in $fromPkgAndVersion; do
pkgFrom=$(echo $pkgVersionFrom | cut -d: -f1)
versionFrom=$(echo $pkgVersionFrom | cut -d: -f2)
......@@ -139,12 +154,17 @@ for pkgVersionFrom in $fromPkgAndVersion; do
doUpdate $pkgTo
fi
elif dpkg --compare-versions $versionFrom gt $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."
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 $pkgTo $versionTo; then
doUpdate $pkgTo
fi
......
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