Lines 5-10
Link Here
|
5 |
# Author: Karl Trygve Kalleberg <karltk@gentoo.org> |
5 |
# Author: Karl Trygve Kalleberg <karltk@gentoo.org> |
6 |
# Rewritten from the old, Perl-based emerge-webrsync script |
6 |
# Rewritten from the old, Perl-based emerge-webrsync script |
7 |
|
7 |
|
|
|
8 |
# |
9 |
# gpg key import |
10 |
# KEY_ID=0x7DDAD20D |
11 |
# gpg --homedir /etc/portage/gnupg --keyserver subkeys.pgp.net --recv-keys $KEY_ID |
12 |
# gpg --homedir /etc/portage/gnupg --edit-key $KEY_ID trust |
13 |
|
8 |
# If PORTAGE_NICENESS is overriden via the env then it will |
14 |
# If PORTAGE_NICENESS is overriden via the env then it will |
9 |
# still pass through the portageq call and override properly. |
15 |
# still pass through the portageq call and override properly. |
10 |
PORTAGE_NICENESS="$(/usr/lib/portage/bin/portageq envvar PORTAGE_NICENESS)" |
16 |
PORTAGE_NICENESS="$(/usr/lib/portage/bin/portageq envvar PORTAGE_NICENESS)" |
Lines 21-26
USERLAND="$(/usr/lib/portage/bin/portage
Link Here
|
21 |
DISTDIR="$(/usr/lib/portage/bin/portageq envvar PORTAGE_TMPDIR)/emerge-webrsync" |
27 |
DISTDIR="$(/usr/lib/portage/bin/portageq envvar PORTAGE_TMPDIR)/emerge-webrsync" |
22 |
PORTAGE_INST_UID="$(/usr/lib/portage/bin/portageq envvar PORTAGE_INST_UID)" |
28 |
PORTAGE_INST_UID="$(/usr/lib/portage/bin/portageq envvar PORTAGE_INST_UID)" |
23 |
PORTAGE_INST_GID="$(/usr/lib/portage/bin/portageq envvar PORTAGE_INST_GID)" |
29 |
PORTAGE_INST_GID="$(/usr/lib/portage/bin/portageq envvar PORTAGE_INST_GID)" |
|
|
30 |
WEBSYNC_VERIFY_SIGNATURE="$(/usr/lib/portage/bin/portageq envvar WEBSYNC_VERIFY_SIGNATURE)" |
31 |
PORTAGE_GPG_HOME="$(/usr/lib/portage/bin/portageq envvar PORTAGE_GPG_HOME)" |
32 |
|
33 |
if [ -z "$WEBSYNC_VERIFY_SIGNATURE" ]; then |
34 |
WEBSYNC_VERIFY_SIGNATURE=0 |
35 |
fi |
36 |
|
24 |
if [ ! -d $DISTDIR ] ; then |
37 |
if [ ! -d $DISTDIR ] ; then |
25 |
mkdir -p $DISTDIR |
38 |
mkdir -p $DISTDIR |
26 |
fi |
39 |
fi |
Lines 50-55
else
Link Here
|
50 |
md5_com='true' |
63 |
md5_com='true' |
51 |
fi |
64 |
fi |
52 |
|
65 |
|
|
|
66 |
if [ $WEBSYNC_VERIFY_SIGNATURE != 0 ]; then |
67 |
if type -p gpg > /dev/null; then |
68 |
gpg_com='gpg --homedir "${PORTAGE_GPG_HOME}" --verify "${FILE}.gpgsig" "${FILE}"' |
69 |
else |
70 |
echo "Cannot find gpg" |
71 |
exit 1 |
72 |
fi |
73 |
else |
74 |
gpg_com='true' |
75 |
fi |
76 |
|
77 |
if [ -f /usr/portage/metadata/timestamp.x ]; then |
78 |
portage_current_timestamp=$(cut -f 1 -d " " /usr/portage/metadata/timestamp.x) |
79 |
else |
80 |
portage_current_timestamp=0 |
81 |
fi |
82 |
|
83 |
check_snapshot_timestamp() { |
84 |
local snapshot_timestamp=$(tar --to-stdout -xf "${FILE}" portage/metadata/timestamp.x | cut -f 1 -d " ") |
85 |
|
86 |
if [ $portage_current_timestamp -lt $snapshot_timestamp ]; then |
87 |
return 0 |
88 |
else |
89 |
return 1 |
90 |
fi |
91 |
} |
92 |
|
53 |
sync_local() { |
93 |
sync_local() { |
54 |
echo Syncing local tree... |
94 |
echo Syncing local tree... |
55 |
if type -p tarsync &> /dev/null; then |
95 |
if type -p tarsync &> /dev/null; then |
Lines 57-70
sync_local() {
Link Here
|
57 |
echo "tarsync failed; tarball is corrupt?" |
97 |
echo "tarsync failed; tarball is corrupt?" |
58 |
exit 1; |
98 |
exit 1; |
59 |
fi |
99 |
fi |
60 |
rm "${FILE}" |
|
|
61 |
else |
100 |
else |
62 |
if ! tar jxf $FILE; then |
101 |
if ! tar jxf "${FILE}"; then |
63 |
echo "Tar failed to extract the image. Please review the output." |
102 |
echo "Tar failed to extract the image. Please review the output." |
64 |
echo "Executed command: tar jxf $FILE" |
103 |
echo "Executed command: tar jxf ${FILE}" |
65 |
exit 1 |
104 |
exit 1 |
66 |
fi |
105 |
fi |
67 |
rm -f $FILE |
106 |
rm -f "${FILE}" |
68 |
# Make sure user and group file ownership is ${PORTAGE_INST_UID}:${PORTAGE_INST_GID} |
107 |
# Make sure user and group file ownership is ${PORTAGE_INST_UID}:${PORTAGE_INST_GID} |
69 |
chown -R ${PORTAGE_INST_UID:-0}:${PORTAGE_INST_GID:-0} portage |
108 |
chown -R ${PORTAGE_INST_UID:-0}:${PORTAGE_INST_GID:-0} portage |
70 |
cd portage |
109 |
cd portage |
Lines 72-80
sync_local() {
Link Here
|
72 |
--exclude='/distfiles' --exclude='/packages' \ |
111 |
--exclude='/distfiles' --exclude='/packages' \ |
73 |
--exclude='/local' . ${PORTDIR%%/} |
112 |
--exclude='/local' . ${PORTDIR%%/} |
74 |
cd .. |
113 |
cd .. |
75 |
echo "cleaning up" |
|
|
76 |
rm -rf portage |
77 |
fi |
114 |
fi |
|
|
115 |
|
116 |
echo "cleaning up" |
117 |
rm -fr portage "${FILE}*" |
118 |
|
78 |
if hasq metadata-transfer ${FEATURES} ; then |
119 |
if hasq metadata-transfer ${FEATURES} ; then |
79 |
echo "transferring metadata/cache" |
120 |
echo "transferring metadata/cache" |
80 |
emerge --metadata |
121 |
emerge --metadata |
Lines 93-102
while (( $attempts < 40 )) ; do
Link Here
|
93 |
day=$(date -r $daysbefore +"%d") |
134 |
day=$(date -r $daysbefore +"%d") |
94 |
month=$(date -r $daysbefore +"%m") |
135 |
month=$(date -r $daysbefore +"%m") |
95 |
year=$(date -r $daysbefore +"%Y") |
136 |
year=$(date -r $daysbefore +"%Y") |
|
|
137 |
|
138 |
seconds=$daysbefore |
96 |
else |
139 |
else |
97 |
day=$(date -d "-$attempts day" +"%d") |
140 |
day=$(date -d "-$attempts day" +"%d") |
98 |
month=$(date -d "-$attempts day" +"%m") |
141 |
month=$(date -d "-$attempts day" +"%m") |
99 |
year=$(date -d "-$attempts day" +"%Y") |
142 |
year=$(date -d "-$attempts day" +"%Y") |
|
|
143 |
|
144 |
seconds=$(date -d "$year-$month-$day" +"%s") |
145 |
fi |
146 |
|
147 |
if [ $seconds -lt $portage_current_timestamp ]; then |
148 |
echo " --- Portage content is newer than available snapshots" |
149 |
exit 1 |
100 |
fi |
150 |
fi |
101 |
|
151 |
|
102 |
FILE_ORIG="portage-${year}${month}${day}.tar.bz2" |
152 |
FILE_ORIG="portage-${year}${month}${day}.tar.bz2" |
Lines 123-147
while (( $attempts < 40 )) ; do
Link Here
|
123 |
echo " --- No md5sum present on the mirror. (Not yet available.)" |
173 |
echo " --- No md5sum present on the mirror. (Not yet available.)" |
124 |
continue |
174 |
continue |
125 |
elif [ -s "${FILE}" ]; then |
175 |
elif [ -s "${FILE}" ]; then |
126 |
if eval "$md5_com"; then |
176 |
if eval "$md5_com" && eval "$gpg_com" && check_snapshot_timestamp; then |
127 |
echo " === snapshot $FILE is correct, using it" |
177 |
echo " === snapshot ${FILE} is correct, using it" |
128 |
sync_local |
178 |
sync_local |
129 |
echo |
179 |
echo |
130 |
echo " === Snapshot has been sync'd" |
180 |
echo " === Snapshot has been sync'd" |
131 |
echo |
181 |
echo |
132 |
exit 0 |
182 |
exit 0 |
133 |
else |
183 |
else |
134 |
rm $FILE |
184 |
rm "${FILE}" |
135 |
fi |
185 |
fi |
136 |
fi |
186 |
fi |
137 |
|
187 |
|
138 |
for i in $GENTOO_MIRRORS ; do |
188 |
for i in $GENTOO_MIRRORS ; do |
139 |
URI="${i}/snapshots/$FILE" |
189 |
URI="${i}/snapshots/${FILE}" |
140 |
rm -f "$FILE" |
190 |
rm -f "${FILE}" |
141 |
if (eval "$FETCHCOMMAND $wgetops") && [ -s "$FILE" ]; then |
191 |
if (eval "$FETCHCOMMAND $wgetops") && [ -s "${FILE}" ]; then |
|
|
192 |
URI="${i}/snapshots/${FILE}.gpgsig" |
193 |
rm -f "${FILE}.gpgsig" |
194 |
|
195 |
if [ $WEBSYNC_VERIFY_SIGNATURE != 0 ]; then |
196 |
if ! (eval "$FETCHCOMMAND $wgetops") || ! [ -s "${FILE}.gpgsig" ]; then |
197 |
echo "Cannot download signature for ${FILE}" |
198 |
continue |
199 |
fi |
200 |
fi |
201 |
|
142 |
if ! eval "$md5_com"; then |
202 |
if ! eval "$md5_com"; then |
143 |
echo "md5 failed on $FILE" |
203 |
echo "md5 failed on ${FILE}" |
144 |
rm ${FILE} |
204 |
rm "${FILE}" |
|
|
205 |
continue |
206 |
elif ! eval "$gpg_com"; then |
207 |
echo "Signature validation failed on ${FILE}" |
208 |
rm "${FILE}" |
209 |
continue |
210 |
elif ! check_snapshot_timestamp; then |
211 |
echo "Timestamp is invalid on ${FILE}" |
212 |
rm "${FILE}" |
145 |
continue |
213 |
continue |
146 |
else |
214 |
else |
147 |
sync_local |
215 |
sync_local |