From facad9c5895b0bd5b5f64958257b80caa27cb0ac Mon Sep 17 00:00:00 2001 From: Diego Pasqualin <dpasqualin@c3sl.ufpr.br> Date: Fri, 12 Apr 2013 16:30:39 -0300 Subject: [PATCH] Add bin directory with some helper scripts Signed-off-by: Diego Pasqualin <dpasqualin@c3sl.ufpr.br> --- bin/le-publica.sh | 54 ++++++++++++++ bin/update_mirror.sh | 174 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+) create mode 100755 bin/le-publica.sh create mode 100755 bin/update_mirror.sh diff --git a/bin/le-publica.sh b/bin/le-publica.sh new file mode 100755 index 000000000..67d197b29 --- /dev/null +++ b/bin/le-publica.sh @@ -0,0 +1,54 @@ +#!/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. + +if (( $# < 2 )) || [[ "$1" == "--help" ]]; then + printf "Uso: le-publica repositorio arquivo1 [arquivo2 ... arquivoN]\n" + printf " repositorio = le-unstable | le-testing | le-stable | le-educ | le5-unstable | le5-testing | le5-stable | mc-unstable | mc-testing | mc-stable\n" + exit 1 +fi + +REPOSITORIO=$1 +shift 1 +ARQUIVOS=$* + +if ! egrep -q "(le-testing|le-unstable|le-stable|le-educ|le5-unstable|le5-testing|le5-stable|mc-unstable|mc-testing|mc-stable)" <<< $REPOSITORIO; then + printf "\"$REPOSITORIO\": Nao conhecido" + printf ", rode $0 --help para saber mais\n" + exit 1 +fi + +for pkg in $ARQUIVOS; do + if ! test -e "$pkg"; then + echo "ERROR: file doesn't exist: $pkg" + exit 1 + fi +done + +printf "Enviando arquivos:\n" +scp $ARQUIVOS $REPOSITORIO@windu.c3sl.ufpr.br:incoming + +exit $? diff --git a/bin/update_mirror.sh b/bin/update_mirror.sh new file mode 100755 index 000000000..b5302c3ee --- /dev/null +++ b/bin/update_mirror.sh @@ -0,0 +1,174 @@ +#!/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/le" + +function clean() { + rm -rf $TMPDIR + exit 0 +} + +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" +} + +# Return a string containing the tuple package:version with all packages +# from $repoFile +function getPackagesAndVersions() { + local repoFile=$1 + 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" + done + 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 + local vFrom=$3 + local vTo=$4 + read -p "Update mirror le-$repo, $pkg ($vTo -> $vFrom) (y/N)? " yn + 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 + local version=$3 + read -p "$pkg:$version doesn't exist on le-$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 link="" + + link=$(grep -m1 "Filename:.*${pkg}/${pkg}_" $FROMREPOFILE | awk '{print $2}') + + echo "$HOST/$link" +} + +# Perform the update of package $pkg on the repository +function doUpdate() { + local pkg="$1" + local pkgFile="$TMPDIR/$pkg.deb" + + wget -q $(getDownloadLink $pkg) -O "$pkgFile" + + echo "---------------------------------------------" + echo "Updating $pkg..." + + $PUBLISHSCRIPT le-$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" +} + +# Sanity check +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" + +# 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) + found=false + for pkgVersionTo in $toPkgAndVersion; do + pkgTo=$(echo $pkgVersionTo | cut -d: -f1) + if test $pkgFrom = $pkgTo; then + versionTo=$(echo $pkgVersionTo | cut -d: -f2) + found=true + if dpkg --compare-versions $versionFrom gt $versionTo; then + if askUpdate $TOREPO $pkgTo $versionFrom $versionTo; then + 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 $pkgFrom $versionFrom; then + doUpdate $pkgTo + fi +done + +# Clean temp files before exit +clean -- GitLab