apt_get_offline.sh 817 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #! /bin/bash
  2. basepath=$(cd `dirname $0`; pwd)
  3. pkg="$*"
  4. #rm -rf /var/cache/apt/archives/*
  5. function getDepends()
  6. {
  7. ret=`sudo apt-cache depends $1 |grep -i 依赖 |cut -d: -f2 |tr -d "<>"`
  8. if [[ -z $ret ]]; then
  9. # echo '$1 No depends'
  10. echo -n
  11. else
  12. for i in $ret
  13. do
  14. if [[ `echo $pkg |grep -e "$i "` ]]; then
  15. echo "$i already in set"
  16. echo -n
  17. #dpkg-query --list | grep libgtkglext1
  18. #elif [ "`sudo apt-cache search $i | grep $i`" != "" ]; then
  19. elif [ "`dpkg -l | grep $i`" != "" ]; then
  20. echo "$i already installed"
  21. else
  22. pkg="$pkg $i"
  23. echo "Download $i ing"
  24. getDepends $i
  25. fi
  26. done
  27. fi
  28. }
  29. for j in $@
  30. do
  31. getDepends $j
  32. done
  33. echo $pkg
  34. #apt install $pkg --reinstall -d -y
  35. sudo apt-get download $pkg -d -y