OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # This script moves ebuilds between 'stable' and 'live' states. | 7 # This script moves ebuilds between 'stable' and 'live' states. |
8 # By default 'stable' ebuilds point at and build from source at the | 8 # By default 'stable' ebuilds point at and build from source at the |
9 # last known good commit. Moving an ebuild to 'live' (via cros_workon start) | 9 # last known good commit. Moving an ebuild to 'live' (via cros_workon start) |
10 # is intended to support development. The current source tip is fetched, | 10 # is intended to support development. The current source tip is fetched, |
11 # source modified and built using the unstable 'live' (9999) ebuild. | 11 # source modified and built using the unstable 'live' (9999) ebuild. |
12 | 12 |
13 # Load common constants. This should be the first executable line. | 13 # Load common constants. This should be the first executable line. |
14 # The path to common.sh should be relative to your script's location. | 14 # The path to common.sh should be relative to your script's location. |
15 . "$(dirname "$0")/common.sh" | 15 . "$(dirname "$0")/common.sh" |
16 | 16 |
17 # Script must be run inside the chroot | 17 # Script must be run inside the chroot |
18 restart_in_chroot_if_needed $* | 18 restart_in_chroot_if_needed $* |
19 get_default_board | 19 get_default_board |
20 | 20 |
21 DEFINE_string board "${DEFAULT_BOARD}" \ | 21 DEFINE_string board "${DEFAULT_BOARD}" \ |
22 "The board to set package keywords for." | 22 "The board to set package keywords for." |
| 23 DEFINE_boolean host "${FLAGS_FALSE}" \ |
| 24 "Uses the host instead of board" |
23 DEFINE_string command "git status" \ | 25 DEFINE_string command "git status" \ |
24 "The command to be run by forall." | 26 "The command to be run by forall." |
25 | 27 |
26 FLAGS_HELP="usage: $0 <command> [flags] | 28 FLAGS_HELP="usage: $0 <command> [flags] |
27 commands: | 29 commands: |
28 start: Moves an ebuild to live (intended to support development) | 30 start: Moves an ebuild to live (intended to support development) |
29 stop: Moves an ebuild to stable (use last known good) | 31 stop: Moves an ebuild to stable (use last known good) |
30 list: List of all live ebuilds | 32 list: List of all live ebuilds |
31 forall: For each ebuild, cd to the source dir and run a commond" | 33 forall: For each ebuild, cd to the source dir and run a commond" |
32 FLAGS "$@" || exit 1 | 34 FLAGS "$@" || exit 1 |
33 eval set -- "${FLAGS_ARGV}" | 35 eval set -- "${FLAGS_ARGV}" |
34 | 36 |
35 [ -n "${FLAGS_board}" ] || die "--board is required." | 37 # board dir config |
| 38 [ -n "${FLAGS_board}" ] && [ "${FLAGS_host}" = ${FLAGS_TRUE} ] && \ |
| 39 die "Flags --host and --board are mutually exclusive." |
| 40 [ -z "${FLAGS_board}" ] && [ "${FLAGS_host}" = ${FLAGS_FALSE} ] && \ |
| 41 die "You must specify either --host or --board=" |
| 42 |
| 43 if [ -n "${FLAGS_board}" ]; then |
| 44 BOARD_DIR=/build/"${FLAGS_board}" # --board specified |
| 45 EQUERY=equery-"${FLAGS_board}" |
| 46 else |
| 47 BOARD_DIR="" # --host specified |
| 48 EQUERY=equery |
| 49 fi |
| 50 |
36 | 51 |
37 # eat the workon command keywords: start, stop or list. | 52 # eat the workon command keywords: start, stop or list. |
38 WORKON_CMD=$1 | 53 WORKON_CMD=$1 |
39 shift | 54 shift |
40 | 55 |
41 BOARD_DIR=/build/"${FLAGS_board}" | |
42 | 56 |
43 KEYWORDS_DIR=${BOARD_DIR}/etc/portage/package.keywords | 57 KEYWORDS_DIR=${BOARD_DIR}/etc/portage/package.keywords |
44 UNMASK_DIR=${BOARD_DIR}/etc/portage/package.unmask | 58 UNMASK_DIR=${BOARD_DIR}/etc/portage/package.unmask |
45 KEYWORDS_FILE=${KEYWORDS_DIR}/cros-workon | 59 KEYWORDS_FILE=${KEYWORDS_DIR}/cros-workon |
46 UNMASK_FILE=${UNMASK_DIR}/cros-workon | 60 UNMASK_FILE=${UNMASK_DIR}/cros-workon |
47 | 61 |
48 sudo mkdir -p "${KEYWORDS_DIR}" "${UNMASK_DIR}" || die "mkdir -p ${KEYWORDS_DIR}
${UNMASK_DIR}" | 62 sudo mkdir -p "${KEYWORDS_DIR}" "${UNMASK_DIR}" || \ |
49 sudo touch "${KEYWORDS_FILE}" "${UNMASK_FILE}" || die "touch ${KEYWORDS_FILE} ${
UNMASK_FILE}" | 63 die "mkdir -p ${KEYWORDS_DIR} ${UNMASK_DIR}" |
| 64 sudo touch "${KEYWORDS_FILE}" "${UNMASK_FILE}" || \ |
| 65 die "touch ${KEYWORDS_FILE} ${UNMASK_FILE}" |
50 | 66 |
51 # Canonicalize package name to category/package. | 67 # Canonicalize package name to category/package. |
52 canonicalize_name () { | 68 canonicalize_name () { |
53 equery-${FLAGS_board} which $1 | \ | 69 ${EQUERY} which $1 | \ |
54 awk -F '/' '{ print $(NF-2) "/" $(NF-1) }' | 70 awk -F '/' '{ print $(NF-2) "/" $(NF-1) }' |
55 } | 71 } |
56 | 72 |
57 # Canonicalize a list of names. | 73 # Canonicalize a list of names. |
58 canonicalize_names () { | 74 canonicalize_names () { |
59 local atoms=$1 | 75 local atoms=$1 |
60 local names="" | 76 local names="" |
61 | 77 |
62 for atom in ${atoms}; do | 78 for atom in ${atoms}; do |
63 local name=$(canonicalize_name "${atom}") | 79 local name=$(canonicalize_name "${atom}") |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 121 |
106 done | 122 done |
107 } | 123 } |
108 | 124 |
109 # Run a command on all or a set of repos. | 125 # Run a command on all or a set of repos. |
110 ebuild_forall() { | 126 ebuild_forall() { |
111 local atoms=$1 | 127 local atoms=$1 |
112 | 128 |
113 for atom in ${atoms}; do | 129 for atom in ${atoms}; do |
114 info "Running \"${FLAGS_command}\" on ${atom}" | 130 info "Running \"${FLAGS_command}\" on ${atom}" |
115 eval $(ebuild-${FLAGS_board} $(equery-${FLAGS_board} which ${atom}) info) | 131 eval $(ebuild-${FLAGS_board} $(${EQUERY} which ${atom}) info) |
116 (cd "${CROS_WORKON_SRCDIR}" && bash -c "${FLAGS_command}") | 132 (cd "${CROS_WORKON_SRCDIR}" && bash -c "${FLAGS_command}") |
117 done | 133 done |
118 } | 134 } |
119 | 135 |
120 case ${WORKON_CMD} in | 136 case ${WORKON_CMD} in |
121 start) ebuild_to_live "${ATOM_LIST}" ;; | 137 start) ebuild_to_live "${ATOM_LIST}" ;; |
122 stop) ebuild_to_stable "${ATOM_LIST}" ;; | 138 stop) ebuild_to_stable "${ATOM_LIST}" ;; |
123 list) show_live_ebuilds ;; | 139 list) show_live_ebuilds ;; |
124 forall) ebuild_forall "${ATOM_LIST}" ;; | 140 forall) ebuild_forall "${ATOM_LIST}" ;; |
125 *) die "invalid cros_workon command" ;; | 141 *) die "invalid cros_workon command" ;; |
126 esac | 142 esac |
OLD | NEW |