install 2.7 KB

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