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.

101 lines
2.0 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. db_capb backup progresscancel
  30. db_progress START 0 $(expr $gencount \* 200) apt-setup/progress/title
  31. PROGRESS_FROM=0
  32. PROGRESS_TO=100
  33. export PROGRESS_FROM
  34. export PROGRESS_TO
  35. progress_advance() {
  36. db_progress SET $PROGRESS_TO || true
  37. PROGRESS_FROM=$PROGRESS_TO
  38. PROGRESS_TO=$(expr $PROGRESS_FROM + 100)
  39. }
  40. for generator in $gendir/*; do
  41. base=$(basename $generator | sed 's/[0-9]*//')
  42. base="${base%%.*}"
  43. if ! db_progress INFO apt-setup/progress/$base; then
  44. db_subst apt-setup/progress/fallback SCRIPT "$base"
  45. db_progress INFO apt-setup/progress/fallback || true
  46. fi
  47. tmp=$($chroot $ROOT tempfile)
  48. code=0
  49. $generator $ROOT$tmp || code=$?
  50. progress_advance
  51. case $code in
  52. 0)
  53. if ! apt-setup-verify \
  54. --from $PROGRESS_FROM --to $PROGRESS_TO \
  55. $ROOT$tmp $ROOT/etc/apt/sources.list.new; then
  56. warning "$generator output did not verify"
  57. fi
  58. ;;
  59. 9)
  60. apt-setup-verify --invalid $ROOT$tmp $ROOT/etc/apt/sources.list.new || true
  61. warning "$generator output added commented out"
  62. ;;
  63. 10)
  64. # TODO handle backup better
  65. log "$generator backed up"
  66. rm -f $ROOT$tmp $ROOT/etc/apt/sources.list.new
  67. db_progress STOP
  68. db_capb backup
  69. exit 10
  70. ;;
  71. *)
  72. warning "$generator returned error code $code; discarding output"
  73. ;;
  74. esac
  75. rm -f $ROOT$tmp
  76. progress_advance
  77. done
  78. mv $ROOT/etc/apt/sources.list.new $ROOT/etc/apt/sources.list
  79. if [ -s $ROOT/etc/apt/apt.conf.new ]; then
  80. mv $ROOT/etc/apt/apt.conf.new $ROOT/etc/apt/apt.conf
  81. else
  82. rm -f $ROOT/etc/apt/apt.conf.new
  83. fi
  84. db_progress STOP
  85. db_capb backup