install 2.6 KB

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