mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-10 06:26:57 +02:00
In both cases move making contact with the remote board to an earlier step and default the "board" option to whatever is reported by the remote. BUG=n0ne TEST=Run without board flag or .default_board Change-Id: I53330ce5ab05b4cff92ac3a384ae0202fc156953 Reviewed-on: http://gerrit.chromium.org/gerrit/433 Reviewed-by: Sam Leffler <sleffler@chromium.org> Tested-by: Paul Stewart <pstew@chromium.org>
119 lines
3.4 KiB
Bash
Executable File
119 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.
|
|
|
|
# Script to update a running device with an optionally built package out
|
|
# of your build directory
|
|
|
|
# --- BEGIN COMMON.SH BOILERPLATE ---
|
|
# Load common CrOS utilities. Inside the chroot this file is installed in
|
|
# /usr/lib/crosutils. Outside the chroot we find it relative to the script's
|
|
# location.
|
|
find_common_sh() {
|
|
local common_paths=(/usr/lib/crosutils "$(dirname "$(readlink -f "$0")")/..")
|
|
local path
|
|
|
|
SCRIPT_ROOT=
|
|
for path in "${common_paths[@]}"; do
|
|
if [ -r "${path}/common.sh" ]; then
|
|
SCRIPT_ROOT=${path}
|
|
break
|
|
fi
|
|
done
|
|
}
|
|
|
|
find_common_sh
|
|
. "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1)
|
|
# --- END COMMON.SH BOILERPLATE ---
|
|
|
|
. "${SCRIPT_ROOT}/remote_access.sh" || die "Unable to load remote_access.sh"
|
|
|
|
get_default_board
|
|
|
|
DEFINE_boolean verbose ${FLAGS_FALSE} \
|
|
"Whether to output verbose information for debugging."
|
|
DEFINE_boolean build ${FLAGS_FALSE} "Build package before installing"
|
|
DEFINE_string board "$DEFAULT_BOARD" \
|
|
"Board for which the package should be built/found"
|
|
DEFINE_string build_root "/build" \
|
|
"The root location for board sysroots."
|
|
|
|
FLAGS "$@" || exit 1
|
|
|
|
TMP=$(mktemp -d /tmp/cros_package_to_live.XXXX)
|
|
|
|
function cleanup {
|
|
if [ "${root_mount_type}" = ro ]; then
|
|
remote_sh "mount -o remount,ro /" || /bin/true
|
|
fi
|
|
if [ "${var_mount_noexec}" = yes ]; then
|
|
remote_sh "mount -o remount,noexec /var" || /bin/true
|
|
fi
|
|
cleanup_remote_access
|
|
rm -rf "${TMP}"
|
|
}
|
|
|
|
# Make sure we have a package name
|
|
if [ -z "${FLAGS_ARGV}" ]; then
|
|
echo "Please specify packages to install. For example:"
|
|
echo " $0 --remote=MyMachine flimflam"
|
|
exit 1
|
|
fi
|
|
|
|
remote_access_init
|
|
learn_board
|
|
|
|
if [ -z "${FLAGS_board}" ]; then
|
|
echo "Please specify a board using the --board=MyBoard argument"
|
|
exit 1
|
|
fi
|
|
|
|
set -e
|
|
trap cleanup EXIT
|
|
|
|
eval set -- "${FLAGS_ARGV}"
|
|
|
|
if [ ${FLAGS_build} -eq ${FLAGS_TRUE} ]; then
|
|
emerge-${FLAGS_board} $@
|
|
fi
|
|
|
|
PKGROOT="${FLAGS_build_root}/${FLAGS_board}/packages"
|
|
|
|
# Temporarily clear read-only flag on / if it is set
|
|
remote_sh "grep '\S* / ' /proc/mounts | tail -1 | awk '{ print \$4 }' |
|
|
cut -d, -f1"
|
|
root_mount_type=${REMOTE_OUT}
|
|
if [ "${root_mount_type}" = ro ]; then
|
|
remote_sh "mount -o remount,rw /"
|
|
fi
|
|
|
|
# Temporarily clear noexec flag on /var if it is set
|
|
remote_sh "grep '\S* /var ' /proc/mounts | tail -1 | awk '{ print \$4 }'"
|
|
if expr "${REMOTE_OUT}" : '.*noexec' >/dev/null; then
|
|
var_mount_noexec=yes
|
|
remote_sh "mount -o remount,exec /var"
|
|
fi
|
|
|
|
for pkg in $@; do
|
|
latest_pkg=$(ls -tr $PKGROOT/*/${pkg}-[0-9]* | tail -1)
|
|
if [ -z "${latest_pkg}" ]; then
|
|
echo "Could not find latest built version of ${pkg}"
|
|
exit 1
|
|
fi
|
|
pkg_dir=$(basename "$(dirname "$latest_pkg")")
|
|
pkg_name=$(basename "$latest_pkg")
|
|
echo "Installing ${latest_pkg}..."
|
|
|
|
remote_sh "mktemp -d /tmp/cros_package_to_live.XXXX"
|
|
temp_dir=$REMOTE_OUT
|
|
remote_cp_to "${latest_pkg}" "${temp_dir}"
|
|
remote_sh "mkdir -p /usr/portage/packages/${pkg_dir} &&
|
|
mv ${temp_dir}/${pkg_name} /usr/portage/packages/${pkg_dir} &&
|
|
env FEATURES=-sandbox emerge --usepkg \
|
|
/usr/portage/packages/${pkg_dir}/${pkg_name} 1>&2"
|
|
echo "${pkg} has been installed"
|
|
remote_sh "rm -rf ${temp_dir}"
|
|
done
|