install 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. OLDLS=`ls -ld $ARCHIVES`
  40. if [ x$WAIT = "xyes" ]; then
  41. $APTGET $OPTS -d dselect-upgrade
  42. echo "Press enter to continue." && read RES
  43. $APTGET $OPTS dselect-upgrade
  44. RES=$?
  45. else
  46. $APTGET $OPTS dselect-upgrade
  47. RES=$?
  48. fi
  49. # 1 means the user choose no at the prompt
  50. if [ $RES -eq 1 ]; then
  51. exit 0
  52. fi
  53. # Finished OK
  54. if [ $RES -eq 0 ]; then
  55. if [ `ls $ARCHIVES $ARCHIVES/partial | egrep -v "^lock$|^partial$" | wc -l` \
  56. -eq 0 ]; then
  57. exit 0
  58. fi
  59. NEWLS=`ls -ld $ARCHIVES`
  60. if [ "x$OLDLS" == "x$NEWLS" ]; then
  61. exit 0
  62. fi
  63. # Check the cleaning mode
  64. case `echo $CLEAN | tr '[:upper:]' '[:lower:]'` in
  65. auto)
  66. $APTGET autoclean && echo "Press enter to continue." && read RES && exit 0;
  67. ;;
  68. always)
  69. $APTGET clean && echo "Press enter to continue." && read RES && exit 0;
  70. ;;
  71. prompt)
  72. exec 3>&1
  73. if [ `yesno "Do you want to erase the downloaded .deb files?" y` = y ]; then
  74. $APTGET clean && echo "Press enter to continue." && read RES && exit 0;
  75. fi
  76. ;;
  77. *)
  78. ;;
  79. esac
  80. else
  81. echo "Some errors occurred while unpacking. I'm going to configure the"
  82. echo "packages that were installed. This may result in duplicate errors"
  83. echo "or errors caused by missing dependencies. This is OK, only the errors"
  84. echo "above this message are important. Please fix them and run [I]nstall again"
  85. echo "Press enter to continue."
  86. read RES && $DPKG --configure -a
  87. exit 100
  88. fi
  89. exit $?