File: apt-setup-verify

package info (click to toggle)
apt-setup 1%3A0.20etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 956 kB
  • ctags: 8
  • sloc: sh: 479; makefile: 26
file content (83 lines) | stat: -rwxr-xr-x 1,425 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
# verify and optionally save out the file
set -e

NL="
"

NOTEST=""
if [ "$1" = "--invalid" ]; then
	NOTEST=1
	shift
fi

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

logoutput=""
if [ "$CATCHLOG" ]; then
	logoutput="log-output -t apt-setup"
fi

chroot=
if [ "$ROOT" ]; then
	chroot=chroot
fi

saveline () {
	if [ "$saveto" ]; then
		echo "$*" >> $saveto
	fi
}

valid () {
	line="$1"

	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
		rm -f $ROOT$tmp
	else
		rm -f $ROOT$tmp
		false
	fi
}

items=0
gooditems=0

OLDIFS="$IFS"
IFS="$NL"
# Can't just iterate over $(cat $file) because that kills newlines, so
# introduce a dummy colon.
for line in $(sed 's/^/:/' $file); do
	IFS="$OLDIFS"
	line="${line#:}"
	if expr "$line" : '.*[^ ].*' >/dev/null && [ "$(expr "$line" : "#")" != 1 ]; 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)
			saveline "$line"
		else
			saveline "# Line commented out by installer because it failed to verify:"
			saveline "#$line"
		fi
	else
		# Ignore leading empty lines
		if [ $items != 0 ] || [ "$line" ]; then
			saveline "$line"
		fi
	fi
done

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