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.

104 lines
2.1 KiB

  1. #!/bin/sh
  2. set -e
  3. . /usr/share/debconf/confmodule
  4. gendir=/usr/lib/apt-setup/generators
  5. if [ "$1" = --log-output ] && type log-output >/dev/null 2>&1; then
  6. CATCHLOG=1
  7. shift
  8. else
  9. CATCHLOG=
  10. fi
  11. export CATCHLOG
  12. if [ "$1" ]; then
  13. ROOT="$1"
  14. chroot=chroot
  15. else
  16. ROOT=
  17. chroot=
  18. fi
  19. export ROOT
  20. # generators/01setup will create this; apt honours it (see apt.conf(5))
  21. export APT_CONFIG=/etc/apt/apt.conf.new
  22. log() {
  23. logger -t apt-setup "$@"
  24. }
  25. warning() {
  26. log "warning: $@"
  27. }
  28. gencount=$(ls "$gendir"/* | wc -l)
  29. # Option to cancel progress bar disabled as there are issues with it;
  30. # see also apt-setup-verify
  31. #db_capb backup progresscancel
  32. db_capb backup
  33. db_progress START 0 $(expr $gencount \* 200) apt-setup/progress/title
  34. PROGRESS_FROM=0
  35. PROGRESS_TO=100
  36. export PROGRESS_FROM
  37. export PROGRESS_TO
  38. progress_advance() {
  39. db_progress SET $PROGRESS_TO || true
  40. PROGRESS_FROM=$PROGRESS_TO
  41. PROGRESS_TO=$(expr $PROGRESS_FROM + 100)
  42. }
  43. for generator in $gendir/*; do
  44. base=$(basename $generator | sed 's/[0-9]*//')
  45. base="${base%%.*}"
  46. if ! db_progress INFO apt-setup/progress/$base; then
  47. db_subst apt-setup/progress/fallback SCRIPT "$base"
  48. db_progress INFO apt-setup/progress/fallback || true
  49. fi
  50. tmp=$($chroot $ROOT tempfile)
  51. code=0
  52. $generator $ROOT$tmp || code=$?
  53. progress_advance
  54. case $code in
  55. 0)
  56. if ! apt-setup-verify \
  57. --from $PROGRESS_FROM --to $PROGRESS_TO \
  58. $ROOT$tmp $ROOT/etc/apt/sources.list.new; then
  59. warning "$generator output did not verify"
  60. fi
  61. ;;
  62. 9)
  63. apt-setup-verify --invalid $ROOT$tmp $ROOT/etc/apt/sources.list.new || true
  64. warning "$generator output added commented out"
  65. ;;
  66. 10)
  67. # TODO handle backup better
  68. log "$generator backed up"
  69. rm -f $ROOT$tmp $ROOT/etc/apt/sources.list.new
  70. db_progress STOP
  71. db_capb backup
  72. exit 10
  73. ;;
  74. *)
  75. warning "$generator returned error code $code; discarding output"
  76. ;;
  77. esac
  78. rm -f $ROOT$tmp
  79. progress_advance
  80. done
  81. mv $ROOT/etc/apt/sources.list.new $ROOT/etc/apt/sources.list
  82. if [ -s $ROOT/etc/apt/apt.conf.new ]; then
  83. mv $ROOT/etc/apt/apt.conf.new $ROOT/etc/apt/apt.conf
  84. else
  85. rm -f $ROOT/etc/apt/apt.conf.new
  86. fi
  87. db_progress STOP
  88. db_capb backup