Particularly useful tips, tricks and documentation go here.

Moderators: slax, siamer

PCLOS repos: mirrors speed

Postby don_crissti » Wed Apr 01, 2009 6:29 am

Someone PMed me asking for a way to test the PCLOS mirrors speed. There are many ways to do that... I just wrote a basic Perl script, you can modify that list and and keep only your favorite mirrors. Note that results may vary, for obvious reasons...

Code: Select all
#!/usr/bin/perl

use strict;
use warnings;
use Time::HiRes qw(gettimeofday);
use LWP::UserAgent;

my $testfile = "pclinuxos/2007/base/srclist.main.bz2";
my @timedList = ();
my @badList = ();
my @reposList = (
    "http://ftp.riken.go.jp/pub/Linux/pclinuxos/apt/",
    "http://ftp.kddlabs.co.jp/Linux/packages/pclinuxos/apt/",
    "http://ftp.jaist.ac.jp/pub/Linux/PCLinuxOS/apt/",
    "http://mirror.pclinuxclub.com/pclinuxos/apt/",
    "http://www2.mirror.in.th./osarchive/pclinuxos/pclinuxos/apt/",
    "http://ftp.twaren.net/Linux/PCLinuxOS/apt/",
    "http://gnupg.cdpa.nsysu.edu.tw/Linux/PCLinuxOS/apt/",
    "http://mirror.internode.on.net/pub/pclinuxos/apt/",
    "ftp://mirror.aarnet.edu.au/pub/pclinuxos/apt/",
    "http://na.mirror.garr.it/mirrors/pclinuxos/apt/",
    "http://ftp.ch.debian.org/mirror/pclinuxos/apt/",
    "http://gnustep.ethz.ch/mirror/pclinuxos/apt/",
    "http://debian.ethz.ch/mirror/pclinuxos/apt/",
    "ftp://ftp.pbone.net/pub/pclinuxos/apt/",
    "http://ftp.klid.dk/ftp/pclinuxos/apt/",
    "http://mirrors.lastdot.org:1280/pclos/apt/",
    "http://mirrors.xservers.ro/pclinuxos/apt/",
    "http://ftp.heanet.ie/pub/pclinuxos/apt/",
    "http://ftp.belnet.be/mirror/pclinuxonline.com/apt/",
    "http://ftp.nl.freebsd.org/os/Linux/distr/texstar/pclinuxos/apt/",
    "http://ftp.sh.cvut.cz/MIRRORS/pclinuxos/apt/",
    "ftp://cesium.di.uminho.pt/pub/pclinuxos/apt/",
    "http://distrib-coffee.ipsl.jussieu.fr/pub/linux/pclinuxos/apt/",
    "http://ftp.cc.uoc.gr/mirrors/linux/pclinuxos/apt/",
    "http://ftp.leg.uct.ac.za/pub/linux/pclinuxos/apt/",
    "http://spout.ussg.indiana.edu/linux/pclinuxos/pclinuxos/apt/",
    "http://ftp.uwsg.indiana.edu/linux/pclinuxos/pclinuxos/apt/",
    "http://ftp.ussg.iu.edu/linux/pclinuxos/pclinuxos/apt/",
    "http://pclosusers.com/pclosfiles/",
    "http://distro.ibiblio.org/pub/linux/distributions/texstar/pclinuxos/apt/"
       );
print "Downloading srclist.main.bz2 from each mirror...\n";
foreach my $url (@reposList) {
    my $link = "$url$testfile";
    my $ua = LWP::UserAgent->new();
    $ua->timeout(3);
    $ua->show_progress('TRUE');
    my $t0 = gettimeofday();
    my $response = $ua->get($link);
    my $t1 = gettimeofday();
    $url =~ s|(\w+://.*?)(:\d+)?/(.*)|$1|;
    if ($response->is_success) {
        my $delta = ($t1 - $t0);
        my $line = $url.' '.$delta;
        push(@timedList, $line);
    }   else {
            push(@badList, $url);
        }
}
my @sortedList =
    map { $_->[0] }
    sort { $a->[1] <=> $b->[1] }
    map { [$_, (split)[1] ] } @timedList;
print "\nMirrors speed (time to get 400 KB):\n";
foreach (@sortedList) {
    print "$_", "s\n";
}
if (@badList) {
    print "\nThe following mirrors timed out or are not valid :\n";
    foreach (@badList) {
        print "$_", "\n";
    }
}
Those who cling to life, die; those who defy death, live.
Uesugi Kenshin
don_crissti
User avatar
Hero Member
Hero Member
 
Posts: 2261
Joined: Thu Nov 15, 2007 2:16 pm

Re: PCLOS repos: mirrors speed

Postby Texstar » Fri Apr 03, 2009 1:47 pm

Works great!
Texstar
CEO
CEO
 
Posts: 85
Joined: Tue Oct 23, 2007 11:08 pm
Location: Houston Tx

Re: PCLOS repos: mirrors speed

Postby youcantoo » Sat Apr 04, 2009 11:46 am

here is the correct url for the pclosusers.com repo

http://pclosusers.com/pclosfiles/pclinuxos/
youcantoo
New Friend
New Friend
 
Posts: 3
Joined: Sat Apr 04, 2009 11:42 am

Re: PCLOS repos: mirrors speed

Postby don_crissti » Sat Apr 04, 2009 12:05 pm

OK, added that to the list.

Thanks !
Those who cling to life, die; those who defy death, live.
Uesugi Kenshin
don_crissti
User avatar
Hero Member
Hero Member
 
Posts: 2261
Joined: Thu Nov 15, 2007 2:16 pm

Re: PCLOS repos: mirrors speed

Postby Sh4dow » Mon May 11, 2009 4:15 am

Could you add optional GUI? Simple progress bar will be enought.

TIA
Sh4dow
New Friend
New Friend
 
Posts: 2
Joined: Fri Dec 28, 2007 8:16 am

Re: PCLOS repos: mirrors speed

Postby don_crissti » Mon May 11, 2009 11:30 am

I don't have the time to build a GUI right now...
Terminal progress indicator (counter) for each mirror is piece of cake since the new perl-libwww-perl has it built-in. Unfortunately the version in the PCLOS repos is quite old and doesn't support show_progress object method.
I have however updated my script and you guys just have to wait until perl-libwww-perl goes to the repos :)
So... script updated with progress counters for each mirror :wink:
Those who cling to life, die; those who defy death, live.
Uesugi Kenshin
don_crissti
User avatar
Hero Member
Hero Member
 
Posts: 2261
Joined: Thu Nov 15, 2007 2:16 pm

Re: PCLOS repos: mirrors speed

Postby Texstar » Mon May 11, 2009 12:45 pm

perl-libwww-perl-5.826-1pclos2009.noarch.rpm going to the repos.
Texstar
CEO
CEO
 
Posts: 85
Joined: Tue Oct 23, 2007 11:08 pm
Location: Houston Tx

Re: PCLOS repos: mirrors speed

Postby don_crissti » Mon May 11, 2009 4:49 pm

OK, thanks !
Those who cling to life, die; those who defy death, live.
Uesugi Kenshin
don_crissti
User avatar
Hero Member
Hero Member
 
Posts: 2261
Joined: Thu Nov 15, 2007 2:16 pm

Re: PCLOS repos: mirrors speed

Postby travisn000 » Sat Oct 10, 2009 10:52 am

