-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapt-setup-verify
More file actions
executable file
·137 lines (122 loc) · 2.67 KB
/
apt-setup-verify
File metadata and controls
executable file
·137 lines (122 loc) · 2.67 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/sh
# verify and optionally save out the file
set -e
NL="
"
NOTEST=""
PROGRESS=""
PROGRESS_FROM=""
PROGRESS_TO=""
file=""
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
done
if [ "$PROGRESS_FROM" ] && [ "$PROGRESS_TO" ] && \
[ $PROGRESS_FROM -lt $PROGRESS_TO ]; then
PROGRESS=1
else
DAP_OPTS="--no-progress"
fi
logoutput=""
if [ "$CATCHLOG" ]; then
logoutput="log-output -t apt-setup"
fi
chroot=
intarget=
if [ "$ROOT" ]; then
chroot=chroot
intarget=in-target
fi
saveline () {
if [ "$saveto" ]; then
echo "$*" >> $saveto
fi
}
# Cancellation may still have reliability problems:
# - application does not seem to always react to a cancel signal?
# - debconf-apt-progress sometimes fails to exit with code 30 when cancelled?
# See also thread http://lists.debian.org/debian-boot/2008/01/msg00094.html
valid () {
local line="$1"
local dap_opts="$2"
[ "${line%%:*}" != "deb cdrom" ] || return 0
tmp=$($chroot $ROOT mktemp)
echo "$line" > $ROOT$tmp
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
false
fi
}
if [ "$PROGRESS" ]; then
tot_items=$(grep -Ev "^(#.*|)[[:space:]]*$" $file | wc -l)
p_from=$PROGRESS_FROM
fi
items=0
gooditems=0
spacer=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 echo "$line" | grep -Evq "^(#.*|)[[:space:]]*$"; then
items=$(expr $items + 1)
# Write blank line between generators
if [ $spacer = 0 ] && [ -f "$saveto" ]; then
saveline ""
spacer=1
fi
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:"
saveline "#$line"
fi
else
if [ "$line" ] && [ $spacer = 0 ] && [ -f "$saveto" ]; then
saveline ""
spacer=1
fi
# Ignore leading empty lines
if [ $items -ne 0 ] || [ "$line" ]; then
saveline "$line"
fi
fi
done
if [ $gooditems -ne $items ]; then
exit 1
fi