Browse Source

Beginnings of a new, modular apt-setup that will run inside d-i or

(theoretically, with some more work) in Debian proper.

r29547
tags/0.1
Joey Hess 16 years ago
commit
48a5ee6da2
8 changed files with 332 additions and 0 deletions
  1. +29
    -0
      README
  2. +5
    -0
      TODO
  3. +55
    -0
      apt-setup
  4. +57
    -0
      apt-setup-verify
  5. +57
    -0
      debian/apt-setup.templates
  6. +7
    -0
      generators/01setup
  7. +77
    -0
      generators/50mirror
  8. +45
    -0
      generators/90security

+ 29
- 0
README View File

@@ -0,0 +1,29 @@
apt-setup is used to generate an /etc/apt/sources.list for the installed
system. It does this by creating a new sources.list file (commenting out
the previous contents) and then running each program in
/usr/lib/apt-setup/generators/ in turn (run-parts ordering). Each generator
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
added to the sources.list. If the verification fails, the sources will be
discarded. Gnerators 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 lins that do not work, and exits nonzero if all apt and
apt-set lines in the file failed.

Generators should add both "apt" lines and corresponding
apt-src lines to the sources.list. apt-setup-verify will handle commenting
out any apt-src lines for unavailable sources.

Generators can ask configuration questions using debconf. To support
backing up, generators should exit with the special return code of 10 if
the user backs up from their first question. Each generator should provide
a progress bar text template named apt-setup/progress/<generator>, where
<generator> is the script's name with leading digets removed.

Note that apt-setup and its generators may be run against some other system
in a chroot. (ie, 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.

+ 5
- 0
TODO View File

@@ -0,0 +1,5 @@
- move mirror generator to choose-mirror or something similar. Probably
move the non-free and contrib questions to there too.
- http proxy asking for installs from only CD w/o choose-mirror
- generator for CDs (needs to handle CD mounting stuff)
- multi-cd support

+ 55
- 0
apt-setup View File

@@ -0,0 +1,55 @@
#!/bin/sh
set -e

. /usr/share/debconf/confmodule
db_capb backup

gendir=/usr/lib/apt-setup/generators

if [ "$1" ]; then
ROOT="$1"
chroot=chroot
else
ROOT=
chroot=
fi
export ROOT

log() {
logger -t apt-setup "$@"
}
warning() {
log "warning: $@"
}

gencount=`ls "$gendir"/* | wc -l`
db_progress START 0 $gencount apt-setup/progress/title

for generator in $gendir/*; do
base=$(basename $generator | sed 's/[0-9]*//')
if ! db_progress INFO apt-setup/progress/$base; then
db_subst apt-setup/progress/fallback SCRIPT "$base"
db_progress INFO apt-setup/progress/fallback
fi
tmp=$($chroot tempfile)
echo > $tmp
if $generator $tmp; then
:
if ! apt-setup-verify $tmp $ROOT/etc/apt/sources.list; then
warning "$generator output did not verify"
fi
else
code="$?"
if [ "$code" = 10 ]; then
# TODO handle backup better
log "$generator backed up"
exit 10
fi
warning "$generator returned error code $code; discarding output"
fi
rm -f $tmp
db_progress STEP 1
done

db_progress STOP

+ 57
- 0
apt-setup-verify View File

@@ -0,0 +1,57 @@
#!/bin/sh
# verify and optionally save out the file
set -e

file="$1"
saveto="$2"

if [ -n "$ROOT" ]; then
chroot=chroot
else
chroot=
fi

valid () {
line="$1"

tmp=$($chroot tempfile)
echo "$line" > $ROOT$tmp
if $chroot $ROOT apt-get -o APT::Get::List-Cleanup=false \
-o Dir::Etc::sourcelist=$tmp update
then
rm -f $ROOT$tmp
else
rm -f $ROOT$tmp
false
fi
}

items=0
gooditems=0

IFS="
"
for line in $(cat $file); do
if [ "$(expr "$line" : "#")" != 1 ]; then
items=$(expr "$items" + 1)
if valid "$line"; then
gooditems=$(expr "$gooditems" + 1)
if [ -n "$saveto" ]; then
echo "$line" >> $saveto
fi
else
if [ -n "$saveto" ]; then
echo "#$line" >> $saveto
fi
fi
else
if [ -n "$saveto" ]; then
echo "$line" >> $saveto
fi
fi
done

if [ "$gooditems" != "$items" ]; then
exit 1
fi

+ 57
- 0
debian/apt-setup.templates View File

@@ -0,0 +1,57 @@
Template: debian-installer/apt-setup/title
Type: text
# Main menu item
_Description: Configure apt

Template: apt-setup/progress/title
Type: text
_Description: Configuring apt

Template: apt-setup/progress/fallback
Type: text
_Description: Configuring ${SCRIPT}...

Template: apt-setup/progress/setup
Type: text
_Description: Setting up...

Template: apt-setup/progress/security
Type: text
_Description: Finding security update repository...

Template: apt-setup/security_host
Type: string
Default: security.debian.org
Description: host to use for security updates (internal use)

Template: apt-setup/non-free
Type: boolean
Default: false
_Description: Use non-free software?
Some non-free software has been made to work with Debian. Though this
software is not at all a part of Debian, standard Debian tools can be used
to install it. This software has varying licenses which may prevent you
from using, modifying, or sharing it.
.
Please choose whether you want to have it available anyway.

Template: apt-setup/contrib
Type: boolean
Default: false
_Description: Use contrib software?
Some additional software has been made to work with Debian. Though this
software is free, it depends on non-free software for its operation. This
software is not a part of Debian, but standard Debian tools can be
used to install it.
.
Please choose whether you want this software to be made available to you.

Template: apt-setup/security-updates-failed
Type: error
_Description: Cannot access security updates
The security updates on ${SECURITY_HOST} couldn't be accessed, so those
updates will not be made available to you at this time. You should
investigate this later.
.
Commented out entries for ${SECURITY_HOST} have been added to the
/etc/apt/sources.list file.

+ 7
- 0
generators/01setup View File

@@ -0,0 +1,7 @@
#!/bin/sh
set -e

file="$1"

# add old file as comments
sed 's/^/# /' < $ROOT/etc/apt/sources.list | sed 's/^# # */# /' > $file

+ 77
- 0
generators/50mirror View File

@@ -0,0 +1,77 @@
#!/bin/sh
set -e

. /usr/share/debconf/confmodule

file="$1"

STATE=1
while true; do
case "$STATE" in
1)
db_input low apt-setup/non-free || true
;;
2)
# If they chose not use non-free, ask about
# contrib, with a default of no. If they chose to
# use non-free, they get contrib too..
db_get apt-setup/non-free
if [ "$RET" = false ]; then
db_fget apt-setup/contrib seen
if [ "$RET" = false ]; then
db_set apt-setup/contrib false
fi
db_input low apt-setup/contrib || true
else
db_fget apt-setup/contrib seen
if [ "$RET" = false ]; then
db_set apt-setup/contrib true
fi
fi
;;
*)
break
;;
esac