I too would also love to see that GUI !!

..but that's not the reason I'm here.. I also wanted to suggest that the script be modified to download the most recent sources.list from ibiblio, and possibly even update the sources.list in the process.

If it helps, i just added this type of functionality to the updated (for bash v4) synaptic-repair script.. If you are busy I understand... I've been meaning to translate the repo speed test idea to bash and add it to the synaptic repair script, but still haven't yet managed to get too it! :oops:

..perhaps if you do decide to create a gui the two scripts could be combined, and maybe even integrated into PCC.

Here is the new synaptic-repair bash script if you are interested:

Code: Select all

#!/bin/bash
#
#  synaptic-repair
#
#  by travisn000 <my username at gmail dot com>
#  based heavily on mkrepo, Copyright (C) 2008 by Steven J Stover <stump842@gmail.com>
#
#  This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
 


yorn () {
   local s
   while ! [[ $s =~ [ynYN] ]]; do
      read -p"$2" s
      s=${s:-$1}
      [ ${#s} -gt 1 ] && s=
   done
   echo -n $s|tr yn YN
}

bkmsg () {
   local f=$(basename "$2")
   case "$1" in
      0)   echo "Current file $f backed up as $f.old";;
      999) :;;
      *)   echo "Failed to create backup of $f";;
   esac
}

#############################################
##          Execution starts here          ##
#############################################

myname=$(basename "$0") ; NL=$'\012' ; tmpfn=$myname.$$

#if ! ps|grep $PPID|grep -q $(basename $SHELL); then
#   e="Run $myname from a console please."
#   which kdialog && exec kdialog --title $myname --caption "" --error "$e"
#   which zenity && exec zenity --title $myname --error --text="$e"
#   which konsole && exec konsole -T $myname --caption "" --noclose -e echo "$e"
#   which xterm && exec xterm -T $myname -fn *-fixed-*-*-*-20-* -hold -e echo "$e"
#   exit 0
#fi


if [ $UID -eq 0 ]; then
   echo -e "\nPlease use this command as normal user, not root."
   exit 1
fi


echo -e "\\n You have started the Synaptic Repair Tool.\n\n"
echo -e " This tool is designed to automatically repair and "
echo -e " restore Synaptic Package Manager to a functional state"
echo -e " in the event of certain underlying failures.\n\n"
echo -e " NOTE: this will delete all cached RPMs.\n\n"

if [ "$(yorn y " Would you like to continue? [Y/n] ")" = "N" ]; then
   echo -e "\nOperation cancelled."
   sleep 1
   exit 1
fi


aptsl="/etc/apt/sources.list"
atemp="atemp.$$"

cat > $tmpfn <<EOF
#!/bin/bash

echo; echo;
echo Rebuilding RPM Database..;
echo -e "(..this may take a while!)";
echo; echo;
sleep 4;
rpmdb -vv --rebuilddb;
echo Done;
echo;

