aboutsummaryrefslogtreecommitdiff
path: root/binary_search_tool/cros_pkg/setup.sh
blob: ae31fa8252456690e8c39524a7cdb3901532521d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash -u
#
# Copyright 2015 Google Inc. All Rights Reserved.
#
# This script is part of the ChromeOS package binary search triage process.
# It should be the first script called by the user, after the user has set up
# the three necessary build tree directories (see the prerequisites section of
# README.cros_pkg_triage).
#
# This script requires two arguments.  The first argument must be the name of
# the board for which this work is being done (e.g. 'daisy', 'lumpy','parrot',
# etc.).  The second argument must be the name or IP address of the chromebook
# on which the ChromeOS images will be pushed and tested.
#
# This script sets up a soft link definining /build/${board} to point
# to the working build tree, for the binary search triags process.  In
# addition, this script generates two other scripts, common.sh,
# which generates enviroment variables used by the other scripts in the
# package binary search triage process; and ${board}_cleanup.sh,
# which undoes the various changes that this script performs, returning the
# user's environment to its original state.
#

# Set up basic variables.

BOARD=$1
REMOTE=$2

GOOD_BUILD=/build/${BOARD}.good
BAD_BUILD=/build/${BOARD}.bad
WORK_BUILD=/build/${BOARD}.work

#
# Verify that the necessary directories exist.
#

if [[ ! -d ${GOOD_BUILD} ]] ; then
    echo "Error:  ${GOOD_BUILD} does not exist."
    exit 1
fi

if [[ ! -d ${BAD_BUILD} ]] ; then
    echo "Error:  ${BAD_BUILD} does not exist."
    exit 1
fi

if [[ ! -d ${WORK_BUILD} ]] ; then
    echo "Error:  ${WORK_BUILD} does not exist."
    exit 1
fi

#
# Check to see if /build/${BOARD} already exists and if so, in what state.
# Set appropriate flags & values, in order to be able to undo these changes
# in ${board}_cleanup.sh. If it's a soft link, remove it; if it's a
# read tree, rename it.
#

build_tree_existed=0
build_tree_was_soft_link=0
build_tree_renamed=0
build_tree_link=""

if [[ -d "/build/${BOARD}" ]] ; then
    build_tree_existed=1
    if [[ -L "/build/${BOARD}" ]] ; then
        build_tree_was_soft_link=1
        build_tree_link=`readlink /build/${BOARD}`
        sudo rm /build/${BOARD}
    else
        build_tree_renamed=1
        sudo mv /build/${BOARD} /build/${BOARD}.save
    fi
fi

# Make "working' tree the default board tree (set up soft link)

sudo ln -s /build/${BOARD}.work /build/${BOARD}

#
# Create common.sh file, containing appropriate environment variables.
#

COMMON_FILE="common/common.sh"

cat <<-EOF > ${COMMON_FILE}

BISECT_BOARD=${BOARD}
BISECT_REMOTE=${REMOTE}
BISECT_MODE="PACKAGE_MODE"

GOOD_BUILD=/build/${BOARD}.good
BAD_BUILD=/build/${BOARD}.bad
WORK_BUILD=/build/${BOARD}.work

EOF

chmod 755 ${COMMON_FILE}

#
# Create clean-up script, calling create_cleanup_script.py with
# the appropriate flags.
#

if [[ ${build_tree_existed} -eq 0 ]] ; then

    python cros_pkg/create_cleanup_script.py --board=${BOARD} \
        --old_tree_missing

elif [[ ${build_tree_was_soft_link} -eq 0 ]] ; then

    python cros_pkg/create_cleanup_script.py --board=${BOARD} \
        --renamed_tree

else

    python cros_pkg/create_cleanup_script.py --board=${BOARD} \
        --old_link="'${build_tree_link}'"
fi

chmod 755 cros_pkg/${BOARD}_cleanup.sh

exit 0