#!/bin/bash
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# Author: Karl Trygve Kalleberg <karltk@gentoo.org>
# Rewritten from the old, Perl-based emerge-webrsync script
eecho "could not find 'portageq'; aborting"
exit 1
fi
-eval $("${portageq}" envvar -v FEATURES FETCHCOMMAND GENTOO_MIRRORS \
+eval $("${portageq}" envvar -v DISTDIR FEATURES FETCHCOMMAND GENTOO_MIRRORS \
PORTAGE_BIN_PATH PORTAGE_GPG_DIR \
PORTAGE_NICENESS PORTAGE_RSYNC_EXTRA_OPTS PORTAGE_TMPDIR PORTDIR \
SYNC http_proxy ftp_proxy)
-DISTDIR="${PORTAGE_TMPDIR}/emerge-webrsync"
export http_proxy ftp_proxy
# If PORTAGE_NICENESS is overriden via the env then it will
do_verbose=0
do_debug=0
+keep=false
if has webrsync-gpg ${FEATURES} ; then
WEBSYNC_VERIFY_SIGNATURE=1
vecho "Fetching file ${FILE} ..."
# already set DISTDIR=
eval "${FETCHCOMMAND}" ${opts}
- [ -s "${FILE}" ]
+ [ -s "${DISTDIR}/${FILE}" ]
}
check_file_digest() {
vecho "Checking digest ..."
if type -P md5sum > /dev/null; then
- md5sum -c $digest && r=0
+ local md5sum_output=$(md5sum "${file}")
+ local digest_content=$(< "${digest}")
+ [ "${md5sum_output%%[[:space:]]*}" = "${digest_content%%[[:space:]]*}" ] && r=0
elif type -P md5 > /dev/null; then
[ "$(md5 -q "${file}")" == "$(cut -d ' ' -f 1 "${digest}")" ] && r=0
else
fi
# Free disk space
- rm -f "${file}"
+ ${keep} || rm -f "${file}"
chown portage:portage portage > /dev/null 2>&1 && \
chown -R portage:portage portage
for mirror in ${GENTOO_MIRRORS} ; do
+ mirror=${mirror%/}
vecho "Trying to retrieve ${date} snapshot from ${mirror} ..."
for compression in ${compressions} ; do
local digest="${file}.md5sum"
local signature="${file}.gpgsig"
- if [ -s "${file}" -a -s "${digest}" -a -s "${signature}" ] ; then
+ if [ -s "${DISTDIR}/${file}" -a -s "${DISTDIR}/${digest}" -a -s "${DISTDIR}/${signature}" ] ; then
check_file_digest "${DISTDIR}/${digest}" "${DISTDIR}/${file}" && \
check_file_signature "${DISTDIR}/${signature}" "${DISTDIR}/${file}" && \
have_files=1
if [ ${have_files} -eq 1 ]; then
vecho "Getting snapshot timestamp ..."
- local snapshot_timestamp=$(get_snapshot_timestamp "${file}")
+ local snapshot_timestamp=$(get_snapshot_timestamp "${DISTDIR}/${file}")
if [ ${ignore_timestamp} == 0 ]; then
if [ ${snapshot_timestamp} -lt $(get_portage_timestamp) ]; then
#
# Remove files and use a different mirror
#
- rm -f "${file}" "${digest}" "${signature}"
+ rm -f "${DISTDIR}/${file}" "${DISTDIR}/${digest}" "${DISTDIR}/${signature}"
fi
done
done
if [ ${have_files} -eq 1 ]; then
- sync_local "${file}" && r=0
+ sync_local "${DISTDIR}/${file}" && r=0
else
vecho "${date} snapshot was not found"
fi
-
- rm -f "${file}" "${digest}" "${signature}"
+
+ ${keep} || rm -f "${DISTDIR}/${file}" "${DISTDIR}/${digest}" "${DISTDIR}/${signature}"
return "${r}"
}
Options:
--revert=yyyymmdd Revert to snapshot
+ -k, --keep Keep snapshots in DISTDIR (don't delete)
-q, --quiet Only output errors
-v, --verbose Enable verbose output
-x, --debug Enable debug output
main() {
local arg
local revert_date
-
- [ ! -d "${DISTDIR}" ] && mkdir -p "${DISTDIR}"
- cd "${DISTDIR}"
for arg in "$@" ; do
local v=${arg#*=}
case ${arg} in
-h|--help) usage ;;
+ -k|--keep) keep=true ;;
-q|--quiet) PORTAGE_QUIET=1 ;;
-v|--verbose) do_verbose=1 ;;
-x|--debug) do_debug=1 ;;
esac
done
+ TMPDIR=${PORTAGE_TMPDIR}/emerge-webrsync
+ ${keep} || DISTDIR=${TMPDIR}
+
+ [ ! -d "${TMPDIR}" ] && mkdir -p "${TMPDIR}"
+ [ ! -d "${DISTDIR}" ] && mkdir -p "${DISTDIR}"
+ cd "${TMPDIR}" || exit 1
+
# This is a sanity check to help prevent people like funtoo users
# from accidentally wiping out their git tree.
if [[ -n $SYNC && ${SYNC#rsync:} = $SYNC ]] ; then