From b74b784f67f1e935869886fbf71bad2b1eb8f3a6 Mon Sep 17 00:00:00 2001 From: Joseph Graham Date: Mon, 2 Jun 2014 07:12:56 +0100 Subject: Made it get the .torrent files from any of the mirrors. Made the progress indicator tell whether it is downloading the packages by http or p2p. --- pacman2pacman-get | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/pacman2pacman-get b/pacman2pacman-get index fd7ed37..61e1ec5 100644 --- a/pacman2pacman-get +++ b/pacman2pacman-get @@ -18,9 +18,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - -# Where Pacman2pacman will look to find .torrent files. -torrents='http://repo.parabolagnulinux.org/torrents/' +shopt -s extglob torrent_folder='/srv/pacman2pacman/torrents' @@ -44,8 +42,6 @@ then exit 1 fi -torrent_url="${torrents}${url##*/}.torrent" - cd "${torrent_folder}" # Find the name of the package that will be displayed @@ -53,7 +49,36 @@ pname="${url##*/}" pname="${pname%%-[[:digit:]]*}" # Check for a .torrent. -if curl -O -f -L -s -A 'Pacman2pacman' "${torrent_url}" + +# We will cycle through the mirrors in the mirrorlist, trying to get +# the torrent file for this package. If it fails we keep trying more +# mirrors until we get a 404 or a success, because only a 404 +# indicates that the .torrent does not exist. + +while read mirror +do + # Remove the `Server = ' part, whether it has spaces or not + mirror="${mirror##Server?( )=?( )}" + + torrent_url="${mirror%%\$*}torrents/${url##*/}.torrent" + + err=$( curl -O -f -L -s -A 'Pacman2pacman' "${torrent_url}" ) + + if [[ "${?}" == 0 ]] + then + response='found_torrent' + break + + elif [[ "${err}" == *'404'* ]] + then + response='no_torrent' + break + fi +done < <(grep 'Server \?= \?' "/etc/pacman.d/mirrorlist") + +# If there's a .torrent we download the package with transmission +# otherwize we just download it by http. +if [[ "${response}" == 'found_torrent' ]] then cd "${pkg_cache_location}" # Add the torrent to transmission @@ -92,14 +117,14 @@ then # the right place. progress='0%' - echo -n "Pacman2pacman download: ${pname}: ${progress}" + echo -n "Pacman2pacman p2p download: ${pname}: ${progress}" until [[ "${progress}" == '100%' ]] do progress=$(transmission-remote -t "${id}" -i | grep 'Percent Done:') progress="${progress##* }" # Remove stuff we don't want - printf "\rPacman2pacman download: %s: %s " "${pname}" "${progress}" + printf "\rPacman2pacman p2p download: %s: %s " "${pname}" "${progress}" sleep 0.7 done @@ -118,7 +143,7 @@ else progress='0%' - echo -n "Pacman2pacman download: ${pname}: ${progress}" + echo -n "Pacman2pacman http download: ${pname}: ${progress}" # The first loop gets rid of all the backspace and `#'es and # stuff. The second loop isolates the percent done number. @@ -134,7 +159,7 @@ else # For consistency with the transmission progress bar: [[ "${progress}" == '100.0%' ]] && progress='100%' - printf "\rPacman2pacman download: %s: %s " "${pname}" "${progress}" + printf "\rPacman2pacman http download: %s: %s " "${pname}" "${progress}" done echo -- cgit v1.2.2