if db_go; then
STATE=$(($STATE + 1))
else
STATE=$(($STATE - 1))
fi
done
if [ $STATE -eq 1 ]; then
exit 10
fi

dists="main"
db_get apt-setup/non-free
if [ "$ret" = true ]; then
dists="$dists non-free"
fi
db_get apt-setup/contrib
if [ "$ret" = true ]; then
dists="$dists contrib"
fi

db_get mirror/suite
suite="$RET"
db_get mirror/protocol
protocol="$RET"
db_get mirror/$protocol/hostname
hostname="$RET"
db_get mirror/$protocol/directory
directory="$RET"

if [ "$protocol" = http ]; then
db_get mirror/$protocol/proxy
proxy="$RET"
if [ -n "$proxy" ]; then
if ! grep -iq "Acquire::$procotol::Proxy" $ROOT/etc/apt/apt.conf; then
echo "Acquire::$protocol::Proxy \"$proxy\";" >> $ROOT/etc/apt/apt.conf
fi
fi
fi

echo "deb $protocol://$hostname/$directory $suite $dists" >> $file
echo "deb-src $protocol://$hostname/$directory $suite $dists" >> $file

+ 45
- 0
generators/90security View File

@@ -0,0 +1,45 @@
#!/bin/sh
set -e

. /usr/share/debconf/confmodule

file="$1"

db_get apt-setup/security_host
host="$RET"
if [ -z "$host" ]; then
exit
fi

# To determine if non-free and contrib should be included, grep
# the file to see if they are listed in it.
dists="main"
for dist in contrib non-free; do
if grep -q '^[^#]*'$dist $ROOT/etc/apt/sources.list; then
dists="$dists $dist"
fi
done

# mirro/suite is also set by cdrom methods
db_get mirror/suite
suite="$RET"

# FIXME what if choose-mirror isn't avalable, ie full CD install?
db_fget mirror/http/proxy seen || true
proxy="$RET"
if [ -n "$proxy" ]; then
if ! grep -iq "Acquire::$procotol::Proxy" $ROOT/etc/apt/apt.conf; then
echo "Acquire::$protocol::Proxy \"$proxy\";" >> $ROOT/etc/apt/apt.conf
fi
fi

echo "deb http://$host/ $suite/updates $dists" >> $file
if ! apt-setup-verify; then
db_sust apt-setup/security-updates-failed SECURITY_HOST "$host"
db_input critical apt-setup/security-updates-failed || true
if ! db_go; then
exit 10 # back up
fi
fi

echo "deb-src http://$host/ $suite/updates $dists" >> $file

Loading…
Cancel
Save