#!/bin/sh
### Common function to wget files with debconf error handling.

# $1 error severity
# $2 is url to file
# $3 is dest file
wgetfile() {
  if ! wget -q -O "$3" "$2" 2>/dev/null; then
    case "$1" in
      fatal)
        db_subst system-integrity-check/wget-error HOST "$host"
        db_subst system-integrity-check/wget-error SUBST0 "$2"
        db_input critical system-integrity-check/wget-error
        db_go || true
        exit 1
      ;;
      warn)
        db_subst system-integrity-check/report/wget-error SUBST0 "$2"
        db_metaget system-integrity-check/report/wget-error description || RET=''
        if [ -z "$RET" ]; then
          echo "Unable to fetch debconf translation: using plain english." >> "$report"
          echo "Unable to fetch $2" >> "$report"
        else
          echo "$RET" >> "$report"
        fi
      ;;
    esac
  fi
}
