blob: b62ea931338b32ae0274e17443abb5521e446fdf [file] [log] [blame]
Chirayu Desai3ccdcf42021-11-26 03:24:45 +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 Desai3ccdcf42021-11-26 03:24:45 +05307#
8# download:
9#
10# Download Pixel factory images and OTA updates from Google
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 '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 Desai3ccdcf42021-11-26 03:24:45 +053031
32readonly work_dir="${WORK_DIR:-/tmp/pixel}"
33
Chirayu Desaidd101d62022-03-01 23:38:44 +053034source "${vars_path}/pixels"
Chirayu Desai3ccdcf42021-11-26 03:24:45 +053035
36readonly device="${1}"
37source "${vars_path}/${device}"
38
39## HELP MESSAGE (USAGE INFO)
40# TODO
41
42### FUNCTIONS ###
43
44download_factory_image() {
45 local factory_dir="${work_dir}/${device}/${build_id}"
46 mkdir -p "${factory_dir}"
47 local output="${factory_dir}/$(basename ${image_url})"
48 curl --http1.1 -C - -L -o "${output}" "${image_url}"
49 echo "${image_sha256} ${output}" | sha256sum --check --status
50}
51
52download_ota_zip() {
53 local ota_dir="${work_dir}/${device}/${build_id}"
54 mkdir -p "${ota_dir}"
55 local output="${ota_dir}/$(basename ${ota_url})"
56 curl --http1.1 -C - -L -o "${output}" "${ota_url}"
57 echo "${ota_sha256} ${output}" | sha256sum --check --status
58}
59
60# error message
61# ARG1: error message for STDERR
62# ARG2: error status
63error_m() {
64 echo "ERROR: ${1:-'failed.'}" 1>&2
65 return "${2:-1}"
66}
67
68# print help message.
69help_message() {
70 echo "${help_message:-'No help available.'}"
71}
72
73main() {
74 download_factory_image
Chirayu Desaie23c6c82021-12-03 04:03:31 +053075 # Not all devices need OTA, most are supported in image_unpacker
76 if [[ -n ${needs_ota-} ]]; then
77 download_ota_zip
78 fi
Chirayu Desai3ccdcf42021-11-26 03:24:45 +053079}
80
81### RUN PROGRAM ###
82
83main "${@}"
84
85
86##