makesl () {
head="# Package repository URL's

# Signed repositories have a [<key>] where <key> is the name of the key
# as it appears in vendors.list. If you remove it, no digital signature check
# will be made.
"


kde_section="kde"

if [ -d /usr/share/kde4 ]; then
   echo -e "\\nYou appear to have the KDE4 desktop installed;"
   echo -e "the KDE4 repository section will be used.."
   if [ "\$(yorn y " Is this OK? [Y/n] ")" = "N" ]; then
       kde_section="kde"
       echo -e "\nThe kde repository section for KDE3 has been selected."
   else
       kde_section="kde4"
       echo -e "\nThe kde4 repository section for KDE4 has been selected."
   fi
fi

dsx="pclinuxos/2007 main extra nonfree \${kde_section} gnome"



echo -e "\\nIf your network connection is not active, please"
read -p "activate it now, then press Enter to continue. "

echo -e "\\nRetrieving updated apt sources.list..."

rm -fR /tmp/synaptic-repair &>/dev/null
mkdir /tmp/synaptic-repair

wget --directory-prefix=/tmp/synaptic-repair http://distro.ibiblio.org/pub/linux/distributions/texstar/repo/sources.list




if [ -f /tmp/synaptic-repair/sources.list ]; then
   echo -e "Connection to ibiblio successful.."
   echo -e "Retrieved new sources.list\\n\\n"
   sleep 1

# repo list with line breaks
   repos=( \`grep rpm.*:/ /tmp/synaptic-repair/sources.list | sed -e 's@^[# \\t]*rpm @@' | cut -d" " -f1\` )

# repo list with NO line breaks
#   repos=""
#   for url in \`grep rpm.*p:// /tmp/synaptic-repair/sources.list | sed -e 's@^[# \t]*rpm @@' | cut -d" " -f1\`; do repos="\$repos \$url "; done;

else
   echo -e "\\nFAILED.\\n"
   echo -e "Unable to contact ibiblio repository for updated apt sources.list"
   if [ "\$(yorn n "Would you like to continue anyway? [y/N] ")" = "N" ]; then
      exit 1
   fi
repos=( \\
http://ftp.heanet.ie/pub/pclinuxos/apt/ \\
ftp://ftp.belnet.be/pub/mirror/pclinuxonline.com/apt/ \\
http://cesium.di.uminho.pt/pub/pclinuxos/apt/pclinuxos/2007/ \\
ftp://ftp.ch.debian.org/mirror/pclinuxos/apt/ \\
http://ftp.sh.cvut.cz/MIRRORS/pclinuxos/apt/ \\
http://ftp.nl.freebsd.org/os/Linux/distr/texstar/pclinuxos/apt/ \\
ftp://ftp.pbone.net/pub/pclinuxos/apt/ \\
ftp://rm.mirror.garr.it/mirrors/pclinuxos/apt/ \\
http://mirrors.lastdot.org:1280/pclos/apt/ \\
http://pclosusers.com/pclosusers/pclosfiles/ \\
http://ftp.leg.uct.ac.za/pub/linux/pclinuxos/apt/ \\
http://mirror.pacific.net.au/pub1/linux/texstar/pclinuxos/apt/ \\
ftp://mirror.internode.on.net/pub/pclinuxos/apt/ \\
)

fi


#  repo=""
#  for url in \`grep rpm.*p:// /etc/apt/sources.list | sed -e 's@^[# \t]*rpm @@' | cut -d" " -f1\`; do repo="\$repo \$url "; done;
#  select sel_repo in \$repo; do   echo;   echo "Your selected repo is:  \$sel_repo.";   echo;   break; done


echo
a=-1
echo "PCLinuxOS official repositories: "
for r in \${repos[@]}; do
   (( a++ ))
   echo -e "  \$a) \$( echo \$r |cut -d/ -f1-3 ) "
done
echo

while [[ "\$n" < "0" || "\$n" > "\$a" ]]
do   read -p "Choose a repo to make active [0-\$a] " n
done
active_repo="\${repos[\$n]}"
echo -e "\\n\\n  Activating \$active_repo"
echo -e "  Creating \$aptsl\\n"

rs="# rpm" ; echo "\$head" > \$aptsl
for (( r=0; r<\${#repos[@]}; r++ ))
do   (( a=\$r!=\$n?0:2 ))
   echo -e "\${rs:\$a} \${repos[\$r]} \$dsx\\n" >> \$aptsl
done

}   ###### end makesl ######



editsl_file () {
   exec 9<\${aptsl}.pre-fix #\$aptsl

   echo -e "\\n\\nLocal repo line(s) found:\\n"
   while read -u 9 r
   do   if [[ \$r =~ \$rpm_file ]]; then
         echo "\$r"
         if [ "\$(yorn y "Keep this line? [Y/n] ")" = "Y" ]; then
            if ( echo \$r | grep ^[:space:]*# ); then
                echo -e "\${r}\\n">>\$aptsl
            else
                echo -e "# \${r}\\n">>\$aptsl
            fi
            echo "..successfully recovered; you may reactivate using Synaptic"
         fi
      fi
   done
   exec 9<&-
}   ###### end editsl_file ######

editsl_pass () {
   exec 9<\${aptsl}.pre-fix

   echo -e "\\n\\nPASS repo line found:\\n"
   while read -u 9 r
   do   if [[ \$r =~ \$rpm_pass ]]; then
         echo "\$r"
         if [ "\$(yorn y "Keep this line? [Y/n] ")" = "Y" ]; then
            if ( echo \$r | grep ^[:space:]*# ); then
                echo -e "\${r}\\n">>\$aptsl
            else
                echo -e "# \${r}\\n">>\$aptsl
            fi
            echo "..successfully recovered; you may reactivate using Synaptic"
         fi

      fi
   done
   exec 9<&-
}   ###### end editsl_pass ######


yorn () {
   local s
   while ! [[ \$s =~ [ynYN] ]]; do
      read -p"\$2" s
      s=\${s:-\$1}
      [ \${#s} -gt 1 ] && s=
   done
   echo -n \$s|tr yn YN
}   ###### end yorn ######



aptsl="$aptsl" ; atemp="$atemp"
if [ -f "\$aptsl" ]; then
   cp -f --backup=t \$aptsl \${aptsl}.old &>/dev/null
   aptslbk=\$?
   cp -f --backup=t \$aptsl \${aptsl}.pre-fix
   echo -e "\\nThe file containing your current list of repositories "
   echo -e "has been backed up to \${aptsl}.pre-fix."
else
   aptslbk=999
fi
echo -n "\$aptslbk">\$atemp

makesl
echo Active Repo: \$active_repo

echo -e "\\n\\nTesting connection to selected repo...\\n"

wget_active_repo="\${active_repo}pclinuxos/2007/base/release.main"

wget --directory-prefix=/tmp/synaptic-repair \$wget_active_repo

if [ -f /tmp/synaptic-repair/release.main ]; then
   rm -f /tmp/synaptic-repair/release.main
   echo -e "Connection to repository successful.."
   echo -e "Retrieved file: \$wget_active_repo\\n\\n"
   sleep 1
else
   echo -e "\\nFAILED.\\n"
   echo -e "Unable to contact selected repository \(REQUIRED\)."
   if [ "\$(yorn n "Would you like to continue anyway? [y/N] ")" = "N" ]; then
      exit 1
   fi
fi


[ "\$aptslbk" != "999" ] && force=1

[ -n "\$force" -a -f \${aptsl}.old ] && cp -f -backup=off \${aptsl}.old \$aptsl &>/dev/null

if ! [ -f "\$aptsl" ]; then
   echo -e "Can\\'t find \$aptsl"
   exit 1
fi

rpm_file="rpm.*file:/"
egrep -q "\$rpm_file" \${aptsl}.pre-fix && editsl_file

rpm_pass="rpm.*@"
egrep -q "\$rpm_pass" \${aptsl}.pre-fix && editsl_pass

# disables.. adds new local repo in mkrepo ?
#echo -e "\\n$aptln">>\$aptsl

# -s = Squeeze multiple blank lines
cat -s \$aptsl > aptsl.tmp.\$\$
mv -f --backup=off aptsl.tmp.\$\$ \$aptsl &>/dev/null



echo;
sleep 2
echo Cleaning RPM cache..;
sleep 4;
apt-get clean;
echo Done;
echo; echo;
sleep 2
echo Updating package lists..;
apt-get update;
echo Done;
echo; echo;
sleep 2
echo Checking for broken packages..;
apt-get -f install;
echo Done;
echo; echo;
echo Updating system, please wait..;
apt-get dist-upgrade;
sleep 2

EOF

chmod +x $tmpfn
echo -n " Please enter root "
su -c "./$tmpfn"
err=$?

#[ "$err" -eq "0" ] && gbd -n

[ -f "$atemp" ] && aptslbk=$(<$atemp)
rm -f $tmpfn $atemp 2>/dev/null
aptslbk=${aptslbk:-1}
echo ; bkmsg $aptslbk $aptsl

if [ "$err" -ne "0" ]; then
   echo -e "\nAn error occurred... quitting."
   exit $err
fi


echo $myname is now finished.
echo; echo;



if [ "$(yorn y "Would you like to launch synaptic now? [Y/n] ")" = "Y" ]; then
   echo; echo;
   # -r = launch synaptic with repository selection dialog open
   synaptic -r &>/dev/null
fi

read -p "Press the Enter key to exit. "
sleep 1

exit




..maybe one day I will learn perl and do it myself!
travisn000
Jr. Member
Jr. Member
 
Posts: 15
Joined: Mon Feb 11, 2008 3:19 pm
Location: Oregon, USA

Re: PCLOS repos: mirrors speed

Postby don_crissti » Sat Oct 10, 2009 1:24 pm

Hey Travis !

I'd go for a GUI if I had the time... Perl-Gtk would be a good option for a standalone app... although for best integration in PCC I suggest you guys use ugtk+/mygtk+ as Mandy devs have written a ton of useful stuff.
As to the BASH port... here is how I'd do it, of course this is a very basic BASH translation of the perl script, quick 'n dirty stuff but you can always improve/adjust/modify it (use a regex to format the URL for better readability, add conditional blocks... well, whatever):

Code: Select all
#!/bin/bash

TESTFILE="pclinuxos/2007/base/srclist.main.bz2"
REPOSLIST="http://ftp.riken.go.jp/pub/Linux/pclinuxos/apt/
    http://ftp.kddlabs.co.jp/Linux/packages/pclinuxos/apt/
    http://ftp.jaist.ac.jp/pub/Linux/PCLinuxOS/apt/
    http://mirror.pclinuxclub.com/pclinuxos/apt/
    http://www2.mirror.in.th./osarchive/pclinuxos/pclinuxos/apt/
    http://ftp.twaren.net/Linux/PCLinuxOS/apt/
    http://gnupg.cdpa.nsysu.edu.tw/Linux/PCLinuxOS/apt/
    http://mirror.internode.on.net/pub/pclinuxos/apt/
    ftp://mirror.aarnet.edu.au/pub/pclinuxos/apt/
    http://na.mirror.garr.it/mirrors/pclinuxos/apt/
    http://ftp.ch.debian.org/mirror/pclinuxos/apt/
    http://gnustep.ethz.ch/mirror/pclinuxos/apt/
    http://debian.ethz.ch/mirror/pclinuxos/apt/
    ftp://ftp.pbone.net/pub/pclinuxos/apt/
    http://ftp.klid.dk/ftp/pclinuxos/apt/
    http://mirrors.lastdot.org:1280/pclos/apt/
    http://mirrors.xservers.ro/pclinuxos/apt/
    http://ftp.heanet.ie/pub/pclinuxos/apt/
    http://ftp.belnet.be/mirror/pclinuxonline.com/apt/
    http://ftp.nl.freebsd.org/os/Linux/distr/texstar/pclinuxos/apt/
    http://ftp.sh.cvut.cz/MIRRORS/pclinuxos/apt/
    ftp://cesium.di.uminho.pt/pub/pclinuxos/apt/
    http://distrib-coffee.ipsl.jussieu.fr/pub/linux/pclinuxos/apt/
    http://ftp.cc.uoc.gr/mirrors/linux/pclinuxos/apt/
    http://ftp.leg.uct.ac.za/pub/linux/pclinuxos/apt/
    http://spout.ussg.indiana.edu/linux/pclinuxos/pclinuxos/apt/
    http://ftp.uwsg.indiana.edu/linux/pclinuxos/pclinuxos/apt/
    http://ftp.ussg.iu.edu/linux/pclinuxos/pclinuxos/apt/
    http://pclosusers.com/pclosfiles/
    http://distro.ibiblio.org/pub/linux/distributions/texstar/pclinuxos/apt/"

TIMEOUT="3"
GOODLIST=""
BADLIST=""

for REPO in $REPOSLIST ; do
    URL="${REPO}%{TESTFILE}"
    GETTIME=$(curl --max-time $TIMEOUT --silent --output /dev/null --write-out %{time_total} $URL)

    if [ "$GETTIME" == "0.000" ] ; then
        echo -e "$REPO\tFail"
        BADLIST="${BADLIST}${REPO}\n";
    else
        echo -e "$REPO\t$GETTIME"
        GOODLIST="${GOODLIST}${GETTIME}\t${REPO}\n";
    fi

done;

echo "\nMirrors speed (time to get 400 KB):\n"
echo -e $GOODLIST | sort -n

if  [ "$BADLIST" != "" ] ; then
    echo -e "\nThe following mirrors timed out or are not valid :\n"
    echo -e $BADLIST;
fi

HTH !
Regards,

Don
Those who cling to life, die; those who defy death, live.
Uesugi Kenshin
don_crissti
User avatar
Hero Member
Hero Member
 
Posts: 2261
Joined: Thu Nov 15, 2007 2:16 pm

Re: PCLOS repos: mirrors speed

Postby travisn000 » Sat Oct 10, 2009 1:59 pm

Thanks Don.. that will make it quite easy.

The synaptic-repair script already puts together a well formatted repolist by parsing an up to date sources.list that tex has put on ibiblio just for the script... ..I just hadn't taken the time to figure out how to to time the downloads.. I think I can pretty easily integrate your bash script into what I currently have..


Thanks again!

(..he goes off to play :mrgreen: )
travisn000
Jr. Member
Jr. Member
 
Posts: 15
Joined: Mon Feb 11, 2008 3:19 pm
Location: Oregon, USA

Re: PCLOS repos: mirrors speed

Postby don_crissti » Sat Oct 10, 2009 6:01 pm

Travis,

As to this:
I also wanted to suggest that the script be modified to download the most recent sources.list from ibiblio, and possibly even update the sources.list in the process.

I modified the perl script as per your suggestion. Comments in the script... Let me know if there's something unclear. Note that you have to manually create the /root/.repotest directory. No need to add a conditional block in the script as you only have to do it once. Also, Tex's file will only be downloaded under certain circumstances :) :
$ua->mirror( $url, $filename )

This method will get the document identified by $url and store it in file called $filename. If the file already exists, then the request will contain an "If-Modified-Since" header matching the modification time of the file. If the document on the server has not changed since this time, then nothing happens. If the document has been updated, it will be downloaded again. The modification time of the file will be forced to match that of the server.

The return value is the response object.

for more details read here:

http://kobesearch.cpan.org/htdocs/libwww-perl/LWP/UserAgent.html

Here is my modified script:

Code: Select all
#!/usr/bin/perl

use strict;
use warnings;
use POSIX;
use IO::File;
use Time::HiRes qw(gettimeofday);
use LWP::UserAgent;

# check for root
unless ($> == 0 || $< == 0) {
    die( "You must be root to run this script.\n" );
}

my ($text,$pkg,$fastest);
my (@sortedList,@timedList,@badList,@reposList,@lines) = ();
my $aptSources = "/etc/apt/sources.list";
my $testfile = "pclinuxos/2007/base/srclist.main.bz2";
my $sections = " pclinuxos/2007 main extra nonfree kde gnome ";
my $texSources = "http://distro.ibiblio.org/pub/linux/distributions/texstar/repo/sources.list";

# you have to create this directory manually before running the script !!!
my $logdir = "/root/.repotest";

# get Tex list from ibiblio - HOW THIS WORKS: since /etc/apt/sources.list already exists, then the request will contain an "If-Modified-Since" header matching the modification time of the file. If the document on the server has not changed since this time, then nothing happens. If the document has been updated, it will be downloaded again. The modification time of the file will be forced to match that of the server.
print "Downloading new sources list...\n";
my $uad = LWP::UserAgent->new();
$uad->timeout(7);
$uad->show_progress('TRUE');
$uad->mirror( $texSources, $aptSources );

# we grep lines containing http or ftp
print "Updating your sources list...\n";
open (MYSOURCES, $aptSources) or die "Could not open /etc/apt/sources.list: $!\n";
    @lines = <MYSOURCES>;
    @lines = grep(/http|ftp$/,@lines);
close MYSOURCES;

# we need only the URL from those lines
foreach (@lines) {
    chomp $_;
    $_ =~ s|(.*rpm\s)(\S+)(\s)(.*)|$2|;
    push(@reposList, $_);
}

# now the speed test
print "Downloading srclist.main.bz2 from each mirror...\n";
foreach my $url (@reposList) {
    my $link = "$url$testfile";
    my $ua = LWP::UserAgent->new();
    $ua->timeout(3);
    $ua->show_progress('TRUE');
    my $t0 = gettimeofday();
    my $response = $ua->get($link);
    my $t1 = gettimeofday();
    if ($response->is_success) {
        my $delta = ($t1 - $t0);
        my $line = $url.' '.$delta;
        push(@timedList, $line);
    }   else {
            push(@badList, $url);
        }
}

# sort results, re-write /etc/apt/sources.list accordingly, write logs
if (@timedList) {
   @sortedList = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [$_, (split)[1] ] } @timedList;
      if ($sortedList[0] =~ /^(\S+)(\s)(\S+)/) {
      $fastest = $1;
      }
    open(SOURCES, ">$aptSources") or die "Error trying to write to file: $!";
   foreach my $url (@reposList) {
      chomp $url;
      if ($url eq $fastest) {
          $pkg = "rpm ";
      }    else {
          $pkg = "#rpm ";
      }
       $text = $pkg.$url.$sections;
      print SOURCES "$text\n";
   }
    close (SOURCES);
   my $logdate = set_logdate();
   my $logfile = "$logdir/$logdate.log";
    open(LOG, ">$logfile") or die "Error trying to write to file: $!";
   print LOG "Speed test results (seconds to download 400KB):\n\n";
      foreach (@sortedList) {
      print LOG "$_", "s\n";
      }
      if (@badList) {
         print LOG "\nThe following mirrors have not responded in a timely manner:\n\n";
            foreach (@badList) {
            print LOG "$_\n";
            }

      }   
   close (LOG);
}    else {
   print "It appears none of the mirrors is responding.\nMake sure you're connected to the internet and try again.\n";
}

# set log date as HourMinSec-Day-Month-Year.log
sub set_logdate {
   my @date = (localtime)[0..5];
   foreach my $tm (@date) {
      if  ( $tm < 10 ) {
         $tm = "0".$tm;
      }
   }
   my $date = $date[2].$date[1].$date[0].'-'.$date[3].'-'.($date[4] + 1).'-'.($date[5] + 1900);
   chomp $date;
   return $date;
}
exit 0;


Enjoy !
Those who cling to life, die; those who defy death, live.
Uesugi Kenshin
don_crissti
User avatar
Hero Member
Hero Member
 
Posts: 2261
Joined: Thu Nov 15, 2007 2:16 pm

Re: PCLOS repos: mirrors speed

Postby travisn000 » Sun Oct 25, 2009 5:12 pm

Looks good!

I was also successful at integrating the speed test into my synaptic-repair script using your bash code. I did have to modify the curl line to use speed_download instead of total_time, as total time was not returning 0.000 on bogus / dead servers (apparently total_time includes time trying to connect & waiting for a response)

The last "feature" I wanted to add is some method of checking the time stamp on the srclist.main.bz2 file so that I can verify that it is of an appropriate age (not greater than 2 wks old.. 1209600 seconds, or maybe 30 days), but unfortunately I cannot figure out a way to do this. :x

I tried wget -N as suggested by some google results, but it doesn't keep the timestamp on the d/l file

I tried using curl / awk to parse the html for the directory listings that most servers provide, but the formatting is too inconsistent across the different repo servers and some don't even generate an html directory listing:

Code: Select all
#!/bin/bash

# For testing purposes..
REPOSLIST="http://ftp.heanet.ie/pub/pclinuxos/apt/
ftp://ftp.belnet.be/pub/mirror/pclinuxonline.com/apt/
http://cesium.di.uminho.pt/pub/pclinuxos/apt/pclinuxos/2007/
ftp://ftp.ch.debian.org/mirror/pclinuxos/apt/
http://ftp.sh.cvut.cz/MIRRORS/pclinuxos/apt/
http://ftp.nl.freebsd.org/os/Linux/distr/texstar/pclinuxos/apt/
ftp://ftp.pbone.net/pub/pclinuxos/apt/
ftp://rm.mirror.garr.it/mirrors/pclinuxos/apt/
http://mirrors.lastdot.org:1280/pclos/apt/
http://pclosusers.com/pclosusers/pclosfiles/
http://ImBad.pclosusersImBad.com./pclosusers/pclosfiles/
http://ImBad2.pclosusers.ImBad.com/pclosusers/pclosfiles/
http://ftp.leg.uct.ac.za/pub/linux/pclinuxos/apt/
http://mirror.pacific.net.au/pub1/linux/texstar/pclinuxos/apt/
ftp://mirror.internode.on.net/pub/pclinuxos/apt/"


TESTFILE="srclist.main.bz2"
TESTFILEDIR="pclinuxos/2007/base/"
TIMEOUT="5"
GOODLIST=""
BADLIST=""
NOW=`date +%s`

echo -e "\nTesting repo average download speeds..\n"
for REPO in $REPOSLIST ; do
    URL="${REPO}${TESTFILEDIR}${TESTFILE}"
    URLDIR=$( echo -e "${REPO}${TESTFILEDIR}" | cut -d: -f2)
    URLDIR="http:${URLDIR}"
    GETTIME=$(curl --max-time ${TIMEOUT} --silent --output /dev/null --write-out %{speed_download} ${URL})

#  ..if age cannot be calculated, set it to 1209601 (..older than two weeks)
TESTFILE_TIMESTAMP=$(curl $URLDIR -silent | awk '/srclist.main.bz2/{ print $8; exit }') # && AGE=$(($NOW-$TESTFILE_TIMESTAMP)) ||
AGE=120960

# if older than two weeks, also send to BADLIST
    if [ "$AGE" -gt "1209600" ] || [ "$GETTIME" ==  "0.000" ]; then
   echo -e "$REPO\tFail"
   BADLIST="${BADLIST}${REPO}\n";
    else
   echo -e "$REPO\t$GETTIME"
   GOODLIST="${GOODLIST}${GETTIME}\t${REPO}\n";
    fi
# FOR DEBUGGING:
echo -e "HTML=$(curl $URLDIR -silent | awk '/srclist.main.bz2/{ print $0; exit }')"
echo -e "DATE=$TESTFILE_TIMESTAMP\n"

done;

echo -e "\nMirrors speed: \n(average download speed in bytes/seconds for ~500 KB file) "
echo -e $GOODLIST | sort -n


if  [ "$BADLIST" != "" ] ; then
    echo
    echo -e "\nThe following mirrors timed out, are out-dated, or are not valid:\n"
    echo -e "$BADLIST\n\n";
fi



..output of the above script is as follows:
Code: Select all

Testing repo average download speeds..

http://ftp.heanet.ie/pub/pclinuxos/apt/ 154305.000
HTML=<img src="/icons/unknown.gif" alt="[   ]" /> <a href="srclist.main.bz2">srclist.main.bz2</a>                   20-Oct-2009 13:07  505K 
DATE=20-Oct-2009                                                                                                                             

ftp://ftp.belnet.be/pub/mirror/pclinuxonline.com/apt/   34373.000
HTML=<img src="/icons/unknown.gif" alt="[   ]"> <a href="srclist.main.bz2">srclist.main.bz2</a>                                  20-Oct-2009 14:07  505K                                                                                                                                                 
DATE=14:07                                                                                                                                           

http://cesium.di.uminho.pt/pub/pclinuxos/apt/pclinuxos/2007/    1793.000
HTML=                                                                   
DATE=                                                                   

ftp://ftp.ch.debian.org/mirror/pclinuxos/apt/   38929.000
HTML=<img src="/icons/unknown.gif" alt="[   ]"> <a href="srclist.main.bz2">srclist.main.bz2</a>                      20-Oct-2009 14:07  505K 
DATE=14:07                                                                                                                                   

http://ftp.sh.cvut.cz/MIRRORS/pclinuxos/apt/    157439.000
HTML=<tr><td valign="top"><img src="/icons/unknown.png" alt="[   ]" width="15" height="15"></td><td><a href="srclist.main.bz2">srclist.main.bz2</a></td><td align="right">20-Oct-2009 14:07  </td><td align="right">505K</td></tr>                                                                       
DATE=href="srclist.main.bz2">srclist.main.bz2</a></td><td                                                                                           

http://ftp.nl.freebsd.org/os/Linux/distr/texstar/pclinuxos/apt/ 114975.000
HTML=<img src="/icons/unknown.gif" alt="[   ]"> <a href="srclist.main.bz2">srclist.main.bz2</a>                                      20-Oct-2009 00:11  505K                                                                                                                                             
DATE=00:11                                                                                                                                           

ftp://ftp.pbone.net/pub/pclinuxos/apt/  41346.000
HTML=                                           
DATE=                                           

ftp://rm.mirror.garr.it/mirrors/pclinuxos/apt/  Fail
HTML=                                               
DATE=                                               

http://mirrors.lastdot.org:1280/pclos/apt/      118836.000
HTML=                                                     
DATE=                                                     

http://pclosusers.com/pclosusers/pclosfiles/    546464.000
HTML=<tr><td valign="top"><img src="/icons/unknown.gif" alt="[   ]"></td><td><a href="srclist.main.bz2">srclist.main.bz2</a></td><td align="right">20-Oct-2009 05:07  </td><td align="right">505K</td></tr>                                                                                               
DATE=05:07                                                                                                                                           

http://ImBad.pclosusersImBad.com./pclosusers/pclosfiles/        Fail
HTML=                                                               
DATE=                                                               

http://ImBad2.pclosusers.ImBad.com/pclosusers/pclosfiles/       Fail
HTML=                                                               
DATE=                                                               

http://ftp.leg.uct.ac.za/pub/linux/pclinuxos/apt/       12184.000
HTML=<tr><td valign="top"><img src="/icons/unknown.gif" alt="[   ]" /></td><td><a href="srclist.main.bz2">srclist.main.bz2</a></td><td align="right">20-Oct-2009 14:07  </td><td align="right">505K</td></tr>                                                                                             
DATE=align="right">20-Oct-2009                                                                                                                       

http://mirror.pacific.net.au/pub1/linux/texstar/pclinuxos/apt/  848.000
HTML=                                                                 
DATE=

ftp://mirror.internode.on.net/pub/pclinuxos/apt/        Fail
HTML=<img src="/icons/unknown.gif" alt="[   ]"> <a href="srclist.main.bz2">srclist.main.bz2</a>                   20-Oct-2009 22:37  505K
DATE=22:37


Mirrors speed:
(average download speed in bytes/seconds for ~500 KB file)

848.000 http://mirror.pacific.net.au/pub1/linux/texstar/pclinuxos/apt/
1793.000        http://cesium.di.uminho.pt/pub/pclinuxos/apt/pclinuxos/2007/
12184.000       http://ftp.leg.uct.ac.za/pub/linux/pclinuxos/apt/
34373.000       ftp://ftp.belnet.be/pub/mirror/pclinuxonline.com/apt/
38929.000       ftp://ftp.ch.debian.org/mirror/pclinuxos/apt/
41346.000       ftp://ftp.pbone.net/pub/pclinuxos/apt/
114975.000      http://ftp.nl.freebsd.org/os/Linux/distr/texstar/pclinuxos/apt/
118836.000      http://mirrors.lastdot.org:1280/pclos/apt/
154305.000      http://ftp.heanet.ie/pub/pclinuxos/apt/
157439.000      http://ftp.sh.cvut.cz/MIRRORS/pclinuxos/apt/
546464.000      http://pclosusers.com/pclosusers/pclosfiles/


The following mirrors timed out, are out-dated, or are not valid:

ftp://rm.mirror.garr.it/mirrors/pclinuxos/apt/
http://ImBad.pclosusersImBad.com./pclosusers/pclosfiles/
http://ImBad2.pclosusers.ImBad.com/pclosusers/pclosfiles/
ftp://mirror.internode.on.net/pub/pclinuxos/apt/




..any suggestions ???
travisn000
Jr. Member
Jr. Member
 
Posts: 15
Joined: Mon Feb 11, 2008 3:19 pm
Location: Oregon, USA

Re: PCLOS repos: mirrors speed

Postby don_crissti » Sun Oct 25, 2009 7:14 pm

I don't know if this is what you actually need but why don't you try to play with cURL -z option:
-z/--time-cond <date expression>
(HTTP) Request a file that has been modified later than the given time and date, or one that has been modified before that time. The date expression can be all sorts of date strings or if it doesn't match any internal ones, it tries to get the time from a given file name instead!

See man curl for more details if needed.

Now, this one is really off-topic but just for fun (linux is about having fun after all :mrgreen: ), I'm going to use the -R option to download the srclist.main.bz2 from heanet and see the timestamp of that file (it'll be the same on my machine as that's what the -R does).
-R/--remote-time
When used, this will make libcurl attempt to figure out the timestamp of the remote file, and if that is available make the local file get that same timestamp.

Code: Select all
[me@isis ~]$ curl -R -C - -O http://ftp.heanet.ie/pub/pclinuxos/apt/pclinuxos/2007/base/srclist.main.bz2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  505k  100  505k    0     0   273k      0  0:00:01  0:00:01 --:--:--  301k
[me@isis ~]$ stat srclist.main.bz2
  File: `srclist.main.bz2'
  Size: 517142       Blocks: 1024       IO Block: 4096   regular file
Device: 811h/2065d   Inode: 1353872     Links: 1
Access: (0644/-rw-r--r--)  Uid: (  501/  me)   Gid: (  501/  me)
Access: 2009-10-20 08:07:20.000000000 -0400
Modify: 2009-10-20 08:07:20.000000000 -0400

As you can see the file on heanet was last modified on October, 20. So it's about 5 days old

Let's get back to our problem:
We're gonna tell cURL to download the file only if it was modified later than October 24:

Code: Select all
[me@isis ~]$ curl -z 20091024 -C - -O http://ftp.heanet.ie/pub/pclinuxos/apt/pclinuxos/2007/base/srclist.main.bz2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

As you can see nothing happens, as that file last modified time was before October 24 so curl won't bother to download it.
But if we change the date to October 19 this is what happens:

Code: Select all
[me@isis ~]$ curl -z 20091019 -C - -O http://ftp.heanet.ie/pub/pclinuxos/apt/pclinuxos/2007/base/srclist.main.bz2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  505k  100  505k    0     0   286k      0  0:00:01  0:00:01 --:--:--  317k

So, a curl line to benchmark the download of a file modified after October 20 should look like this :

Code: Select all
[me@isis ~]$ curl -z 20091019 --max-time 3 --silent --output /dev/null --write-out %{time_total} http://ftp.heanet.ie/pub/pclinuxos/apt/pclinuxos/2007/base/srclist.main.bz2
2.284

Unless there is a way to input a time frame (that I'm not aware of but I ain't no curl expert... you can read HERE some more info) , you'll have to write a piece of code for the time interval conversion, i.e. those 1209600 seconds have to be converted into a pure date number of the form YYYYMMDD at script runtime. That shouldn't be a problem though...

So, IMO, using -z should solve your problem.

HTH.

Don
Those who cling to life, die; those who defy death, live.
Uesugi Kenshin
don_crissti
User avatar
Hero Member
Hero Member
 
Posts: 2261
Joined: Thu Nov 15, 2007 2:16 pm

Re: PCLOS repos: mirrors speed

Postby travisn000 » Mon Oct 26, 2009 8:38 pm

Once again, thank you!

..I did skim through the curl man pages quite a few times before posting but I guess my ADHD got the best of me... I either missed or misused those options in my testing! :oops:

-z was just what was needed; here is the final (..for now) product:

Code: Select all
#!/bin/bash
#
#  synaptic-repair
#

#
#  This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
 


yorn () {
   local s
   while ! [[ $s =~ [ynYN] ]]; do
      read -p"$2" s
      s=${s:-$1}
      [ ${#s} -gt 1 ] && s=
   done
   echo -n $s|tr yn YN
}

bkmsg () {
   local f=$(basename "$2")
   case "$1" in
      0)   echo "Current file $f backed up as $f.old";;
      999) :;;
      *)   echo "Failed to create backup of $f";;
   esac
}

#############################################
##          Execution starts here          ##
#############################################

myname=$(basename "$0") ; NL=$'\012' ; tmpfn=$myname.$$

#if ! ps|grep $PPID|grep -q $(basename $SHELL); then
#   e="Run $myname from a console please."
#   which kdialog && exec kdialog --title $myname --caption "" --error "$e"
#   which zenity && exec zenity --title $myname --error --text="$e"
#   which konsole && exec konsole -T $myname --caption "" --noclose -e echo "$e"
#   which xterm && exec xterm -T $myname -fn *-fixed-*-*-*-20-* -hold -e echo "$e"
#   exit 0
#fi

# check that package managers are closed
for idx in synaptic smart ksmarttray kpackage apt-get
do
 if [ -n "`pidof $idx`" ]; then
#  zenity --error --title="$TITLE" --text=$"Please close your package manager '$idx' and then click on the link again.\n\nExiting..."
  echo -e "Please close your ${idx} package manager and then try again.\n\nExiting...\n\n"
  sleep 2
  exit 1
 fi
done


if [ $UID -eq 0 ]; then
   echo -e "\nPlease use this command as normal user, not root."
   exit 1
fi


echo -e "\\n You have started the Synaptic Repair Tool.\n\n"
echo -e " This tool is designed to automatically repair and "
echo -e " restore Synaptic Package Manager to a functional state"
echo -e " in the event of certain underlying failures.\n\n"
#echo -e " NOTE: this will delete all cached RPMs.\n\n"

if [ "$(yorn y " Would you like to continue? [Y/n] ")" = "N" ]; then
   echo -e "\nOperation cancelled."
   sleep 1
   exit 1
fi


aptsl="/etc/apt/sources.list"
atemp="atemp.$$"

cat > $tmpfn <<EOF
#!/bin/bash


yorn () {
   local s
   while ! [[ \$s =~ [ynYN] ]]; do
      read -p"\$2" s
      s=\${s:-\$1}
      [ \${#s} -gt 1 ] && s=
   done
   echo -n \$s|tr yn YN
}   ###### end yorn ######



echo; echo;
if [ "\$(yorn y "Would you like to rebuild the RPM Database? (..this may take a while!) [Y/n] ")" = "Y" ]; then
    echo Rebuilding RPM Database..;
#     echo -e "(..this may take a while!)";
#     sleep 4;
    echo -e "\\n\\n"
    rpmdb -vv --rebuilddb;
    echo -e "\\nRPM database rebuild complete\!\\n";
fi


makesl () {
head="# Package repository URL's

# Signed repositories have a [<key>] where <key> is the name of the key
# as it appears in vendors.list. If you remove it, no digital signature check
# will be made.
"


kde_section="kde"

if [ -d /usr/share/kde4 ]; then
   echo -e "\\nYou appear to have the KDE4 desktop installed;"
   echo -e "the KDE4 repository section should be used.."
   if [ "\$(yorn y " Is this correct? [Y/n] ")" = "N" ]; then
       kde_section="kde"
       echo -e "\nThe kde repository section for KDE3 has been selected."
   else
       kde_section="kde4"
       echo -e "\nThe kde4 repository section for KDE4 has been selected."
   fi
fi

dsx="pclinuxos/2007 main extra nonfree \${kde_section} "



echo -e "\\nIf your network connection is not active, please"
read -p "activate it now, then press Enter to continue. "

echo -e "\\nRetrieving updated apt sources.list..."

rm -fR /tmp/synaptic-repair &>/dev/null
mkdir /tmp/synaptic-repair
wget --directory-prefix=/tmp/synaptic-repair http://distro.ibiblio.org/pub/linux/distributions/texstar/repo/sources.list





if [ -f /tmp/synaptic-repair/sources.list ]; then
   echo -e "Connection to ibiblio successful.."
   echo -e "Retrieved new sources.list\\n\\n"
#   sleep 1

# repo list with line breaks
   REPOSLIST=( \`grep rpm.*:/ /tmp/synaptic-repair/sources.list | sed -e 's@^[# \\t]*rpm @@' | cut -d" " -f1\` )

# repo list with NO line breaks
#   REPOSLIST=""
#   for url in \`grep rpm.*p:// /tmp/synaptic-repair/sources.list | sed -e 's@^[# \t]*rpm @@' | cut -d" " -f1\`; do REPOSLIST="\$REPOSLIST \$url "; done;

else
   echo -e "\\nFAILED.\\n"
   echo -e "Unable to contact ibiblio repository for updated apt sources.list"
   if [ "\$(yorn n "Would you like to continue anyway? [y/N] ")" = "N" ]; then
      exit 1
   fi

REPOSLIST=( \\
http://ftp.heanet.ie/pub/pclinuxos/apt/ \\
ftp://ftp.belnet.be/pub/mirror/pclinuxonline.com/apt/ \\
http://cesium.di.uminho.pt/pub/pclinuxos/apt/pclinuxos/2007/ \\
ftp://ftp.ch.debian.org/mirror/pclinuxos/apt/ \\
http://ftp.sh.cvut.cz/MIRRORS/pclinuxos/apt/ \\
http://ftp.nl.freebsd.org/os/Linux/distr/texstar/pclinuxos/apt/ \\
ftp://ftp.pbone.net/pub/pclinuxos/apt/ \\
ftp://rm.mirror.garr.it/mirrors/pclinuxos/apt/ \\
http://mirrors.lastdot.org:1280/pclos/apt/ \\
http://pclosusers.com/pclosusers/pclosfiles/ \\
http://ftp.leg.uct.ac.za/pub/linux/pclinuxos/apt/ \\
http://mirror.pacific.net.au/pub1/linux/texstar/pclinuxos/apt/ \\
ftp://mirror.internode.on.net/pub/pclinuxos/apt/ \\
)

fi


echo
ans=""
while ! [[ \$ans == [0-9] || \$ans == [0-9][0-9] ]]; do
    read -p"Enter acceptable repo sync age (0-99 days): " ans
done



TESTFILE="srclist.main.bz2"
TESTFILEDIR="pclinuxos/2007/base/"
DATE_OLD=\$(date --date "now - \$ans days" +%Y%m%d) #; echo \$DATE_OLD
TIMEOUT="5"
GOODLIST=""
BADLIST=""

echo -e "\\nTesting repo sync age and download speeds..\\n"
for REPO in \${REPOSLIST[@]} ; do
    URL="\${REPO}\${TESTFILEDIR}\${TESTFILE}"
    GETTIME=\$(curl --max-time \${TIMEOUT} --time-cond \${DATE_OLD} --silent --write-out %{speed_download} -O \${URL})
#    GETTIME=\$(curl --max-time \${TIMEOUT} --time-cond \${DATE_OLD} --silent --write-out %{total_time} -O \${URL})

    if [ "\$GETTIME" ==  "0.000" ]; then
   echo -e "\$REPO\\tFail"
   BADLIST="\${BADLIST}\${REPO}\n";
    else
   echo -e "\$REPO\t\$GETTIME"
   GOODLIST="\${GOODLIST}\${GETTIME}  \t\${REPO}\\n";
    fi

done


echo -e "\nMirrors speed: \n(average download speed in bytes/seconds for ~500 KB file) "
echo -e \$GOODLIST | sort -n

finalrepolist=( \`echo -e \$GOODLIST | sort -n | cut -d"   " -f2\` )

echo -e "\\n\\nfinalrepolist=\\n\$finalrepolist"

if  [ "\$BADLIST" != "" ] ; then
    echo
    echo -e "\\nThe following mirrors timed out, are out of date, or are not valid :\\n"
    echo -e \$BADLIST;
fi



#  repo=""
#  for url in \`grep rpm.*p:// /etc/apt/sources.list | sed -e 's@^[# \t]*rpm @@' | cut -d" " -f1\`; do repo="\$repo \$url "; done;
#  select sel_repo in \$repo; do   echo;   echo "Your selected repo is:  \$sel_repo.";   echo;   break; done


echo -e "\\nPCLinuxOS official repositories: \\n(ordered by speed-test results, fastest at the bottom)\\n\\n"

a=-1
if  [ "\$finalrepolist" != "" ]; then
    for r in \${finalrepolist[@]} ; do
       (( a++ ))
       echo -e "  \$a) \$( echo \$r |cut -d/ -f1-3 ) "
    done
    echo

    while [[ "\$n" < "0" || "\$n" > "\$a" ]]
    do   read -p "Choose a repo to make active [0-\$a] " n
    done

    active_repo="\${finalrepolist[\$n]}"
    echo -e "\\n\\n  Activating \$active_repo"
    echo -e "  Creating \$aptsl\\n"

    rs="# rpm" ; echo "\$head" > \$aptsl
    for (( r=0; r<\${#finalrepolist[@]}; r++ ))
    do   (( a=\$r!=\$n?0:2 ))
       echo -e "\${rs:\$a} \${finalrepolist[\$r]} \$dsx\\n" >> \$aptsl
    done
else
    echo -e "\\nUnable to contact ALL PCLinuxOS software repositories \(REQUIRED\).\\nYour repository sources.list will not be updated\\n\\n"
    if [ "\$(yorn n "Would you like to continue anyway? [y/N] ")" = "N" ]; then
       echo -e "\\n\\nExiting..  please verify your network connection and try again.\\n\\n"
       sleep 3
       exit 1
    fi
fi

}   ###### end makesl ######



editsl_file () {
   exec 9<\${aptsl}.pre-fix #\$aptsl

   echo -e "\\n\\nLocal repo line(s) found:\\n"
   while read -u 9 r
   do   if [[ \$r =~ \$rpm_file ]]; then
         echo -e "\$r\\n"
         if [ "\$(yorn y "Keep this line? [Y/n] ")" = "Y" ]; then
            if ( echo \$r | grep ^[:space:]*# ); then
                echo -e "\${r}\\n">>\$aptsl
            else
                echo -e "# \${r}\\n">>\$aptsl
            fi
            echo -e "\\n..successfully recovered; you may reactivate using Synaptic\\n"
         fi
      fi
   done
   exec 9<&-
}   ###### end editsl_file ######

editsl_pass () {
   exec 9<\${aptsl}.pre-fix

   echo -e "\\n\\nPASS repo line found:\\n"
   while read -u 9 r
   do   if [[ \$r =~ \$rpm_pass ]]; then
         echo -e "\$r\\n"
         if [ "\$(yorn y "Keep this line? [Y/n] ")" = "Y" ]; then
            if ( echo \$r | grep ^[:space:]*# ); then
                echo -e "\${r}\\n">>\$aptsl
            else
                echo -e "# \${r}\\n">>\$aptsl
            fi
            echo -e "\\n..successfully recovered; you may reactivate using Synaptic\\n"
         fi

      fi
   done
   exec 9<&-
}   ###### end editsl_pass ######


aptsl="$aptsl" ; atemp="$atemp"
if [ -f "\$aptsl" ]; then
   cp -f --backup=t \$aptsl \${aptsl}.old &>/dev/null
   aptslbk=\$?
   cp -f --backup=t \$aptsl \${aptsl}.pre-fix
   echo -e "\\nThe file containing your current list of repositories "
   echo -e "has been backed up to \${aptsl}.pre-fix."
else
   aptslbk=999
fi
echo -n "\$aptslbk">\$atemp


makesl
echo Active Repo: \$active_repo



#### disabled as connection now verified by repo speed test above ####
# echo -e "\\n\\nTesting connection to selected repo...\\n"
# wget_active_repo="\${active_repo}pclinuxos/2007/base/release.main"
#
# wget --directory-prefix=/tmp/synaptic-repair \$wget_active_repo
#
# if [ -f /tmp/synaptic-repair/release.main ]; then
#    rm -f /tmp/synaptic-repair/release.main
#    echo -e "Connection to repository successful.."
#    echo -e "Retrieved file: \$wget_active_repo\\n\\n"
#    sleep 1
# else
#    echo -e "\\nFAILED.\\n"
#    echo -e "Unable to contact selected repository \(REQUIRED\)."
#    if [ "\$(yorn n "Would you like to continue anyway? [y/N] ")" = "N" ]; then
#       exit 1
#    fi
# fi


[ "\$aptslbk" != "999" ] && force=1

[ -n "\$force" -a -f \${aptsl}.old ] && cp -f -backup=off \${aptsl}.old \$aptsl &>/dev/null

if ! [ -f "\$aptsl" ]; then
   echo -e "Can\\'t find \$aptsl"
   exit 1
fi



rpm_file="rpm.*file:/"
egrep -q "\$rpm_file" \${aptsl}.pre-fix && editsl_file

rpm_pass="rpm.*@"
egrep -q "\$rpm_pass" \${aptsl}.pre-fix && editsl_pass


# -s = Squeeze multiple blank lines
cat -s \$aptsl > aptsl.tmp.\$\$
mv -f --backup=off aptsl.tmp.\$\$ \$aptsl &>/dev/null



echo;
sleep 2
echo "It is reccomended that the RPM cache be cleaned to remove\\nthe possibility that it contains corrupt packages."
if  [ "\$(yorn y "Would you like to clean the RPM cache? [Y/n] ")" = "Y" ]; then
    echo Cleaning RPM cache..;
    sleep 4;
    apt-get clean;
    echo Done
fi
echo; echo; sleep 2
echo Updating package lists..;
apt-get update;
echo -e "Done\\n\\n\\n"
sleep 2
echo Checking for broken packages..;
apt-get -f install;
echo -e "Done\\n\\n\\n"
echo Updating system, please wait..;
apt-get dist-upgrade;
sleep 2

exit

EOF

chmod +x $tmpfn
echo -n " Please enter root "
su -c "./$tmpfn"
err=$?

#[ "$err" -eq "0" ] && gbd -n

[ -f "$atemp" ] && aptslbk=$(<$atemp)
rm -f $tmpfn $atemp 2>/dev/null
aptslbk=${aptslbk:-1}
echo ; bkmsg $aptslbk $aptsl

if [ "$err" -ne "0" ]; then
   echo -e "\nAn error occurred... quitting."
   exit $err
fi


echo $myname is now finished.
echo; echo;



if [ "$(yorn y "Would you like to launch synaptic now? [Y/n] ")" = "Y" ]; then
   echo; echo;
   # -r = launch synaptic with repository selection dialog open
   ( synaptic -r &>/dev/null )&
fi

read -p "Press the Enter key to exit. "
sleep 1

exit



EDIT:

NOTE - Please post all feedback related to this script in the following forum / topic:
http://www.pclinuxos.com/forum/index.ph ... 308.0.html
(..lets not hijack this one any more than I already have! :mrgreen: )
travisn000
Jr. Member
Jr. Member
 
Posts: 15
Joined: Mon Feb 11, 2008 3:19 pm
Location: Oregon, USA

Next
Forum Statistics

Who is online

Users browsing this forum: No registered users and 1 guest

Options

Return to Howtos, Tips & Tricks