blob: 6dea7680ca72f10eee39372d31549911461eafa5 [file] [log] [blame]
Chirayu Desaie0416982021-11-26 05:20:54 +05301#!/bin/bash
Chirayu Desaicc931dc2022-07-08 19:43:32 +05302
Michael Bestasd137feb2023-12-01 02:26:28 +02003# SPDX-FileCopyrightText: 2022-2023 The Calyx Institute
Chirayu Desaicc931dc2022-07-08 19:43:32 +05304#
5# SPDX-License-Identifier: Apache-2.0
6
Chirayu Desaie0416982021-11-26 05:20:54 +05307#
Michael Bestasd137feb2023-12-01 02:26:28 +02008# extract-factory-image:
Chirayu Desaie0416982021-11-26 05:20:54 +05309#
10# Extract Pixel factory images
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 Desaie0416982021-11-26 05:20:54 +053031
32readonly work_dir="${WORK_DIR:-/tmp/pixel}"
33
Chirayu Desaidd101d62022-03-01 23:38:44 +053034source "${vars_path}/pixels"
Chirayu Desaie0416982021-11-26 05:20:54 +053035
36readonly device="${1}"
37source "${vars_path}/${device}"
38
39## HELP MESSAGE (USAGE INFO)
40# TODO
41
42### FUNCTIONS ###
43
44extract_factory_image() {
45 local factory_dir="${work_dir}/${device}/${build_id}/factory"
Chirayu Desai69f1f3f2023-03-16 02:58:41 +053046 if [[ -d "${factory_dir}" ]]; then
47 echo "Skipping factory image extraction, ${factory_dir} already exists"
48 exit
49 fi
Chirayu Desaie0416982021-11-26 05:20:54 +053050 mkdir -p "${factory_dir}"
51 local factory_zip="${work_dir}/${device}/${build_id}/$(basename ${image_url})"
52 echo "${image_sha256} ${factory_zip}" | sha256sum --check --status
53 pushd "${factory_dir}"
54 unzip -o "${factory_zip}"
55 pushd ${device}-${build_id,,}
Michael Bestasd137feb2023-12-01 02:26:28 +020056 unzip -o "image-${device}-${build_id,,}.zip"
Chirayu Desaie0416982021-11-26 05:20:54 +053057 popd
58 popd
59}
60
61# error message
62# ARG1: error message for STDERR
63# ARG2: error status
64error_m() {
65 echo "ERROR: ${1:-'failed.'}" 1>&2
66 return "${2:-1}"
67}
68
69# print help message.
70help_message() {
71 echo "${help_message:-'No help available.'}"
72}
73
74main() {
75 extract_factory_image
76}
77
78### RUN PROGRAM ###
79
80main "${@}"
81
82
83##