Home | History | Annotate | Download | only in cros_pkg
      1 #!/bin/bash -u
      2 #
      3 # Copyright 2015 Google Inc. All Rights Reserved.
      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 
     26 BOARD=$1
     27 REMOTE=$2
     28 
     29 GOOD_BUILD=/build/${BOARD}.good
     30 BAD_BUILD=/build/${BOARD}.bad
     31 WORK_BUILD=/build/${BOARD}.work
     32 
     33 #
     34 # Verify that the necessary directories exist.
     35 #
     36 
     37 if [[ ! -d ${GOOD_BUILD} ]] ; then
     38     echo "Error:  ${GOOD_BUILD} does not exist."
     39     exit 1
     40 fi
     41 
     42 if [[ ! -d ${BAD_BUILD} ]] ; then
     43     echo "Error:  ${BAD_BUILD} does not exist."
     44     exit 1
     45 fi
     46 
     47 if [[ ! -d ${WORK_BUILD} ]] ; then
     48     echo "Error:  ${WORK_BUILD} does not exist."
     49     exit 1
     50 fi
     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 
     59 build_tree_existed=0
     60 build_tree_was_soft_link=0
     61 build_tree_renamed=0
     62 build_tree_link=""
     63 
     64 if [[ -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
     74 fi
     75 
     76 # Make "working' tree the default board tree (set up soft link)
     77 
     78 sudo ln -s /build/${BOARD}.work /build/${BOARD}
     79 
     80 #
     81 # Create common.sh file, containing appropriate environment variables.
     82 #
     83 
     84 COMMON_FILE="common/common.sh"
     85 
     86 cat <<-EOF > ${COMMON_FILE}
     87 
     88 BISECT_BOARD=${BOARD}
     89 BISECT_REMOTE=${REMOTE}
     90 BISECT_MODE="PACKAGE_MODE"
     91 
     92 GOOD_BUILD=/build/${BOARD}.good
     93 BAD_BUILD=/build/${BOARD}.bad
     94 WORK_BUILD=/build/${BOARD}.work
     95 
     96 EOF
     97 
     98 chmod 755 ${COMMON_FILE}
     99 
    100 #
    101 # Create clean-up script, calling create_cleanup_script.py with
    102 # the appropriate flags.
    103 #
    104 
    105 if [[ ${build_tree_existed} -eq 0 ]] ; then
    106 
    107     python cros_pkg/create_cleanup_script.py --board=${BOARD} \
    108         --old_tree_missing
    109 
    110 elif [[ ${build_tree_was_soft_link} -eq 0 ]] ; then
    111 
    112     python cros_pkg/create_cleanup_script.py --board=${BOARD} \
    113         --renamed_tree
    114 
    115 else
    116 
    117     python cros_pkg/create_cleanup_script.py --board=${BOARD} \
    118         --old_link="'${build_tree_link}'"
    119 fi
    120 
    121 chmod 755 cros_pkg/${BOARD}_cleanup.sh
    122 
    123 exit 0
    124