From 66e80f3278ac50a15fd37f5e86693a3b93bb4936 Mon Sep 17 00:00:00 2001 From: Joseph Graham Date: Fri, 6 Jun 2014 11:13:40 +0100 Subject: tried to fix bug of it failing to move torrents. Made it not check for .torrents for .db files. Made it check the last modified date on .db files. --- pacman2pacman-get | 90 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 22 deletions(-) diff --git a/pacman2pacman-get b/pacman2pacman-get index 6cf2aa6..c020a6a 100644 --- a/pacman2pacman-get +++ b/pacman2pacman-get @@ -1,7 +1,7 @@ #! /bin/bash # /usr/bin/pacman2pacman-get # -# Version 1.3.0 +# Version 1.4.0 # # Copyright (C) 2014 Joseph Graham # @@ -48,6 +48,14 @@ cd "${torrent_folder}" pname="${url##*/}" pname="${pname%%-[[:digit:]]*}" +# Find out if it's a dbfile +if [[ "${url}" == *'.db' ]] || [[ "${url}" == *'.db.sig' ]] +then + dbfile=1 +else + dbfile=0 +fi + # Check for a .torrent. # We will cycle through the mirrors in the mirrorlist, trying to get @@ -55,26 +63,33 @@ pname="${pname%%-[[:digit:]]*}" # 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 +# If it's a .db file then we don't even check for a .torrent +if (( dbfile )) +then + response='no_torrent' - elif [[ "${err}" == *'404'* ]] - then - response='no_torrent' - break - fi -done < <(grep 'Server \?= \?' "/etc/pacman.d/mirrorlist") +else + 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") +fi # If there's a .torrent we download the package with transmission # otherwize we just download it by http. @@ -131,7 +146,19 @@ then echo - mv -f "${pkg_cache_location}/${url##*/}" "${filename}" || exit 1 + err_count=0 + until mv -f "${pkg_cache_location}/${url##*/}" "${filename}" 2>/dev/null + do + if (( err_count > 50 )) + then + echo "error moving \"${pkg_cache_location}/${url##*/}\"" + exit 1 + fi + + sleep 0.1 + + (( ++ err_count )) + done else cd "${pkg_cache_location}" @@ -147,7 +174,20 @@ else # The first loop gets rid of all the backspace and `#'es and # stuff. The second loop isolates the percent done number. - curl -# -f -L -o "${filename}" -A 'Pacman2pacman' "${url}" 2>&1 | + { + # For dbs we check if they are modified + if (( dbfile )) + then + if [[ -f "/srv/pacman2pacman/dbcache/${filename##*/}" ]] + then + curl -# -f -L -z "/srv/pacman2pacman/dbcache/${filename##*/}" -o "/srv/pacman2pacman/dbcache/${filename##*/}" -A 'Pacman2pacman' "${url}" 2>&1 + else + curl -# -f -L -o "/srv/pacman2pacman/dbcache/${filename##*/}" -A 'Pacman2pacman' "${url}" 2>&1 + fi + else + curl -# -f -L -o "${filename}" -A 'Pacman2pacman' "${url}" 2>&1 + fi + } | while read -N 1 char do [[ "${char}" =~ [[:digit:].%\ ] ]] && echo -n "${char}" @@ -164,7 +204,13 @@ else echo + if (( dbfile )) && [[ -f "/srv/pacman2pacman/dbcache/${filename##*/}" ]] + then + cp "/srv/pacman2pacman/dbcache/${filename##*/}" "${filename}" 2>/dev/null + fi + [[ -f "${filename}" ]] || exit 1 + fi exit -- cgit v1.2.3