1#!/bin/bash -u 2# 3# Copyright 2015 Google LLC 4# 5# This script is part of the ChromeOS package binary search triage process. 6# It should be the first script called by the user, after the user has set up 7# the three necessary build tree directories (see the prerequisites section of 8# README.cros_pkg_triage). 9# 10# This script requires two arguments. The first argument must be the name of 11# the board for which this work is being done (e.g. 'daisy', 'lumpy','parrot', 12# etc.). The second argument must be the name or IP address of the chromebook 13# on which the ChromeOS images will be pushed and tested. 14# 15# This script sets up a soft link definining /build/${board} to point 16# to the working build tree, for the binary search triags process. In 17# addition, this script generates two other scripts, common.sh, 18# which generates enviroment variables used by the other scripts in the 19# package binary search triage process; and ${board}_cleanup.sh, 20# which undoes the various changes that this script performs, returning the 21# user's environment to its original state. 22# 23 24# Set up basic variables. 25 26BOARD=$1 27REMOTE=$2 28 29GOOD_BUILD=/build/${BOARD}.good 30BAD_BUILD=/build/${BOARD}.bad 31WORK_BUILD=/build/${BOARD}.work 32 33# 34# Verify that the necessary directories exist. 35# 36 37if [[ ! -d ${GOOD_BUILD} ]] ; then 38 echo "Error: ${GOOD_BUILD} does not exist." 39 exit 1 40fi 41 42if [[ ! -d ${BAD_BUILD} ]] ; then 43 echo "Error: ${BAD_BUILD} does not exist." 44 exit 1 45fi 46 47if [[ ! -d ${WORK_BUILD} ]] ; then 48 echo "Error: ${WORK_BUILD} does not exist." 49 exit 1 50fi 51 52# 53# Check to see if /build/${BOARD} already exists and if so, in what state. 54# Set appropriate flags & values, in order to be able to undo these changes 55# in ${board}_cleanup.sh. If it's a soft link, remove it; if it's a 56# read tree, rename it. 57# 58 59build_tree_existed=0 60build_tree_was_soft_link=0 61build_tree_renamed=0 62build_tree_link="" 63 64if [[ -d "/build/${BOARD}" ]] ; then 65 build_tree_existed=1 66 if [[ -L "/build/${BOARD}" ]] ; then 67 build_tree_was_soft_link=1 68 build_tree_link=`readlink /build/${BOARD}` 69 sudo rm /build/${BOARD} 70 else 71 build_tree_renamed=1 72 sudo mv /build/${BOARD} /build/${BOARD}.save 73 fi 74fi 75 76# Make "working' tree the default board tree (set up soft link) 77 78sudo ln -s /build/${BOARD}.work /build/${BOARD} 79 80# 81# Create common.sh file, containing appropriate environment variables. 82# 83 84COMMON_FILE="common/common.sh" 85 86cat <<-EOF > ${COMMON_FILE} 87 88BISECT_BOARD=${BOARD} 89BISECT_REMOTE=${REMOTE} 90BISECT_MODE="PACKAGE_MODE" 91 92GOOD_BUILD=/build/${BOARD}.good 93BAD_BUILD=/build/${BOARD}.bad 94WORK_BUILD=/build/${BOARD}.work 95 96EOF 97 98chmod 755 ${COMMON_FILE} 99 100# 101# Create clean-up script, calling create_cleanup_script.py with 102# the appropriate flags. 103# 104 105if [[ ${build_tree_existed} -eq 0 ]] ; then 106 107 python cros_pkg/create_cleanup_script.py --board=${BOARD} \ 108 --old_tree_missing 109 110elif [[ ${build_tree_was_soft_link} -eq 0 ]] ; then 111 112 python cros_pkg/create_cleanup_script.py --board=${BOARD} \ 113 --renamed_tree 114 115else 116 117 python cros_pkg/create_cleanup_script.py --board=${BOARD} \ 118 --old_link="'${build_tree_link}'" 119fi 120 121chmod 755 cros_pkg/${BOARD}_cleanup.sh 122 123exit 0 124