-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sh
executable file
·141 lines (120 loc) · 3.79 KB
/
build.sh
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env bash
###
# build.sh – Build apps for testing or production.
#
# This script builds one or all of the VxSuite applications. It is used by
# setup-machine.sh when a machine becomes specialized and locked down.
#
# To keep the machine able to switch between apps for testing purposes, run:
#
# ./build.sh all
#
# Then, you can run a specific app for testing like so:
#
# ./run.sh mark
#
# This will leave the machine in an unlocked, unspecialized state suitable for
# testing out new builds/features/etc.
###
set -euo pipefail
local_user=`logname`
local_user_home_dir=$( getent passwd "${local_user}" | cut -d: -f6 )
# Make sure PATH includes cargo and /sbin
export PATH="${local_user_home_dir}/.cargo/bin:${PATH}:/sbin/"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Define vxsuite apps that can be built, along with the expected path prefix
ALL_APPS=(admin central-scan mark scan mark-scan)
APPS_PATH_PREFIX="${DIR}/vxsuite/apps"
# Define vxsuite services that can be built, along with the expected path prefix
ALL_SERVICES=(converter-ms-sems)
SERVICES_PATH_PREFIX="${DIR}/vxsuite/services"
usage() {
echo "usage: ./build.sh [all|$(IFS=\| ; echo "${ALL_APPS[*]}")]"
echo
echo "Build all or some of the VxSuite apps."
}
APPS_TO_BUILD=()
# Determine which apps to build
if [ $# = 0 ]; then
APPS_TO_BUILD+=(${ALL_APPS[@]})
else
for arg in $@; do
if [[ " ${ALL_APPS[@]} " =~ " ${arg} " ]]; then
if [[ ! " ${APPS_TO_BUILD[@]} " =~ " ${arg} " ]]; then
APPS_TO_BUILD+=($arg)
fi
elif [[ "${arg}" = all ]]; then
APPS_TO_BUILD=(${ALL_APPS[@]})
elif [[ "${arg}" = -h || "${arg}" = --help ]]; then
usage
exit 0
elif [[ "${arg}" = -* ]]; then
echo "✘ unknown option: ${arg}" >&2
usage >&2
exit 1
else
echo "✘ unknown app: ${arg}" >&2
usage >&2
exit 1
fi
done
fi
# Function that builds a single app
build() {
local APP="$1"
echo "🔨Building ${APP}"
export BUILD_ROOT="${DIR}/build/${APP}"
rm -rf "${BUILD_ROOT}"
# In order to get the subshell exit code without exiting the whole script, we
# need to temporarily set +e
set +e
(
set -euo pipefail
cd "${DIR}/vxsuite/apps/${APP}/frontend"
BUILD_ROOT="${BUILD_ROOT}/vxsuite" ./script/prod-build
cp -rp \
"${DIR}/run-scripts/run-${APP}.sh" \
"${DIR}/run-scripts/run-kiosk-browser.sh" \
"${DIR}/run-scripts/run-kiosk-browser-forever-and-log.sh" \
"${DIR}/config" \
"${DIR}/app-scripts" \
"${BUILD_ROOT}"
# temporary hack because the symlink works but somehow the copy doesn't for precinct-scanner
cd ${BUILD_ROOT}
rm -rf vxsuite # this is the built version
ln -s ../../vxsuite ./vxsuite
)
if [[ $? = 0 ]]; then
echo -e "\e[32m✅${APP} built\e[0m"
else
echo -e "\e[31m✘ ${APP} build failed! check the logs above\e[0m" >&2
exit 1
fi
set -e
}
echo "Building ${#APPS_TO_BUILD[@]} app(s): ${APPS_TO_BUILD[@]}"
if ! which kiosk-browser >/dev/null 2>&1
then
make offline-kiosk-browser
fi
for app in "${APPS_TO_BUILD[@]}"; do
build "${app}"
# mark-scan has additional daemons that need to be built
# crates were fetched while online, now we build the release while offline
if [[ "${app}" == "mark-scan" ]]; then
# default to 155 daemons
vx_daemons="accessible-controller pat-device-input"
vxsuite_env_file="${DIR}/vxsuite/.env"
# check for the 150 env var to build the 150 daemon instead
if grep REACT_APP_VX_MARK_SCAN_USE_BMD_150 $vxsuite_env_file | grep -i true > /dev/null 2>&1
then
vx_daemons="fai-100-controller"
fi
for vx_daemon in ${vx_daemons}
do
cd "${DIR}/vxsuite/apps/mark-scan/${vx_daemon}"
mkdir -p target && cargo build --offline --release --target-dir target/.
done
fi
done
exit 0