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.

58 lines
834 B

#!/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