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.

138 lines
2.7 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. spacer=0
  81. OLDIFS="$IFS"
  82. IFS="$NL"
  83. # Can't just iterate over $(cat $file) because that kills newlines, so
  84. # introduce a dummy colon.
  85. for line in $(sed 's/^/:/' $file); do
  86. IFS="$OLDIFS"
  87. line="${line#:}"
  88. if echo "$line" | grep -Evq "^(#.*|)[[:space:]]*$"; then
  89. items=$(expr $items + 1)
  90. # Write blank line between generators
  91. if [ $spacer = 0 ] && [ -f "$saveto" ]; then
  92. saveline ""
  93. spacer=1
  94. fi
  95. if [ "$PROGRESS" ]; then
  96. [ $items -eq 1 ] || p_from=$p_to
  97. p_to=$(expr $PROGRESS_FROM + \
  98. \( $PROGRESS_TO - $PROGRESS_FROM \) \* \
  99. $items / $tot_items)
  100. DAP_OPTS="--dlwaypoint 100 --from $p_from --to $p_to"
  101. fi
  102. if [ -z "$NOTEST" ] && valid "$line" "$DAP_OPTS"; then
  103. gooditems=$(expr $gooditems + 1)
  104. saveline "$line"
  105. else
  106. saveline "# Line commented out by installer because it failed to verify:"
  107. saveline "#$line"
  108. fi
  109. else
  110. if [ "$line" ] && [ $spacer = 0 ] && [ -f "$saveto" ]; then
  111. saveline ""
  112. spacer=1
  113. fi
  114. # Ignore leading empty lines
  115. if [ $items -ne 0 ] || [ "$line" ]; then
  116. saveline "$line"
  117. fi
  118. fi
  119. done
  120. if [ $gooditems -ne $items ]; then
  121. exit 1
  122. fi