Commit 6e5acb6d authored by Frans Pop's avatar Frans Pop

Add back progress/cancelation changes

r50785
parent feb25b42
......@@ -6,11 +6,12 @@ is passed the name of a temporary file that it can write sources.list lines
(and comments) to.
After the generator finishes writing the file, apt-setup-verify will be run
on it to verify that each line of the sources sources works, and it will be
on it to verify that each line of the sources works, and it will be
added to the sources.list. Generators can also run apt-setup-verify
themselves and do their own error recovery if it fails. apt-setup-verify
tests each line of the file and comments out lines that do not work, and
exits nonzero if all deb and deb-src lines in the file failed.
exits zero if all deb and deb-src lines in the file are ok, 30 if the
verification process was canceled, and otherwise nonzero on error.
Generators should add both "deb" lines and corresponding
deb-src lines to the sources.list. apt-setup-verify will handle commenting
......@@ -25,8 +26,21 @@ after the first dot (if any) will also be removed when constructing the
progress template name, so that different scripts that share the same
purpose can easily be written.
Generators can advance the progress bar from PROGRESS_FROM up to
PROGRESS_TO, or it will be moved to the next step before the next
generator is started.
apt-setup-verify runs apt-get update inside debconf-apt-progress, to update
the progress bar with apt progress information. By default the progress bar
will not be moved. Use --from and --to options to override this. The values
of these options will be used as start and end points for the progress bar;
each source line to be tested will get an equal share. The resulting values
are passed on to debconf-apt-progress.
For example:
apt-setup-verify --from 1 --to 100 <file>
Note that apt-setup and its generators may be run against some other system
in a chroot. (i.e., when installing Debian.) If apt-setup is running this
in a chroot (i.e., when installing Debian). If apt-setup is running this
way, then ROOT will be set to the root of the chroot that it is acting on
and all sources.list validation will occur inside the chroot.
......
......@@ -2,7 +2,6 @@
set -e
. /usr/share/debconf/confmodule
db_capb backup
gendir=/usr/lib/apt-setup/generators
......@@ -33,24 +32,40 @@ warning() {
log "warning: $@"
}
gencount=`ls "$gendir"/* | wc -l`
db_progress START 0 $gencount apt-setup/progress/title
gencount=$(ls "$gendir"/* | wc -l)
db_capb backup progresscancel
db_progress START 0 $(expr $gencount \* 200) apt-setup/progress/title
PROGRESS_FROM=0
PROGRESS_TO=100
export PROGRESS_FROM
export PROGRESS_TO
progress_advance() {
db_progress SET $PROGRESS_TO || true
PROGRESS_FROM=$PROGRESS_TO
PROGRESS_TO=$(expr $PROGRESS_FROM + 100)
}
for generator in $gendir/*; do
base=$(basename $generator | sed 's/[0-9]*//')
base="${base%%.*}"
if ! db_progress INFO apt-setup/progress/$base; then
db_subst apt-setup/progress/fallback SCRIPT "$base"
db_progress INFO apt-setup/progress/fallback
db_progress INFO apt-setup/progress/fallback || true
fi
tmp=$($chroot $ROOT tempfile)
code=0
$generator $ROOT$tmp || code=$?
progress_advance
case $code in
0)
if ! apt-setup-verify $ROOT$tmp $ROOT/etc/apt/sources.list.new; then
if ! apt-setup-verify \
--from $PROGRESS_FROM --to $PROGRESS_TO \
$ROOT$tmp $ROOT/etc/apt/sources.list.new; then
warning "$generator output did not verify"
fi
;;
......@@ -63,6 +78,7 @@ for generator in $gendir/*; do
log "$generator backed up"
rm -f $ROOT$tmp $ROOT/etc/apt/sources.list.new
db_progress STOP
db_capb backup
exit 10
;;
*)
......@@ -70,7 +86,8 @@ for generator in $gendir/*; do
;;
esac
rm -f $ROOT$tmp
db_progress STEP 1
progress_advance
done
mv $ROOT/etc/apt/sources.list.new $ROOT/etc/apt/sources.list
if [ -s $ROOT/etc/apt/apt.conf.new ]; then
......@@ -80,3 +97,4 @@ else
fi
db_progress STOP
db_capb backup
......@@ -6,13 +6,35 @@ NL="
"
NOTEST=""
if [ "$1" = "--invalid" ]; then
NOTEST=1
PROGRESS=""
PROGRESS_FROM=""
PROGRESS_TO=""
while [ "$1" ]; do
case "$1" in
--invalid)
NOTEST=1 ;;
--from)
shift
PROGRESS_FROM=$1 ;;
--to)
shift
PROGRESS_TO=$1 ;;
*)
if [ -z "$file" ]; then
file="$1"
else
saveto="$1"
fi ;;
esac
shift
fi
done
file="$1"
saveto="$2"
if [ "$PROGRESS_FROM" ] && [ "$PROGRESS_TO" ] && \
[ $PROGRESS_FROM -lt $PROGRESS_TO ]; then
PROGRESS=1
else
DAP_OPTS="--no-progress"
fi
logoutput=""
if [ "$CATCHLOG" ]; then
......@@ -20,8 +42,10 @@ if [ "$CATCHLOG" ]; then
fi
chroot=
intarget=
if [ "$ROOT" ]; then
chroot=chroot
intarget=in-target
fi
saveline () {
......@@ -31,16 +55,20 @@ saveline () {
}
valid () {
line="$1"
local line="$1"
local dap_opts="$2"
[ "${line%%:*}" != "deb cdrom" ] || return 0
tmp=$($chroot $ROOT tempfile)
echo "$line" > $ROOT$tmp
if $logoutput $chroot $ROOT apt-get -o APT::Get::List-Cleanup=false \
-o Dir::Etc::sourcelist=$tmp $ASV_TIMEOUT update
then
code=0
$logoutput $intarget debconf-apt-progress --logstderr $dap_opts -- \
apt-get -o APT::Get::List-Cleanup=false \
-o Dir::Etc::sourcelist=$tmp $ASV_TIMEOUT update || code=$?
if [ $code -eq 30 ]; then
exit 30 # canceled
elif [ $code -eq 0 ]; then
rm -f $ROOT$tmp
else
rm -f $ROOT$tmp
......@@ -48,6 +76,11 @@ valid () {
fi
}
if [ "$PROGRESS" ]; then
tot_items=$(grep -Ev "^(#.*|)[[:space:]]*$" $file | wc -l)
p_from=$PROGRESS_FROM
fi
items=0
gooditems=0
......@@ -58,15 +91,23 @@ IFS="$NL"
for line in $(sed 's/^/:/' $file); do
IFS="$OLDIFS"
line="${line#:}"
if expr "$line" : '.*[^ ].*' >/dev/null && [ "$(expr "$line" : "#")" != 1 ]; then
items=$(expr "$items" + 1)
if echo "$line" | grep -Evq "^(#.*|)[[:space:]]*$"; then
items=$(expr $items + 1)
# Write blank line between generators
if [ $items = 1 ] && [ -f "$saveto" ]; then
saveline ""
fi
if [ -z "$NOTEST" ] && valid "$line"; then
gooditems=$(expr "$gooditems" + 1)
if [ "$PROGRESS" ]; then
[ $items -eq 1 ] || p_from=$p_to
p_to=$(expr $PROGRESS_FROM + \
\( $PROGRESS_TO - $PROGRESS_FROM \) \* \
$items / $tot_items)
DAP_OPTS="--dlwaypoint 100 --from $p_from --to $p_to"
fi
if [ -z "$NOTEST" ] && valid "$line" "$DAP_OPTS"; then
gooditems=$(expr $gooditems + 1)
saveline "$line"
else
saveline "# Line commented out by installer because it failed to verify:"
......@@ -74,12 +115,12 @@ for line in $(sed 's/^/:/' $file); do
fi
else
# Ignore leading empty lines
if [ $items != 0 ] || [ "$line" ]; then
if [ $items -ne 0 ] || [ "$line" ]; then
saveline "$line"
fi
fi
done
if [ "$gooditems" != "$items" ]; then
if [ $gooditems -ne $items ]; then
exit 1
fi
apt-setup (1:0.33) UNRELEASED; urgency=low
[ Joey Hess ]
* Put apt downloading info in the progress bar.
* Allocate 100 steps on the progress bar for each generator,
and 100 steps for verifying each generated block.
* Export PROGRESS_FROM and PROGRESS_TO to generators, giving the
starting and ending progress bar position for that generator. This can
be used by generators that need an absolute progress bar position for
calling debconf-apt-progress.
* apt-setup-verify: Use debconf-apt-progress and add a way for generators
to specify how it should advance the progress bar.
* Allow the progress bar to be canceled.
* 50mirror: Call choose-mirror -n to avoid trashing the progress bar.
* Needs debconf 1.5.17.
-- Frans Pop <fjp@debian.org> Sun, 06 Jan 2008 22:47:56 +0100
apt-setup (1:0.32) unstable; urgency=low
[ Frans Pop ]
......
......@@ -184,7 +184,7 @@ while [ ! "$done" ]; do
echo "deb $protocol://$hostname$directory $codename $dists" > $file
if apt-setup-verify $file; then
if apt-setup-verify --from $PROGRESS_FROM --to $PROGRESS_TO $file; then
done=1
else
db_set apt-setup/mirror/error Retry
......@@ -192,7 +192,7 @@ while [ ! "$done" ]; do
db_go || exit 10
db_get apt-setup/mirror/error
if [ "$RET" = "Change mirror" ]; then
choose-mirror || true
choose-mirror -n || true
elif [ "$RET" = Ignore ]; then
exit 1
fi
......
......@@ -36,7 +36,7 @@ if db_get netcfg/dhcp_options && \
else
CODE=0
export ASV_TIMEOUT="-o Acquire::http::Timeout=30"
if ! apt-setup-verify $file; then
if ! apt-setup-verify --from $PROGRESS_FROM --to $PROGRESS_TO $file; then
db_subst apt-setup/service-failed HOST "$host"
db_input critical apt-setup/service-failed || true
if ! db_go; then
......
......@@ -42,7 +42,7 @@ if db_get netcfg/dhcp_options && \
else
CODE=0
export ASV_TIMEOUT="-o Acquire::http::Timeout=30"
if ! apt-setup-verify $file; then
if ! apt-setup-verify --from $PROGRESS_FROM --to $PROGRESS_TO $file; then
db_subst apt-setup/service-failed HOST "$host"
db_input critical apt-setup/service-failed || true
if ! db_go; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment