granada

pacget

Mar 6th, 2012
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. msg() {
  4.   echo ""
  5.   echo -e "   \033[1;34m->\033[1;0m \033[1;1m${1}\033[1;0m" >&2
  6. }
  7.  
  8. error() {
  9.   echo -e "\033[1;31m==> ERROR:\033[1;0m \033[1;1m$1\033[1;0m" >&2
  10. }
  11.  
  12. CONF=/etc/pacget.conf
  13. STATS=/etc/pacget.stats
  14. ARIA2=$(which aria2c 2> /dev/null)
  15.  
  16. # ----- do some checks first -----
  17. if [ ! -x "$ARIA2" ]; then
  18.   error "aria2c was not found or isn't executable."
  19.   exit 1
  20. fi
  21.  
  22. if [ $# -ne 2 ]; then
  23.   error "Incorrect number of arguments"
  24.   exit 1
  25. fi
  26.  
  27. filename=$(basename $1)
  28. server=${1%/$filename}
  29. arch=$(grep ^Architecture /etc/pacman.conf | cut -d '=' -f2 | sed 's/ //g')
  30. if [[ $arch = "auto" ]]; then
  31.   arch=$(uname -m)
  32. fi
  33. # Determine which repo is being used
  34. repo=$(awk -F'/' '$(NF-2)~/^(community|core|extra|testing|comunity-testing|multilib)$/{print $(NF-2)}' <<< $server)
  35. [ -z $repo ] && repo="custom"
  36.  
  37. # For db files, or when using a custom repo (which most likely doesn't have any mirror),
  38. # use only the URL passed by pacman; Otherwise, extract the list of servers (from the include file of the repo) to download from
  39. url=$1
  40. if ! [[ $filename = *.db || $repo = "custom" ]]; then
  41.  mirrorlist=$(awk -F' *= *' '$0~"^\\["r"\\]",/Include *= */{l=$2} END{print l}' r=$repo /etc/pacman.conf)
  42.  if [ -n mirrorlist ]; then
  43.    num_conn=$(grep ^split $CONF | cut -d'=' -f2)
  44.    url=$(sed -r '/^Server *= */!d; s/Server *= *//; s/\$repo'"/$repo/"'; s/\$arch'"/$arch/; s/$/\/$filename/" $mirrorlist | head -n $(($num_conn *2)) )
  45.  fi
  46. fi
  47.  
  48. msg "Downloading $filename"
  49. cd /var/cache/pacman/pkg/
  50.  
  51. touch $STATS
  52.  
  53. $ARIA2 --conf-path=$CONF --max-tries=1 --max-file-not-found=5 \
  54.  --uri-selector=adaptive --server-stat-if=$STATS --server-stat-of=$STATS \
  55.  --allow-overwrite=true --remote-time=true --log-level=error --summary-interval=0 \
  56.  $url --out=${filename}.pacget && [ ! -f ${filename}.pacget.aria2 ] && mv ${filename}.pacget $2 && chmod 644 $2
  57.  
  58. exit $?
Add Comment
Please, Sign In to add comment