blob: 6726b8ab04dc4039dd8ebb79af73481035b3ab94 [file] [log] [blame]
Chirayu Desai9cfa05c2021-11-26 00:17:23 +05301#!/bin/bash
Chirayu Desaicc931dc2022-07-08 19:43:32 +05302
3# SPDX-FileCopyrightText: 2022 The Calyx Institute
4#
5# SPDX-License-Identifier: Apache-2.0
6
Chirayu Desai9cfa05c2021-11-26 00:17:23 +05307#
8# update-vars:
9#
10# Update Pixel device-specific variables by parsing Google's pages
11#
12#
13##############################################################################
14
15
16### SET ###
17
18# use bash strict mode
19set -euo pipefail
20
21
22### TRAPS ###
23
24# trap signals for clean exit
25trap 'rm -rf ${tmp_dir} && exit $?' EXIT
26trap 'error_m interrupted!' SIGINT
27
28### CONSTANTS ###
29readonly script_path="$(cd "$(dirname "$0")";pwd -P)"
Jis G Jacob4c84cfa2024-02-09 11:20:03 -050030readonly vars_path="${script_path}/../../../vendor/bliss/vars"
Chirayu Desai9cfa05c2021-11-26 00:17:23 +053031
32readonly tmp_dir="${TMPDIR:-/tmp}/pixel"
33
Chirayu Desaidd101d62022-03-01 23:38:44 +053034source "${vars_path}/pixels"
Chirayu Desai80c537e2023-05-01 23:58:23 +053035source "${vars_path}/common"
Chirayu Desai9cfa05c2021-11-26 00:17:23 +053036
37## HELP MESSAGE (USAGE INFO)
38# TODO
39
40### FUNCTIONS ###
41
42
43
44# error message
45# ARG1: error message for STDERR
46# ARG2: error status
47error_m() {
48 echo "ERROR: ${1:-'failed.'}" 1>&2
49 return "${2:-1}"
50}
51
52# print help message.
53help_message() {
54 echo "${help_message:-'No help available.'}"
55}
56
57main() {
58 mkdir -p "${tmp_dir}"
59 if [[ $# -ne 0 ]]; then
60 local ds="${@}"
61 else
62 local ds="${devices[@]}"
63 fi
64
65 for d in ${ds}; do
66 (
67 local tmp=$(mktemp "${tmp_dir}/${d}.XXXXXXXXXX")
68 local dv="${vars_path}/${d}"
69 source "${dv}"
Chirayu Desai80c537e2023-05-01 23:58:23 +053070 ${script_path}/get-new-device-vars.py -b "${build_id}" -d "${d}" -t ${aosp_tag_match}> "${tmp}"
Chirayu Desai9cfa05c2021-11-26 00:17:23 +053071 source "${tmp}"
72 if [[ "${new_aosp_tag}" != "${aosp_tag}" ]]; then
73 sed -i "/ prev_aosp_tag=/c\readonly prev_aosp_tag=\"$aosp_tag\"" "${dv}"
74 sed -i "/ aosp_tag=/c\readonly aosp_tag=\"$new_aosp_tag\"" "${dv}"
75 fi
Chirayu Desai695c3af2022-01-18 03:07:03 +053076 sed -i "/ build_number=/c\readonly build_number=\"$new_build_number\"" "${dv}"
Chirayu Desai9cfa05c2021-11-26 00:17:23 +053077 sed -i "/ image_url=/c\readonly image_url=\"$new_image_url\"" "${dv}"
78 sed -i "/ image_sha256=/c\readonly image_sha256=\"$new_image_sha256\"" "${dv}"
79 sed -i "/ flash_url=/c\readonly flash_url=\"$new_flash_url\"" "${dv}"
80 sed -i "/ ota_url=/c\readonly ota_url=\"$new_ota_url\"" "${dv}"
81 sed -i "/ ota_sha256=/c\readonly ota_sha256=\"$new_ota_sha256\"" "${dv}"
82 sed -i "/ security_patch=/c\readonly security_patch=\"$new_security_patch\"" "${dv}"
83 )
Chirayu Desai25445e72022-12-06 00:34:03 +053084 sleep 10s
Chirayu Desai9cfa05c2021-11-26 00:17:23 +053085 done
86}
87
88### RUN PROGRAM ###
89
90main "${@}"
91
92
93##