mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-08 13:36:58 +02:00
And default to git instead of rsync. git has no rate limiting and will generally be quicker after the first run. This does leave a bit of extra data in your local portage-stable `.git` directory, but it doesn't seem unreasonable to me. Note: this means we lose the "ChangeLog" file. In the rsync repositories, that file has been generated by egencache, but the git repository never has it checked in.
104 lines
3.2 KiB
Bash
Executable File
104 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Copyright (c) 2013 The CoreOS Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
|
|
. "${SCRIPT_ROOT}/common.sh" || exit 1
|
|
|
|
# Default RSYNC options emerge --sync uses
|
|
RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --timeout=180"
|
|
|
|
DEFINE_string portage "git" \
|
|
"Path to a local portage tree or 'rsync' or 'git' to fetch from remote."
|
|
DEFINE_string portage_stable "${SRC_ROOT}/third_party/portage-stable" \
|
|
"Path to the portage-stable git checkout."
|
|
DEFINE_string git "https://github.com/gentoo/gentoo.git" \
|
|
"git location for the gentoo portage repo (for use with --portage=git)"
|
|
DEFINE_string rsync "rsync://rsync.gentoo.org/gentoo-portage" \
|
|
"Rsync location for gentoo-portage to use with --portage=rsync"
|
|
DEFINE_boolean commit ${FLAGS_FALSE} \
|
|
"Commit all changes after updating portage-stable."
|
|
DEFINE_boolean regencache ${FLAGS_TRUE} \
|
|
"Regenerate cache for updated ebuilds."
|
|
|
|
|
|
# Parse flags
|
|
FLAGS "$@" || exit 1
|
|
eval set -- "${FLAGS_ARGV}"
|
|
switch_to_strict_mode
|
|
|
|
# Accept arguments from STDIN for batch processing
|
|
if [[ -z "$*" ]]; then
|
|
set -- $(</dev/stdin)
|
|
fi
|
|
|
|
if [[ -z "$*" ]]; then
|
|
die "No packages provided"
|
|
fi
|
|
|
|
# eclass updates impact coreos-overlay too, use update_metadata.
|
|
if [[ "$*" == *eclass* ]]; then
|
|
FLAGS_regencache=${FLAGS_FALSE}
|
|
fi
|
|
|
|
cd "$FLAGS_portage_stable"
|
|
|
|
for pkg in "$@"; do
|
|
# Only allow packages, not categories or the whole tree
|
|
if [[ ! "$pkg" =~ ^[a-z0-9-][a-z0-9-]*\/[a-zA-Z0-9-][a-zA-Z0-9_-]*$ ]] &&
|
|
[[ ! "$pkg" =~ ^(eclass|licenses|profiles|scripts|metadata/glsa) ]]; then
|
|
die "Invalid name $pkg, must be category/package or special dir."
|
|
fi
|
|
|
|
if [[ "$FLAGS_portage" == git ]]; then
|
|
rm -rf "$pkg"
|
|
if [[ "$(git remote get-url update_ebuilds)" != "${FLAGS_git}" ]]; then
|
|
git remote rm update_ebuilds || true
|
|
git remote add update_ebuilds "${FLAGS_git}"
|
|
fi
|
|
git fetch update_ebuilds
|
|
git checkout refs/remotes/update_ebuilds/master -- "$pkg"
|
|
else
|
|
if [[ "$FLAGS_portage" == rsync ]]; then
|
|
FLAGS_portage="${FLAGS_rsync}"
|
|
fi
|
|
mkdir -p "$pkg"
|
|
rsync $RSYNC_OPTS -v --exclude CVS "$FLAGS_portage/$pkg/" "$pkg"
|
|
fi
|
|
|
|
# Make sure we don't change the repo name to 'gentoo'
|
|
if [[ "$pkg" =~ ^profiles ]]; then
|
|
echo portage-stable > profiles/repo_name
|
|
fi
|
|
|
|
git add -A "$pkg"
|
|
|
|
# Sync up the ebuild metadata cache
|
|
if [[ $FLAGS_regencache -eq $FLAGS_TRUE && "$pkg" == */* && "$pkg" != metadata/glsa ]]; then
|
|
egencache --repo=portage-stable --update "$pkg"
|
|
git add -A "metadata/md5-cache/${pkg}-*"
|
|
fi
|
|
done
|
|
|
|
if [[ $FLAGS_commit -eq $FLAGS_TRUE ]]; then
|
|
if [[ $# -eq 1 ]]; then
|
|
git commit -e -m "bump($1): sync with upstream"
|
|
else
|
|
cat > .git/COMMIT_EDITMSG <<EOF
|
|
bump($1): sync with upstream
|
|
|
|
Packages updated:
|
|
$(for p in "$@"; do echo " $p"; done | sort)
|
|
EOF
|
|
git commit -e -F .git/COMMIT_EDITMSG
|
|
fi
|
|
else
|
|
git status
|
|
fi
|
|
|
|
if [[ "$*" == *eclass* ]]; then
|
|
info "Please run update_metadata to update cache in all overlays."
|
|
fi
|