-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathppa
More file actions
executable file
·135 lines (114 loc) · 2.61 KB
/
Copy pathppa
File metadata and controls
executable file
·135 lines (114 loc) · 2.61 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
#!/bin/sh
set -e
# Options management:
options=$(getopt -l 'refresh,check' -o 'r,c' -- "$@")
eval set -- "$options"
while true; do
case "$1" in
-r|--refresh)
refresh=1
;;
-c|--check)
check=1
;;
--)
shift
break
;;
esac
shift
done
# BEGIN: helper functions
load_keys() {
# List known signing keys:
pirogue_keys=$(
gpg --no-default-keyring --keyring "$(pwd)/$KEYRING" --export \
| gpg --show-key --with-colons --keyid-format=long \
| grep -A 1 ^pub \
| grep ^fpr \
| awk -F: '{print $10}'
)
# List local keys:
local_keys=$(
gpg --list-secret-keys --with-colons --keyid-format=long \
| grep -A 1 ^sec \
| grep ^fpr \
| awk -F: '{print $10}'
)
# Any key in the intersection is fine:
signing_key=
for pk in $pirogue_keys; do
for lk in $local_keys; do
if [ "$pk" = "$lk" ]; then
signing_key=$lk
fi
done
done
if [ -z "$signing_key" ]; then
echo "E: Found no local keys matching PiRogue keys"
echo
echo "PiRogue keys:"
for key in $pirogue_keys; do
echo " - $key"
done
echo
echo "Local keys:"
for key in $local_keys; do
echo " - $key"
done
exit 1
fi
}
do_refresh() {
load_keys
for target in $TARGETS; do
echo "I: Indexing $target"
cd "$target"
# Forget old indices:
rm -f Packages* Release*
# Better be safe than sorry, apt can be unhappy with just an uncompressed
# file:
apt-ftparchive packages . > Packages
gzip -9n -k -f Packages
# Use a temporary file to avoid (broken) self-indexing:
apt-ftparchive release . > Release.tmp
mv Release.tmp Release
gpg --local-user "$signing_key" --armor --detach-sign --output Release.gpg Release
cd ..
done
echo "I: Refreshing OK"
}
do_check() {
errors=0
for target in $TARGETS; do
echo "I: Checking $target"
cd "$target"
apt-ftparchive packages . > Packages.check
if ! cmp -s Packages Packages.check; then
echo "E: $target/Packages is outdated"
diffcmd=$(which colordiff 2>/dev/null || which diff)
$diffcmd -u Packages Packages.check || true
errors=$((errors+1))
fi
rm -f Packages.check
cd ..
done
if [ "$errors" != 0 ]; then
echo "E: $errors spotted, please refresh: $0 -r"
exit 1
else
echo "I: Checking OK"
fi
}
# END: helper functions
# Main body
#
# - Configuration/usage:
KEYRING=pirogue.gpg
TARGETS="$*"
if [ "$TARGETS" = '' ]; then
TARGETS='pirogue pirogue-3rd-party'
fi
# - Actions:
if [ "$refresh" = 1 ]; then do_refresh; fi
if [ "$check" = 1 ]; then do_check ; fi