install 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/sh
  2. # Get the configuration from /etc/apt/apt.conf
  3. CLEAN="prompt"
  4. OPTS="-f"
  5. APTGET="/usr/bin/apt-get"
  6. DPKG="/usr/bin/dpkg"
  7. set -e
  8. RES=`apt-config shell CLEAN DSelect::Clean OPTS DSelect::Options \
  9. DPKG Dir::Bin::dpkg APTGET Dir::Bin::apt-get \
  10. ARCHIVES Dir::Cache::Archives/`
  11. eval $RES
  12. set +e
  13. # Yes/No Prompter
  14. yesno() {
  15. # $1 = prompt
  16. # $2 = default(y)
  17. local ans def defp
  18. if [ "$2" ];then
  19. case $2 in
  20. Y|y) defp="(Y/n)" def=y;;
  21. N|n) defp="(y/N)" def=n;;
  22. *) echo "Bad default setting!" 1>&2; exit 1;;
  23. esac
  24. else
  25. defp="(y/N)" def=n
  26. fi
  27. while :;do
  28. echo -n "$1$defp" 1>&3
  29. read ans
  30. case $ans in
  31. Y|y|N|n) break;;
  32. "") ans=$def;break;;
  33. esac
  34. echo
  35. done
  36. echo $ans | tr YN yn
  37. }
  38. $APTGET $OPTS dselect-upgrade
  39. RES=$?
  40. # 1 means the user choose no at the prompt
  41. if [ $RES -eq 1 ]; then
  42. exit 0
  43. fi
  44. # Finished OK
  45. if [ $RES -eq 0 ]; then
  46. if [ `ls $ARCHIVES $ARCHIVES/partial | egrep -v "^lock$|^partial$" | wc -l` \
  47. -eq 0 ]; then
  48. exit 0
  49. fi
  50. # Check the cleaning mode
  51. case `echo $CLEAN | tr '[:upper:]' '[:lower:]'` in
  52. auto)
  53. $APTGET autoclean && echo "Press enter to continue." && read RES && exit 0;
  54. ;;
  55. always)
  56. $APTGET clean && echo "Press enter to continue." && read RES && exit 0;
  57. ;;
  58. prompt)
  59. exec 3>&1
  60. if [ `yesno "Do you want to erase the downloaded .deb files " y` = y ]; then
  61. $APTGET clean && echo "Press enter to continue." && read RES && exit 0;
  62. fi
  63. ;;
  64. *)
  65. ;;
  66. esac
  67. else
  68. echo "Some errors occurred while unpacking. I'm going to configure the"
  69. echo "packages that were installed. This may result in duplicate errors"
  70. echo "or errors caused by missing dependencies. This is OK, only the errors"
  71. echo "above this message are important. Please fix them and run [I]nstall again"
  72. echo "Press enter to continue."
  73. read RES && $DPKG --configure -a
  74. exit 100
  75. fi
  76. exit $?