install 2.1 KB

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