1 |
Author: vapier |
2 |
Date: 2008-02-23 01:17:15 +0000 (Sat, 23 Feb 2008) |
3 |
New Revision: 9371 |
4 |
|
5 |
Modified: |
6 |
main/trunk/bin/emerge-webrsync |
7 |
Log: |
8 |
add support for lzma/gz snapshots |
9 |
|
10 |
Modified: main/trunk/bin/emerge-webrsync |
11 |
=================================================================== |
12 |
--- main/trunk/bin/emerge-webrsync 2008-02-23 01:08:54 UTC (rev 9370) |
13 |
+++ main/trunk/bin/emerge-webrsync 2008-02-23 01:17:15 UTC (rev 9371) |
14 |
@@ -7,6 +7,10 @@ |
15 |
# Author: Alon Bar-Lev <alon.barlev@×××××.com> |
16 |
# Major rewrite from Karl's scripts. |
17 |
|
18 |
+# TODO: |
19 |
+# - all output should prob be converted to e* funcs |
20 |
+# - add support for ROOT |
21 |
+ |
22 |
# |
23 |
# gpg key import |
24 |
# KEY_ID=0x7DDAD20D |
25 |
@@ -14,8 +18,6 @@ |
26 |
# gpg --homedir /etc/portage/gnupg --edit-key $KEY_ID trust |
27 |
# |
28 |
|
29 |
-# XXX: all output should prob be converted to e* funcs ... |
30 |
- |
31 |
# Only echo if in verbose mode |
32 |
vvecho() { [[ ${do_verbose} -eq 1 ]] && echo "$@" ; } |
33 |
# Only echo if not in verbose mode |
34 |
@@ -58,6 +60,20 @@ |
35 |
exit 1 |
36 |
fi |
37 |
|
38 |
+do_tar() { |
39 |
+ local file=$1; shift |
40 |
+ local decompressor |
41 |
+ case ${file} in |
42 |
+ *.lzma) decompressor="lzcat" ;; |
43 |
+ *.bz2) decompressor="bzcat" ;; |
44 |
+ *.gz) decompressor="zcat" ;; |
45 |
+ *) decompressor="cat" ;; |
46 |
+ esac |
47 |
+ ${decompressor} "${file}" | tar "$@" |
48 |
+ _pipestatus=${PIPESTATUS[*]} |
49 |
+ [[ ${_pipestatus// /} -eq 0 ]] |
50 |
+} |
51 |
+ |
52 |
get_utc_date_in_seconds() { |
53 |
date -u +"%s" |
54 |
} |
55 |
@@ -101,7 +117,7 @@ |
56 |
rm -f "${FILE}" |
57 |
fi |
58 |
|
59 |
- vecho "Fetching file ${FILE}..." |
60 |
+ vecho "Fetching file ${FILE} ..." |
61 |
# already set DISTDIR= |
62 |
eval "${FETCHCOMMAND}" ${opts} |
63 |
[ -s "${FILE}" ] |
64 |
@@ -112,7 +128,7 @@ |
65 |
local file="$2" |
66 |
local r=1 |
67 |
|
68 |
- vecho "Checking digest..." |
69 |
+ vecho "Checking digest ..." |
70 |
|
71 |
if type -P md5sum > /dev/null; then |
72 |
md5sum -c $digest && r=0 |
73 |
@@ -132,7 +148,7 @@ |
74 |
|
75 |
if [ ${WEBSYNC_VERIFY_SIGNATURE} != 0 ]; then |
76 |
|
77 |
- vecho "Checking signature..." |
78 |
+ vecho "Checking signature ..." |
79 |
|
80 |
if type -p gpg > /dev/null; then |
81 |
gpg --homedir "${PORTAGE_GPG_DIR}" --verify "$signature" "$file" && r=0 |
82 |
@@ -149,24 +165,21 @@ |
83 |
get_snapshot_timestamp() { |
84 |
local file="$1" |
85 |
|
86 |
- tar --to-stdout -xf "${file}" portage/metadata/timestamp.x | cut -f 1 -d " " |
87 |
+ do_tar "${file}" --to-stdout -xf - portage/metadata/timestamp.x | cut -f 1 -d " " |
88 |
} |
89 |
|
90 |
sync_local() { |
91 |
local file="$1" |
92 |
|
93 |
- vecho "Syncing local tree..." |
94 |
+ vecho "Syncing local tree ..." |
95 |
|
96 |
if type -P tarsync &> /dev/null; then |
97 |
- if [ "${do_verbose}" != 0 ] ; then |
98 |
- tarsync_verbose=-v |
99 |
- fi |
100 |
- if ! tarsync $tarsync_verbose -s 1 -o portage -g portage -e /distfiles -e /packages -e /local "${file}" "${PORTDIR}"; then |
101 |
+ if ! tarsync $(vvecho -v) -s 1 -o portage -g portage -e /distfiles -e /packages -e /local "${file}" "${PORTDIR}"; then |
102 |
eecho "tarsync failed; tarball is corrupt? (${file})" |
103 |
return 1 |
104 |
fi |
105 |
else |
106 |
- if ! tar jxf "${file}"; then |
107 |
+ if ! do_tar "${file}" xf -; then |
108 |
eecho "tar failed to extract the image. tarball is corrupt? (${file})" |
109 |
rm -fr portage |
110 |
return 1 |
111 |
@@ -183,12 +196,12 @@ |
112 |
--exclude='/local' ${PORTAGE_RSYNC_EXTRA_OPTS} . "${PORTDIR%%/}" |
113 |
cd .. |
114 |
|
115 |
- vecho "Cleaning up..." |
116 |
+ vecho "Cleaning up ..." |
117 |
rm -fr portage |
118 |
fi |
119 |
|
120 |
if hasq metadata-transfer ${FEATURES} ; then |
121 |
- vecho "Updating cache..." |
122 |
+ vecho "Updating cache ..." |
123 |
emerge --metadata |
124 |
fi |
125 |
[ -x /etc/portage/bin/post_sync ] && /etc/portage/bin/post_sync |
126 |
@@ -201,73 +214,80 @@ |
127 |
|
128 |
local r=1 |
129 |
|
130 |
- local file="portage-${date}.tar.bz2" |
131 |
- local digest="${file}.md5sum" |
132 |
- local signature="${file}.gpgsig" |
133 |
+ local base_file="portage-${date}.tar" |
134 |
|
135 |
local have_files=0 |
136 |
local mirror |
137 |
|
138 |
- vecho "Trying to retrieve ${date} snapshot..." |
139 |
- |
140 |
for mirror in ${GENTOO_MIRRORS} ; do |
141 |
|
142 |
- [ -s "${file}" -a -s "${digest}" -a -s "${signature}" ] && \ |
143 |
- check_file_digest "${digest}" "${file}" && \ |
144 |
- check_file_signature "${signature}" "${file}" && \ |
145 |
- have_files=1 |
146 |
+ vecho "Trying to retrieve ${date} snapshot from ${mirror} ..." |
147 |
|
148 |
- [ ${have_files} == 0 ] && \ |
149 |
- fetch_file "${mirror}/snapshots/${digest}" "${digest}" && \ |
150 |
- fetch_file "${mirror}/snapshots/${signature}" "${signature}" && \ |
151 |
- fetch_file "${mirror}/snapshots/${file}" "${file}" && \ |
152 |
- check_file_digest "${digest}" "${file}" && \ |
153 |
- check_file_signature "${signature}" "${file}" && \ |
154 |
- have_files=1 |
155 |
+ for compression in lzma bz2 gz ; do |
156 |
+ local file="portage-${date}.tar.${compression}" |
157 |
+ local digest="${file}.md5sum" |
158 |
+ local signature="${file}.gpgsig" |
159 |
|
160 |
- # |
161 |
- # If timestamp is invalid |
162 |
- # we want to try and retieve |
163 |
- # from a different mirror |
164 |
- # |
165 |
- if [ ${have_files} != 0 ]; then |
166 |
+ if [ -s "${file}" -a -s "${digest}" -a -s "${signature}" ] ; then |
167 |
+ check_file_digest "${digest}" "${file}" && \ |
168 |
+ check_file_signature "${signature}" "${file}" && \ |
169 |
+ have_files=1 |
170 |
+ fi |
171 |
|
172 |
- vecho "Getting snapshot timetasmp..." |
173 |
- local snapshot_timestamp=$(get_snapshot_timestamp "${file}") |
174 |
+ if [ ${have_files} -eq 0 ] ; then |
175 |
+ fetch_file "${mirror}/snapshots/${digest}" "${digest}" && \ |
176 |
+ fetch_file "${mirror}/snapshots/${signature}" "${signature}" && \ |
177 |
+ fetch_file "${mirror}/snapshots/${file}" "${file}" && \ |
178 |
+ check_file_digest "${digest}" "${file}" && \ |
179 |
+ check_file_signature "${signature}" "${file}" && \ |
180 |
+ have_files=1 |
181 |
+ fi |
182 |
|
183 |
- if [ ${ignore_timestamp} == 0 ]; then |
184 |
- if [ ${snapshot_timestamp} -lt $(get_portage_timestamp) ]; then |
185 |
- wecho "portage is newer than snapshot" |
186 |
- have_files=0 |
187 |
+ # |
188 |
+ # If timestamp is invalid |
189 |
+ # we want to try and retrieve |
190 |
+ # from a different mirror |
191 |
+ # |
192 |
+ if [ ${have_files} -eq 1 ]; then |
193 |
+ |
194 |
+ vecho "Getting snapshot timetasmp ..." |
195 |
+ local snapshot_timestamp=$(get_snapshot_timestamp "${file}") |
196 |
+ |
197 |
+ if [ ${ignore_timestamp} == 0 ]; then |
198 |
+ if [ ${snapshot_timestamp} -lt $(get_portage_timestamp) ]; then |
199 |
+ wecho "portage is newer than snapshot" |
200 |
+ have_files=0 |
201 |
+ fi |
202 |
+ else |
203 |
+ local utc_seconds=$(get_utc_second_from_string "${date}") |
204 |
+ |
205 |
+ # |
206 |
+ # Check that this snapshot |
207 |
+ # is what it claims to be ... |
208 |
+ # |
209 |
+ if [ ${snapshot_timestamp} -lt ${utc_seconds} ] || \ |
210 |
+ [ ${snapshot_timestamp} -gt $((${utc_seconds}+ 2*86400)) ]; then |
211 |
+ |
212 |
+ wecho "snapshot timestamp is not in acceptable period" |
213 |
+ have_files=0 |
214 |
+ fi |
215 |
fi |
216 |
+ fi |
217 |
+ |
218 |
+ if [ ${have_files} -eq 1 ]; then |
219 |
+ break |
220 |
else |
221 |
- local utc_seconds=$(get_utc_second_from_string "${date}") |
222 |
- |
223 |
# |
224 |
- # Check that this snapshot |
225 |
- # is what it claims to be... |
226 |
+ # Remove files and use a different mirror |
227 |
# |
228 |
- if [ ${snapshot_timestamp} -lt ${utc_seconds} ] || \ |
229 |
- [ ${snapshot_timestamp} -gt $((${utc_seconds}+ 2*86400)) ]; then |
230 |
- |
231 |
- wecho "snapshot timestamp is not in acceptable period" |
232 |
- have_files=0 |
233 |
- fi |
234 |
+ rm -f "${file}" "${digest}" "${signature}" |
235 |
fi |
236 |
- fi |
237 |
+ done |
238 |
|
239 |
- if [ ${have_files} != 0 ]; then |
240 |
- break; |
241 |
- else |
242 |
- # |
243 |
- # Remove files and use |
244 |
- # a diffeernt mirror |
245 |
- # |
246 |
- rm -f "${file}" "${digest}" "${signature}" |
247 |
- fi |
248 |
+ [ ${have_files} -eq 1 ] && break |
249 |
done |
250 |
|
251 |
- if [ ${have_files} != 0 ]; then |
252 |
+ if [ ${have_files} -eq 1 ]; then |
253 |
sync_local "${file}" && r=0 |
254 |
else |
255 |
vecho "${date} snapshot was not found" |
256 |
@@ -281,7 +301,7 @@ |
257 |
local attempts=-1 |
258 |
local r=1 |
259 |
|
260 |
- vecho "Fetching most recent snapshot..." |
261 |
+ vecho "Fetching most recent snapshot ..." |
262 |
|
263 |
while (( ${attempts} < 40 )) ; do |
264 |
local day |
265 |
|
266 |
-- |
267 |
gentoo-commits@l.g.o mailing list |