install 2.8 KB

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