You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

111 lines
2.7 KiB

  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 [ "$WAIT" = "true" ]; 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 [ "$CHECKDIR" = "true" ]; then
  66. if [ "$OLDLS" = "$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. echo -n $"Do you want to erase any previously downloaded .deb files?"
  83. if [ $(yesno "" y) = y ]; then
  84. $APTGET "$APT_OPT0" "$APT_OPT1" clean &&
  85. echo $"Press enter to continue." && read RES && exit 0;
  86. fi
  87. ;;
  88. *)
  89. ;;
  90. esac
  91. else
  92. echo $"Some errors occurred while unpacking. Packages that were installed"
  93. echo $"will be configured. This may result in duplicate errors"
  94. echo $"or errors caused by missing dependencies. This is OK, only the errors"
  95. echo $"above this message are important. Please fix them and run [I]nstall again"
  96. echo $"Press enter to continue."
  97. read RES && $DPKG "$DPKG_OPTS" --configure -a
  98. exit 100
  99. fi
  100. exit $?