代码: 全选
#!/bin/bash
#
# NEED wget and aria2 !!!!
#
#configure:
# CONNECTS = 1..5 for every URL (server)
CONNECTS=3
#TIMEOUT (seconds)
TIMEOUT=15
# MAX_TRIES=0 means unlimited
MAX_TRIES=5
# You can append K or M ; 0=unrestricted
SPEED=0
# FILE_ALLOC can be "prealloc" or "none"
FILE_ALLOC=none
cachedir=/var/cache/pacman/pkg
mirrorlist_file=/etc/pacman.d/mirrorlist
#configure end
getmirror(){
local mirrorlist
#output the url to download in $mirror
while read mirrorlist
do
# cut the mirrorlist's item
#echo $mirrorlist
# ignore the comment
mirrorlist="${mirrorlist%%#*}"
# select out the mirror line
if [ "${mirrorlist##*=*}" != "$mirrorlist" ]
then
mirrorlist="${mirrorlist#*=}"
while [ mirrorlist = "${mirrorlist# }" ];do mirrorlist="${mirrorlist# }";done
while [ mirrorlist = "${mirrorlist% }" ];do mirrorlist="${mirrorlist% }";done
mirror="${mirror} ${mirrorlist}/${purefilename}"
#eval echo "${mirrorlist}/${purefilename}"
fi
done
} <$mirrorlist_file
if [[ $1 = *.db.tar.gz ]]; then
wget --passive-ftp -c -O $2 $1
exit
fi
# compute the global-variable
repo=${1%/*}
repo=${repo%/*}
repo=${repo%/*}
repo=${repo##*/}
purefilename=${1##*/}
getmirror
cd "$cachedir"
echo ">>>>>> Downloading ${purefilename} <<<<<<<"
eval aria2c -d"${cachedir}" -o"${purefilename}" -s${CONNECTS} -t${TIMEOUT} --max-tries=${MAX_TRIES} --max-download-limit=${SPEED} --file-allocation=${FILE_ALLOC} --allow-overwrite=true --continue ${mirror}
if [ -f "$cachedir/$purefilename.aria2" ]
then
exit 130
fi
exit 0