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.

132 lines
2.6 KiB

  1. #!/bin/sh
  2. # verify and optionally save out the file
  3. set -e
  4. NL="
  5. "
  6. NOTEST=""
  7. PROGRESS=""
  8. PROGRESS_FROM=""
  9. PROGRESS_TO=""
  10. file=""
  11. while [ "$1" ]; do
  12. case "$1" in
  13. --invalid)
  14. NOTEST=1 ;;
  15. --from)
  16. shift
  17. PROGRESS_FROM=$1 ;;
  18. --to)
  19. shift
  20. PROGRESS_TO=$1 ;;
  21. *)
  22. if [ -z "$file" ]; then
  23. file="$1"
  24. else
  25. saveto="$1"
  26. fi ;;
  27. esac
  28. shift
  29. done
  30. if [ "$PROGRESS_FROM" ] && [ "$PROGRESS_TO" ] && \
  31. [ $PROGRESS_FROM -lt $PROGRESS_TO ]; then
  32. PROGRESS=1
  33. else
  34. DAP_OPTS="--no-progress"
  35. fi
  36. logoutput=""
  37. if [ "$CATCHLOG" ]; then
  38. logoutput="log-output -t apt-setup"
  39. fi
  40. chroot=
  41. intarget=
  42. if [ "$ROOT" ]; then
  43. chroot=chroot
  44. intarget=in-target
  45. fi
  46. saveline () {
  47. if [ "$saveto" ]; then
  48. echo "$*" >> $saveto
  49. fi
  50. }
  51. # Cancellation may still have reliability problems:
  52. # - application does not seem to always react to a cancel signal?
  53. # - debconf-apt-progress sometimes fails to exit with code 30 when cancelled?
  54. # See also thread http://lists.debian.org/debian-boot/2008/01/msg00094.html
  55. valid () {
  56. local line="$1"
  57. local dap_opts="$2"
  58. [ "${line%%:*}" != "deb cdrom" ] || return 0
  59. tmp=$($chroot $ROOT tempfile)
  60. echo "$line" > $ROOT$tmp
  61. code=0
  62. $logoutput $intarget debconf-apt-progress --logstderr $dap_opts -- \
  63. apt-get -o APT::Get::List-Cleanup=false \
  64. -o Dir::Etc::sourcelist=$tmp $ASV_TIMEOUT update || code=$?
  65. if [ $code -eq 30 ]; then
  66. exit 30 # canceled
  67. elif [ $code -eq 0 ]; then
  68. rm -f $ROOT$tmp
  69. else
  70. rm -f $ROOT$tmp
  71. false
  72. fi
  73. }
  74. if [ "$PROGRESS" ]; then
  75. tot_items=$(grep -Ev "^(#.*|)[[:space:]]*$" $file | wc -l)
  76. p_from=$PROGRESS_FROM
  77. fi
  78. items=0
  79. gooditems=0
  80. OLDIFS="$IFS"
  81. IFS="$NL"
  82. # Can't just iterate over $(cat $file) because that kills newlines, so
  83. # introduce a dummy colon.
  84. for line in $(sed 's/^/:/' $file); do
  85. IFS="$OLDIFS"
  86. line="${line#:}"
  87. if echo "$line" | grep -Evq "^(#.*|)[[:space:]]*$"; then
  88. items=$(expr $items + 1)
  89. # Write blank line between generators
  90. if [ $items = 1 ] && [ -f "$saveto" ]; then
  91. saveline ""
  92. fi
  93. if [ "$PROGRESS" ]; then
  94. [ $items -eq 1 ] || p_from=$p_to
  95. p_to=$(expr $PROGRESS_FROM + \
  96. \( $PROGRESS_TO - $PROGRESS_FROM \) \* \
  97. $items / $tot_items)
  98. DAP_OPTS="--dlwaypoint 100 --from $p_from --to $p_to"
  99. fi
  100. if [ -z "$NOTEST" ] && valid "$line" "$DAP_OPTS"; then
  101. gooditems=$(expr $gooditems + 1)
  102. saveline "$line"
  103. else
  104. saveline "# Line commented out by installer because it failed to verify:"
  105. saveline "#$line"
  106. fi
  107. else
  108. # Ignore leading empty lines
  109. if [ $items -ne 0 ] || [ "$line" ]; then
  110. saveline "$line"
  111. fi
  112. fi
  113. done
  114. if [ $gooditems -ne $items ]; then
  115. exit 1
  116. fi