Commit 02de43a0 authored by Diego Pasqualin's avatar Diego Pasqualin
Browse files

Add script to update packages on a mirror based on another


Signed-off-by: default avatarDiego Pasqualin <dpasqualin@c3sl.ufpr.br>
parent 6afb884d
#!/bin/bash
#
# Copyright (C) 2004-2010 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of Linux Educacional project
#
# Linux Educacional is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
# This script is used to updated on mirror based on another.
# It will look for packages on <from> mirror and check whether they can be
# updated on <to> mirror. It always asks if you want to update before doing
# it.
TMPDIR=$(mktemp -d --tmpdir=/tmp)
PUBLISHSCRIPT="$(dirname $0)/le-publica.sh"
HOST="http://windu.c3sl.ufpr.br/le5"
function buildURL() {
local status="$1"
echo "http://windu.c3sl.ufpr.br/le5/dists/le5-$status/main/binary-i386/Packages"
}
function getPackagesAndVersions() {
local repoFile=$1
local pkgAndVersion=""
local version=""
for pkg in $(grep '^Package:' $repoFile | awk '{print $2}'); do
version=$(grep -m1 -A1 "Package: ${pkg}$" $repoFile | tail -1 |
awk '{print $2}')
pkgAndVersion="$pkgAndVersion $pkg:$version"
done
echo "$pkgAndVersion"
}
function askUpdate() {
local repo=$1
local pkg=$2
local vFrom=$3
local vTo=$4
read -p "Update mirror le5-$repo, $pkg ($vTo -> $vFrom) (y/N)? " yn
test "$yn" = "y" || test "$yn" = "s"
}
function getDownloadLink() {
local pkg=$1
local link=$(grep -m1 "Filename:.*${pkg}.*" $FROMREPOFILE | awk '{print $2}')
echo "$HOST/$link"
}
function doUpdate() {
local pkg="$1"
local pkgFile="$TMPDIR/$pkg.deb"
wget -q $(getDownloadLink $pkg) -O "$pkgFile"
echo "---------------------------------------------"
echo "Updating $pkg..."
$PUBLISHSCRIPT le5-$TOREPO "$pkgFile"
if test $? -ne 0; then
echo "ERROR updating $pkg."
read -p "Continue? (y/N) " yn
if ! (test "$yn" = "y" || test "$yn" = "s"); then
exit 1
fi
else
echo "$pkg updated."
fi
echo "---------------------------------------------"
rm -f "$pkgFile"
}
if test $# -ne 2; then
echo "$0 <from> <to>"
exit 1
elif ! test -f "$PUBLISHSCRIPT"; then
echo "Error finding $PUBLISHSCRIPT"
echo "This script is needed to publish packages"
fi
FROMREPO=$1
TOREPO=$2
FROMREPOFILE="$TMPDIR/$FROMREPO"
TOREPOFILE="$TMPDIR/$TOREPO"
wget -q $(buildURL $FROMREPO) -O $FROMREPOFILE || exit 1
wget -q $(buildURL $TOREPO) -O $TOREPOFILE || exit 1
fromPkgAndVersion="$(getPackagesAndVersions $FROMREPOFILE)"
toPkgAndVersion="$(getPackagesAndVersions $TOREPOFILE)"
for pkgVersionFrom in $fromPkgAndVersion; do
pkgFrom=$(echo $pkgVersionFrom | cut -d: -f1)
versionFrom=$(echo $pkgVersionFrom | cut -d: -f2)
for pkgVersionTo in $toPkgAndVersion; do
pkgTo=$(echo $pkgVersionTo | cut -d: -f1)
if test $pkgFrom = $pkgTo; then
versionTo=$(echo $pkgVersionTo | cut -d: -f2)
if dpkg --compare-versions $versionFrom gt $versionTo; then
if askUpdate $TOREPO $pkgTo $versionFrom $versionTo; then
doUpdate $pkgTo
if test $? -ne 0; then
exit 1
fi
break
fi
elif dpkg --compare-versions $versionFrom gt $versionTo; then
echo -n "WARNING: $pkgFrom($versionFrom) in $FROMREPO is"
echo " greater than $pkgTo($versionTo) in $TOREPO."
break
fi
fi
done
done
rm -rf $TMPDIR
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