setup.sh revision 545b947888df1d07f4ad530e1c5eec930fc283c2
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
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="cros_pkg/common.sh"
85
86cat <<-EOF > ${COMMON_FILE}
87
88BOARD=${BOARD}
89REMOTE=${REMOTE}
90
91GOOD_BUILD=/build/${BOARD}.good
92BAD_BUILD=/build/${BOARD}.bad
93WORK_BUILD=/build/${BOARD}.work
94
95EOF
96
97chmod 755 ${COMMON_FILE}
98
99#
100# Create clean-up script, calling create_cleanup_script.py with
101# the appropriate flags.
102#
103
104if [[ ${build_tree_existed} -eq 0 ]] ; then
105
106    python cros_pkg/create_cleanup_script.py --board=${BOARD} \
107        --old_tree_missing
108
109elif [[ ${build_tree_was_soft_link} -eq 0 ]] ; then
110
111    python cros_pkg/create_cleanup_script.py --board=${BOARD} \
112        --renamed_tree
113
114else
115
116    python cros_pkg/create_cleanup_script.py --board=${BOARD} \
117        --old_link="'${build_tree_link}'"
118fi
119
120chmod 755 cros_pkg/${BOARD}_cleanup.sh
121
122exit 0
123