pixel: Add shell script to download images from Google
Change-Id: I23ea5c3e8de675bf48ae2be93b83f24f7025f5c3
This commit is contained in:
committed by
Michael Bestas
parent
cb6c647e31
commit
05b3a310ce
78
pixel/download.sh
Executable file
78
pixel/download.sh
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# download:
|
||||
#
|
||||
# Download Pixel factory images and OTA updates from Google
|
||||
#
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
### SET ###
|
||||
|
||||
# use bash strict mode
|
||||
set -euo pipefail
|
||||
|
||||
|
||||
### TRAPS ###
|
||||
|
||||
# trap signals for clean exit
|
||||
trap 'exit $?' EXIT
|
||||
trap 'error_m interrupted!' SIGINT
|
||||
|
||||
### CONSTANTS ###
|
||||
readonly script_path="$(cd "$(dirname "$0")";pwd -P)"
|
||||
readonly vars_path="${script_path}/../vars/"
|
||||
|
||||
readonly work_dir="${WORK_DIR:-/tmp/pixel}"
|
||||
|
||||
source "${vars_path}/devices"
|
||||
|
||||
readonly device="${1}"
|
||||
source "${vars_path}/${device}"
|
||||
|
||||
## HELP MESSAGE (USAGE INFO)
|
||||
# TODO
|
||||
|
||||
### FUNCTIONS ###
|
||||
|
||||
download_factory_image() {
|
||||
local factory_dir="${work_dir}/${device}/${build_id}"
|
||||
mkdir -p "${factory_dir}"
|
||||
local output="${factory_dir}/$(basename ${image_url})"
|
||||
curl --http1.1 -C - -L -o "${output}" "${image_url}"
|
||||
echo "${image_sha256} ${output}" | sha256sum --check --status
|
||||
}
|
||||
|
||||
download_ota_zip() {
|
||||
local ota_dir="${work_dir}/${device}/${build_id}"
|
||||
mkdir -p "${ota_dir}"
|
||||
local output="${ota_dir}/$(basename ${ota_url})"
|
||||
curl --http1.1 -C - -L -o "${output}" "${ota_url}"
|
||||
echo "${ota_sha256} ${output}" | sha256sum --check --status
|
||||
}
|
||||
|
||||
# error message
|
||||
# ARG1: error message for STDERR
|
||||
# ARG2: error status
|
||||
error_m() {
|
||||
echo "ERROR: ${1:-'failed.'}" 1>&2
|
||||
return "${2:-1}"
|
||||
}
|
||||
|
||||
# print help message.
|
||||
help_message() {
|
||||
echo "${help_message:-'No help available.'}"
|
||||
}
|
||||
|
||||
main() {
|
||||
download_factory_image
|
||||
download_ota_zip
|
||||
}
|
||||
|
||||
### RUN PROGRAM ###
|
||||
|
||||
main "${@}"
|
||||
|
||||
|
||||
##
|
||||
Reference in New Issue
Block a user