install 1.7 KB

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