diff options
author | Joseph Graham <joseph@fibreglass.tunachunks> | 2014-06-06 11:13:40 +0100 |
---|---|---|
committer | Joseph Graham <joseph@fibreglass.tunachunks> | 2014-06-06 11:28:40 +0100 |
commit | 66e80f3278ac50a15fd37f5e86693a3b93bb4936 (patch) | |
tree | e235d1df0060b01f73678ed929a941d452d75b42 /pacman2pacman-get | |
parent | f79454f71022b6af2f4c2daae4bd334d8756c35b (diff) |
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.
Diffstat (limited to 'pacman2pacman-get')
-rw-r--r-- | pacman2pacman-get | 90 |
1 files 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 <joseph@t67.eu> # @@ -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 |