mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-24 23:21:17 +02:00
Change-Id: I30e97760d5b96077e38414be31ef434542021361 Review URL: http://codereview.chromium.org/2883012
117 lines
3.4 KiB
Bash
Executable File
117 lines
3.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
# This script moves ebuilds between 'stable' and 'live' states.
|
|
# By default 'stable' ebuilds point at and build from source at the
|
|
# last known good commit. Moving an ebuild to 'live' (via cros_workon start)
|
|
# is intended to support development. The current source tip is fetched,
|
|
# source modified and built using the unstable 'live' (9999) ebuild.
|
|
|
|
# Load common constants. This should be the first executable line.
|
|
# The path to common.sh should be relative to your script's location.
|
|
. "$(dirname "$0")/common.sh"
|
|
|
|
# Script must be run inside the chroot
|
|
restart_in_chroot_if_needed $*
|
|
get_default_board
|
|
|
|
DEFINE_string board "${DEFAULT_BOARD}" \
|
|
"The board to set package keywords for."
|
|
DEFINE_string command "git status" \
|
|
"The command to be run by forall."
|
|
|
|
FLAGS_HELP="usage: $0 <command> [flags]
|
|
commands:
|
|
start: Moves an ebuild to live (intended to support development)
|
|
stop: Moves an ebuild to stable (use last known good)
|
|
list: List of all live ebuilds
|
|
forall: For each ebuild, cd to the source dir and run a commond"
|
|
FLAGS "$@" || exit 1
|
|
eval set -- "${FLAGS_ARGV}"
|
|
|
|
[ -n "${FLAGS_board}" ] || die "--board is required."
|
|
|
|
# eat the workon command keywords: start, stop or list.
|
|
WORKON_CMD=$1
|
|
shift
|
|
|
|
BOARD_DIR=/build/"${FLAGS_board}"
|
|
KEYWORDS_DIR=${BOARD_DIR}/etc/portage/package.keywords
|
|
KEYWORDS_FILE=${KEYWORDS_DIR}/cros-workon
|
|
|
|
sudo mkdir -p "${KEYWORDS_DIR}" || die "mkdir -p ${KEYWORDS_DIR}"
|
|
sudo touch "${KEYWORDS_FILE}" || die "touch ${KEYWORDS_FILE}"
|
|
|
|
# Canonicalize package name to category/package.
|
|
canonicalize_name () {
|
|
equery-${FLAGS_board} which $1 | \
|
|
awk -F '/' '{ print $(NF-2) "/" $(NF-1) }'
|
|
}
|
|
|
|
# Canonicalize a list of names.
|
|
canonicalize_names () {
|
|
local atoms=$1
|
|
local names=""
|
|
|
|
for atom in ${atoms}; do
|
|
local name=$(canonicalize_name "${atom}")
|
|
[ -n "${name}" ] || return 1
|
|
names+=" ${name}"
|
|
done
|
|
echo ${names}
|
|
}
|
|
|
|
# Display ebuilds currently part of the live branch and open for development.
|
|
show_live_ebuilds () {
|
|
cat "${KEYWORDS_FILE}"
|
|
}
|
|
|
|
ATOM_LIST=$@
|
|
ATOM_LIST=$(canonicalize_names "${ATOM_LIST}") || die "Invalid package name"
|
|
[ -n "${ATOM_LIST}" ] || ATOM_LIST=$(show_live_ebuilds)
|
|
|
|
# Move a stable ebuild to the live development catgeory. The ebuild
|
|
# src_unpack step fetches the package source for local development.
|
|
ebuild_to_live () {
|
|
local atoms=$1
|
|
|
|
for atom in ${atoms}; do
|
|
if ! grep -qx "${atom}" "${KEYWORDS_FILE}" ; then
|
|
sudo bash -c "echo \"${atom}\" >> \"${KEYWORDS_FILE}\""
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Move a live development ebuild back to stable.
|
|
ebuild_to_stable () {
|
|
local atoms=$1
|
|
|
|
for atom in ${atoms}; do
|
|
sudo bash -c "grep -v '^${atom}\$' \"${KEYWORDS_FILE}\" > \
|
|
\"${KEYWORDS_FILE}+\""
|
|
sudo mv "${KEYWORDS_FILE}+" "${KEYWORDS_FILE}"
|
|
done
|
|
}
|
|
|
|
# Run a command on all or a set of repos.
|
|
ebuild_forall() {
|
|
local atoms=$1
|
|
|
|
for atom in ${atoms}; do
|
|
info "Running \"${FLAGS_command}\" on ${atom}"
|
|
eval $(ebuild-${FLAGS_board} $(equery-${FLAGS_board} which ${atom}) info)
|
|
(cd "${CROS_WORKON_SRCDIR}" && bash -c "${FLAGS_command}")
|
|
done
|
|
}
|
|
|
|
case ${WORKON_CMD} in
|
|
start) ebuild_to_live "${ATOM_LIST}" ;;
|
|
stop) ebuild_to_stable "${ATOM_LIST}" ;;
|
|
list) show_live_ebuilds ;;
|
|
forall) ebuild_forall "${ATOM_LIST}" ;;
|
|
*) die "invalid cros_workon command" ;;
|
|
esac
|