Commit 18569642 authored by Claude's avatar Claude 🌴

Merge branch 'QA' into 'master'

Improve SSH configuration

See merge request raspbian/prepare-raspbian-sd!87
parents ecadb0a7 2981f312
Pipeline #8159 passed with stage
in 18 seconds
......@@ -103,56 +103,8 @@ Optionally you can customize **Prepare Raspbian SD**.
You have two options to customize default download directory, witch is location where images will be store.
To be able to use `--configure` properly, you must choose how and what you want to configure.
See [prepare-raspbian-sd-config.md](prepare-raspbian-sd-config.md) for more details.
```bash
_DATA_="$( xdg-user-dir DOCUMENTS )/raspbian-images"
_DOWNLOAD_="${_DATA_}/download"
_BACKUP_="${_DATA_}/backups"
# Create directories if needed
mkdir -vp "${_DOWNLOAD_}" "${_BACKUP_}"
# Configuration (recommended)
prepare-raspbian-sd-config RASPBIAN_DEFAULT_BACKUP_DIRECTORY "${_BACKUP_}"
prepare-raspbian-sd-config RASPBIAN_DEFAULT_DOWNLOAD_IMAGE_DIRECTORY "${_DOWNLOAD_}"
prepare-raspbian-sd-config SSH_AUTHORIZED_KEYS "$( cat ~/.ssh/id_rsa.pub )"
# Configuration (optional - if used ensure value is what you want)
prepare-raspbian-sd-config DEFAULT_SD_DEV_NAME 'mmcblk0'
prepare-raspbian-sd-config GPU_MEM '16'
prepare-raspbian-sd-config RASPBIAN_DEFAULT_IMG "${_DOWNLOAD_}/2019-07-10-raspbian-buster-lite.img"
```
Or you can export required variables (using `~/.bashrc` or custom script):
```bash
export RASPBIAN_SSH_CONFIG='/path/to/your-ssh-need.config'
```
* If `RASPBIAN_DEFAULT_BACKUP_DIRECTORY` not define, commands your `Documents` directory.
* If `RASPBIAN_DEFAULT_DOWNLOAD_IMAGE_DIRECTORY` not define, commands use your `Download` directory.
### Summary
| Variable name | Usage description | Typical values |
|---------------------------------------------|-------------------------------------------|----------------|
| `DEFAULT_SD_DEV_NAME` | Optional, use to write on SD card. | `mmcblk0` |
| `GPU_MEM` | Optional, use by `--configure`. Configure memory split, if not set or if set to 0 memory split configuration is skipped | `16` |
| `RASPBIAN_DEFAULT_BACKUP_DIRECTORY` | Required to be able to use `--full-clone`. Variable must contain full path of an existing directory where your SD backups will be stored. | `/home/username/Documents/` |
| `RASPBIAN_DEFAULT_DOWNLOAD_IMAGE_DIRECTORY` | Nice to have to use `--download` option of **prepare-raspbian-sd-download-image** and to use `--put-last-image` option of **prepare-raspbian-sd**. | `/home/username/Documents/raspbian-images` |
| `RASPBIAN_DEFAULT_IMG` | Required to be able to use `--put-default-image`. Variable must contain full path to your `raspbian-stretch-lite.img` local file. | `/path/to/2018-10-09-raspbian-stretch-lite.img` |
| `RASPBIAN_PI_GROUP_ID` | Optional, default value 1000 | `1000` |
| `RASPBIAN_PI_USER_ID` | Optional, default value 1000 | `1000` |
| `SSH_AUTHORIZED_KEYS` | Required to be able to use `--configure`. Variable must contain content of `/home/pi/.ssh/authorized_keys` you want to add. | `"$( cat ~/.ssh/id_rsa.pub )"` |
Deprecated configuration entry point:
| Variable name | Usage description |
|---------------------------------------------|---------------------------------------------------|
| `RASPBIAN_SSH_CONFIG` | Is deprecated. Use `SSH_AUTHORIZED_KEYS` instead. |
See [prepare-raspbian-sd-config.md](prepare-raspbian-sd-config.md) for more details.
## Usage
......
......@@ -12,3 +12,15 @@ function print_variable {
echo '<<< not define >>>'
fi
}
# param variable is mandatory
function test_P {
local value=
if ! value="$( P "$@" )" ; then
# shellcheck disable=SC2154
echofatal "Value required for '${param}'"
usage >&2
return 100
fi
echo "${value}"
}
......@@ -14,11 +14,16 @@ declare -gra _PREPARE_RASPBIAN_CONFIG_VARS_=(
'RASPBIAN_PI_GROUP_ID:INTEGER'
'RASPBIAN_PI_USER_ID:INTEGER'
'SSH_AUTHORIZED_KEYS:STRING'
'SSH_CONFIGURE:BOOLEAN'
'SSH_ENABLE:BOOLEAN'
)
function prepare_raspbian_get_config_file {
echo "${_PREPARE_RASPBIAN_CONFIG_FILE_}"
}
function prepare_raspbian_show_list {
local entry=
for entry in "${_PREPARE_RASPBIAN_CONFIG_VARS_[@]}" ; do
cut -d ':' -f1 <<<"${entry}"
done
......@@ -45,8 +50,8 @@ function prepare_raspbian_show_list_json {
function prepare_raspbian_get_type {
local -r var_name="$1"
local entry=
local entry=
for entry in "${_PREPARE_RASPBIAN_CONFIG_VARS_[@]}" ; do
if [ "${entry:0:${#var_name} + 1}" = "${var_name}:" ] ; then
cut -d ':' -f2 <<<"${entry}"
......@@ -57,13 +62,13 @@ function prepare_raspbian_get_type {
function prepare_raspbian_show_list_all {
ensure_raspbian_config_ready
jq -S '.' "${_PREPARE_RASPBIAN_CONFIG_FILE_}" || exit 1
jq -S '.' "$( prepare_raspbian_get_config_file )" || return $?
}
function prepare_raspbian_config_is_var_name_valide {
local -r var_name="$1"
local var=
local var=
while read -r var ; do
if [ "${var_name}" = "${var}" ] ; then
return 0
......@@ -86,13 +91,16 @@ function prepare_raspbian_config_check_var_name {
function ensure_raspbian_config_ready {
if [ ! -d "${__PREPARE_RASPBIAN_CONFIG_DIR__}" ] ; then
mkdir -vp "${__PREPARE_RASPBIAN_CONFIG_DIR__}"
mkdir -vp "${__PREPARE_RASPBIAN_CONFIG_DIR__}" || true
fi
exit_if_directory_not_exists "${__PREPARE_RASPBIAN_CONFIG_DIR__}"
touch "${_PREPARE_RASPBIAN_CONFIG_FILE_}"
exit_if_file_not_exists "${_PREPARE_RASPBIAN_CONFIG_FILE_}"
local config_file=
config_file="$( prepare_raspbian_get_config_file )" || return $?
touch "${config_file}" || true
exit_if_file_not_exists "${config_file}"
}
function prepare_raspbian_initialise_if_needed {
......@@ -102,17 +110,18 @@ function prepare_raspbian_initialise_if_needed {
ensure_raspbian_config_ready
if ! is_variable_define_and_not_empty_safe "${var_name}" ; then
local value=
local json_config_for_var=
json_config_for_var="$(
jq ".[\"${var_name}\"]" "$( prepare_raspbian_get_config_file )"
)" || return $?
json_config_for_var="$( jq ".[\"${var_name}\"]" <"${_PREPARE_RASPBIAN_CONFIG_FILE_}" )" || exit 1
local value=
if [ "${json_config_for_var}" != 'null' ] ; then
value="$( jq -r '.value' <<<"${json_config_for_var}" )" || exit 1
value="$( jq -r '.value' <<<"${json_config_for_var}" )" || return $?
if [ "${value}" = 'null' ] ; then
local link=
link="$( jq -r '.link' <<<"${json_config_for_var}" )" || exit 1
link="$( jq -r '.link' <<<"${json_config_for_var}" )" || return $?
if [ "${link}" != 'null' ] ; then
if [ -f "${link}" ] ; then
......@@ -149,21 +158,21 @@ function _prepare_raspbian_config_json_set_ {
local -r var_name="$1"
local -r var_name_type="$2"
local -r var_value="$3"
local config=
ensure_raspbian_config_ready
local config=
config="$(
jq -S ". | del(.[\"${var_name}\"] | .value) | del(.[\"${var_name}\"] | .link )" \
"${_PREPARE_RASPBIAN_CONFIG_FILE_}"
)" || exit 1
"$( prepare_raspbian_get_config_file )"
)" || return $?
if [ -n "${var_value}" ] ; then
local var_value_json=
if [ "${var_name_type}" != 'link' ] ; then
local var_value_expected_type=
var_value_expected_type="$( prepare_raspbian_get_type "${var_name}" )" || exit 1
var_value_expected_type="$( prepare_raspbian_get_type "${var_name}" )" || return $?
case "${var_value_expected_type}" in
'BOOLEAN'|'INTEGER')
......@@ -181,12 +190,12 @@ function _prepare_raspbian_config_json_set_ {
config="$(
jq -S ". |
(.[\"${var_name}\"] | .${var_name_type} ) |= ${var_value_json}" <<<"${config}"
)" || exit 1
)" || return $?
echo "${config}" >"${_PREPARE_RASPBIAN_CONFIG_FILE_}" || exit 1
echo "${config}" >"$( prepare_raspbian_get_config_file )" || return $?
echoinfo "'${var_name}'.'${var_name_type}' is set : '${var_value}'" >&2
else
echo "${config}" >"${_PREPARE_RASPBIAN_CONFIG_FILE_}" || exit 1
echo "${config}" >"$( prepare_raspbian_get_config_file )" || return $?
echoinfo "'${var_name}' is removed." >&2
fi
}
......@@ -195,7 +204,7 @@ function _prepare_raspbian_config_set_value_ {
local -r var_name="$1"
local -r var_value="$2"
_prepare_raspbian_config_json_set_ "${var_name}" 'value' "${var_value}"
_prepare_raspbian_config_json_set_ "${var_name}" 'value' "${var_value}" || return $?
}
function prepare_raspbian_check_and_set_value_string {
......@@ -237,7 +246,7 @@ function _prepare_raspbian_config_set_link_ {
ensure_raspbian_config_ready
_prepare_raspbian_config_json_set_ "${var_name}" 'link' "${var_link}"
_prepare_raspbian_config_json_set_ "${var_name}" 'link' "${var_link}" || return $?
}
function prepare_raspbian_check_and_set_value_link {
......@@ -245,7 +254,7 @@ function prepare_raspbian_check_and_set_value_link {
local -r var_link="$2"
if prepare_raspbian_config_check_var_name "${var_name}" ; then
_prepare_raspbian_config_set_link_ "${var_name}" "${var_link}"
_prepare_raspbian_config_set_link_ "${var_name}" "${var_link}" || return $?
else
return 1
fi
......@@ -256,10 +265,10 @@ function prepare_raspbian_check_and_set_value {
local -r var_name="$2"
local -r var_value="$3"
prepare_raspbian_config_check_var_name "${var_name}" || exit 1
prepare_raspbian_config_check_var_name "${var_name}" || return $?
local var_value_expected_type=
var_value_expected_type="$( prepare_raspbian_get_type "${var_name}" )" || exit 1
var_value_expected_type="$( prepare_raspbian_get_type "${var_name}" )" || return $?
if [ -z "${var_value_expected_type}" ] ; then
echofatal "Don't know how to handle '${var_name}'."
......@@ -315,7 +324,7 @@ function prepare_raspbian_check_and_get_value {
if is_variable_define_and_not_empty_safe "${var_name}" ; then
local -r value="${!var_name}"
jq "{ \"${var_name}\" : \"${value}\" }" <<<'{}' || exit 1
jq "{ \"${var_name}\" : \"${value}\" }" <<<'{}' || return $?
return 0
else
echo "${var_name} not define." >&2
......
......@@ -21,18 +21,17 @@ usr/bin/raspi-config
'
function customize_sd {
local boot_partition_home=
local rootfs_partition_home=
# Ensure boot partition is has expected
boot_partition_home="$( get_partition_home_by_label_with_timeout 'boot' )" || exit 1
local boot_partition_home=
boot_partition_home="$( get_partition_home_by_label_with_timeout 'boot' )" || return $?
echoinfo "boot_partition_home=${boot_partition_home}"
# Ensure rootfs partition is has expected
rootfs_partition_home="$( get_partition_home_by_label_with_timeout 'rootfs' )" || exit 1
local rootfs_partition_home=
rootfs_partition_home="$( get_partition_home_by_label_with_timeout 'rootfs' )" || return $?
echoinfo "rootfs_partition_home=${rootfs_partition_home}"
verify_sd_content "${boot_partition_home}" "${rootfs_partition_home}"
verify_sd_content "${boot_partition_home}" "${rootfs_partition_home}" || return $?
# shellcheck disable=SC2154
if [ "${param_dry_run}" = 'false' ] ; then
......@@ -50,13 +49,13 @@ function customize_sd {
if [ -f "${ssh_file}" ] ; then
echoinfo "Umounting '${boot_partition_home}'"
if [ "${param_dry_run}" = 'false' ] ; then
sudo umount "${boot_partition_home}" || exit 1
sudo umount "${boot_partition_home}" || return $?
echookay "${boot_partition_home} umounted."
fi
echoinfo "Umounting '${rootfs_partition_home}'"
if [ "${param_dry_run}" = 'false' ] ; then
sudo umount "${rootfs_partition_home}" || exit 1
sudo umount "${rootfs_partition_home}" || return $?
echookay "${rootfs_partition_home} umounted."
fi
else
......@@ -72,14 +71,20 @@ function customize_enable_ssh {
exit 1
fi
echoinfo 'Enable SSH.'
prepare_raspbian_initialise_if_needed SSH_ENABLE ''
local -r ssh_file="${boot_partition_home}/ssh"
if [ "${SSH_ENABLE:-}" = 'true' ] ; then
echoinfo 'Enable SSH.'
if [ -f "${ssh_file}" ] ; then
echoinfo "File '${ssh_file}' already exists."
local -r ssh_file="${boot_partition_home}/ssh"
if [ -f "${ssh_file}" ] ; then
echoinfo "File '${ssh_file}' already exists."
else
touch "${ssh_file}" || return $?
fi
else
touch "${ssh_file}"
echoinfo 'Skip SSH enable'
fi
}
......@@ -135,7 +140,7 @@ function customize_pi_user {
fi
# Create bcm workspace directory (TODO: should be optional)
if [ "${BCM_WORKSPACE}" != 'false' ] ; then
if [ "${BCM_WORKSPACE:-}" != 'false' ] ; then
local -r bcm_workspace_location="${home_pi}/.bcm-workspace"
if [ -d "${bcm_workspace_location}" ] ; then
......@@ -143,50 +148,56 @@ function customize_pi_user {
else
sudo mkdir -v "${bcm_workspace_location}"
# Set user right to 'pi' user and 'pi' group
sudo chown "${RASPBIAN_PI_USER_ID}:${RASPBIAN_PI_GROUP_ID}" "${bcm_workspace_location}" || exit 1
sudo chown "${RASPBIAN_PI_USER_ID}:${RASPBIAN_PI_GROUP_ID}" "${bcm_workspace_location}" || return $?
fi
else
echookay "Skip bcm-workspace. BCM_WORKSPACE: ${BCM_WORKSPACE}"
echookay "Skip bcm-workspace. BCM_WORKSPACE='${BCM_WORKSPACE:-}'"
fi
# Configure ssh (TODO: should be optional)
local -r ssh_folder="${home_pi}/.ssh"
# Configure ssh
prepare_raspbian_initialise_if_needed SSH_CONFIGURE ''
if [ -d "${ssh_folder}" ] ; then
echoinfo "Folder '${ssh_folder}' already exists."
else
sudo mkdir -v "${ssh_folder}"
# Set user right to 'pi' user and 'pi' group
sudo chown "${RASPBIAN_PI_USER_ID}:${RASPBIAN_PI_GROUP_ID}" "${ssh_folder}" || exit 1
sudo chmod 700 "${ssh_folder}" || exit 1
fi
if [ "${SSH_CONFIGURE:-}" = 'true' ] ; then
local -r ssh_folder="${home_pi}/.ssh"
prepare_raspbian_initialise_if_needed SSH_AUTHORIZED_KEYS ''
if [ -d "${ssh_folder}" ] ; then
echoinfo "Folder '${ssh_folder}' already exists."
else
sudo mkdir -v "${ssh_folder}"
# Set user right to 'pi' user and 'pi' group
sudo chown "${RASPBIAN_PI_USER_ID}:${RASPBIAN_PI_GROUP_ID}" "${ssh_folder}" || return $?
sudo chmod 700 "${ssh_folder}" || return $?
fi
if ! is_variable_define_and_not_empty_safe 'SSH_AUTHORIZED_KEYS' ; then
echowarn 'SSH_AUTHORIZED_KEYS not define (or empty) - you can fix this in file define by RASPBIAN_SSH_CONFIG'
prepare_raspbian_initialise_if_needed SSH_AUTHORIZED_KEYS ''
if is_variable_define_and_not_empty_safe 'RASPBIAN_SSH_CONFIG' ; then
echoerror "Check content of '${RASPBIAN_SSH_CONFIG}'"
fi
else
if sudo [ -f "${ssh_folder}/authorized_keys" ] ; then
echowarn "File '${ssh_folder}/authorized_keys' already exists (nothing will be changed)."
if ! is_variable_define_and_not_empty_safe 'SSH_AUTHORIZED_KEYS' ; then
echowarn 'SSH_AUTHORIZED_KEYS not define (or empty) - you can fix this in file define by RASPBIAN_SSH_CONFIG'
if is_variable_define_and_not_empty_safe 'RASPBIAN_SSH_CONFIG' ; then
echoerror "Check content of '${RASPBIAN_SSH_CONFIG}'"
fi
else
cat <<EOF | sudo tee "${ssh_folder}/authorized_keys"
if sudo [ -f "${ssh_folder}/authorized_keys" ] ; then
echowarn "File '${ssh_folder}/authorized_keys' already exists (nothing will be changed)."
else
cat <<EOF | sudo tee "${ssh_folder}/authorized_keys"
${SSH_AUTHORIZED_KEYS}
EOF
# Set user right to 'pi' user and 'pi' group
sudo chown "${RASPBIAN_PI_USER_ID}:${RASPBIAN_PI_GROUP_ID}" "${ssh_folder}/authorized_keys" || exit 1
echoinfo "File '${ssh_folder}/authorized_keys' created."
# Set user right to 'pi' user and 'pi' group
sudo chown "${RASPBIAN_PI_USER_ID}:${RASPBIAN_PI_GROUP_ID}" "${ssh_folder}/authorized_keys" || return $?
echoinfo "File '${ssh_folder}/authorized_keys' created."
fi
fi
else
echookay "Skip ~/.ssh configuration : SSH_CONFIGURE='${SSH_CONFIGURE:-}'"
fi
}
function get_partition_home_by_label_with_timeout {
local -r label="$1"
local partition_home=
local partition_home=
for count in $(seq 10 -1 1) ; do
if partition_home="$( get_partition_home_by_label "${label}" )" ; then
echo "${partition_home}"
......@@ -202,11 +213,11 @@ function get_partition_home_by_label_with_timeout {
function get_partition_home_by_label {
local -r label="$1"
local partition_home=
local partition_home=
partition_home="$(
mount --show-labels | grep "\\[${label}\\]" | cut -d ' ' -f3
)"
)" || return $?
if [ -z "${partition_home}" ] ; then
return 1
......
......@@ -9,9 +9,9 @@ PROJECT_HOME="$( dirname "$( dirname "$( realpath "${BASH_SOURCE[0]}" )" )" )"
declare -gr PROJECT_HOME
# shellcheck disable=SC1090
source "${PROJECT_HOME}/apis/bash-common-api/bash-common-api.sh" || exit 1
source "${PROJECT_HOME}/apis/bash-common-api/bash-common-api.sh" || exit $?
# shellcheck disable=SC1090
source "${PROJECT_HOME}/bin/api/prepare-raspbian-api.sh" || exit 1
source "${PROJECT_HOME}/bin/api/prepare-raspbian-api.sh" || exit $?
function usage {
cat <<EOF
......@@ -50,9 +50,9 @@ function getLastLibreElecUrl {
function prepare_libreelec_sd {
local -a params=()
local url=
url="$( getLastLibreElecUrl )" || exit 1
local url=
url="$( getLastLibreElecUrl )" || return $?
params+=(--unzip)
params+=(--url)
......@@ -60,7 +60,7 @@ function prepare_libreelec_sd {
echoinfo "URL: '${url}'"
if [ -z "${param_expected_img}" ] ; then
param_expected_img="$( basename "${url%.gz}" )" || exit 1
param_expected_img="$( basename "${url%.gz}" )" || return $?
fi
params+=(--expected-img)
......@@ -80,7 +80,7 @@ function prepare_libreelec_sd {
cat <<EOF >&2
"${PROJECT_HOME}/bin/prepare-raspbian-sd.sh" "${params[@]}"
EOF
"${PROJECT_HOME}/bin/prepare-raspbian-sd.sh" "${params[@]}" || exit 1
"${PROJECT_HOME}/bin/prepare-raspbian-sd.sh" "${params[@]}" || return $?
}
function main {
......@@ -100,15 +100,18 @@ function main {
;;
'--download-to')
param_download_to="$( P "$@" )" && shift
param_download_to="$( test_P "$@" )" || return $?
shift
;;
'--dev-name')
param_dev_name="$( P "$@" )" && shift
;;
param_dev_name="$( test_P "$@" )" || return $?
shift
;;
'--expected-img')
param_expected_img="$( P "$@" )" && shift
param_expected_img="$( test_P "$@" )" || return $?
shift
;;
*)
......@@ -119,8 +122,8 @@ function main {
esac
done
prepare_libreelec_sd
prepare_libreelec_sd || return $?
}
main "$@"
main "$@" || exit $?
......@@ -9,13 +9,15 @@ PROJECT_HOME="$( dirname "$( dirname "$( realpath "${BASH_SOURCE[0]}" )" )" )"
declare -gr PROJECT_HOME
# shellcheck disable=SC1090
source "${PROJECT_HOME}/apis/bash-common-api/bash-common-api.sh" || exit 1
source "${PROJECT_HOME}/apis/bash-common-api/bash-common-api.sh" || exit $?
# shellcheck disable=SC1090
source "${PROJECT_HOME}/bin/api/prepare-raspbian-config-json-api.sh" || exit 1
source "${PROJECT_HOME}/bin/api/prepare-raspbian-api.sh" || exit $?
# shellcheck disable=SC1090
source "${PROJECT_HOME}/bin/api/prepare-raspbian-config-json-api.sh" || exit $?
function usage {
cat <<EOF
Configure prepare-raspbian-sd.
Configure prepare-raspbian-sd, allow to modify '$( prepare_raspbian_get_config_file )'
Usage:
......@@ -63,7 +65,7 @@ function main {
if [ "$#" -eq 0 ] ; then
echofatal 'Parameters missing.'
usage >&2
exit 1
exit 100
fi
while [ "$#" -gt 0 ] ; do
......@@ -86,31 +88,39 @@ function main {
'--get')
test_action && action='--get'
param_name="$( P "$@" )" && shift
param_name="$( test_P "$@" )" || return $?
shift
;;
'--set')
test_action && action='--set'
param_name="$( P "$@" )" && shift
param_value="$( P "$@" )" && shift
param_name="$( test_P "$@" )" || return $?
shift
param_value="$( test_P "$@" )" || return $?
shift
;;
'--set-boolean'|'--set-integer')
test_action && action="${param}"
param_name="$( P "$@" )" && shift
param_value="$( P "$@" )" && shift
param_name="$( test_P "$@" )" || return $?
shift
param_value="$( test_P "$@" )" || return $?
shift
;;
'--set-link')
test_action && action='--set-link'
param_name="$( P "$@" )" && shift
param_value="$( P "$@" )" && shift
param_name="$( test_P "$@" )" || return $?
shift
param_value="$( test_P "$@" )" || return $?
shift
;;
*)
test_action && action='--set'
param_name="${param}"
param_value="$( P "$@" )" && shift
param_value="$( test_P "$@" )" || return $?
shift
;;
esac
done
......@@ -146,9 +156,9 @@ function main {
*)
echofatal "Internal error: action='${action}'"
exit 1
exit 100
;;
esac
}
main "$@"
main "$@" || exit $?
......@@ -9,11 +9,11 @@ PROJECT_HOME="$( dirname "$( dirname "$( realpath "${BASH_SOURCE[0]}" )" )" )"
declare -gr PROJECT_HOME
# shellcheck disable=SC1090
source "${PROJECT_HOME}/apis/bash-common-api/bash-common-api.sh" || exit 1
source "${PROJECT_HOME}/apis/bash-common-api/bash-common-api.sh" || exit $?
# shellcheck disable=SC1090
#source "${PROJECT_HOME}/bin/api/prepare-raspbian-api.sh" || exit 1
source "${PROJECT_HOME}/bin/api/prepare-raspbian-api.sh" || exit $?
# shellcheck disable=SC1090
source "${PROJECT_HOME}/bin/api/prepare-raspbian-config-json-api.sh" || exit 1
source "${PROJECT_HOME}/bin/api/prepare-raspbian-config-json-api.sh" || exit $?
declare -g ZIP_CHECKED='false'
......@@ -36,11 +36,13 @@ Actions
--url IMGURL Allow to set image file URL
Parameters
--arch ARCH Define machine hardware name (optional, but recommended).
If not set, or empty, use "Raspbian" as source,
if set use "Raspberry Pi OS" as source).
ARCH could be an empty string (for Raspbian), 'armhf', 'arm32'
(alias for 'armhf') or 'arm64'
--arch ARCH Define machine hardware name (optional). If not set, or empty, use "Raspbian"
as source, if set use "Raspberry Pi OS" as source). ARCH could be an empty string,
armhf or arm64.
--arch '' : Download last available version of raspbian
--arch armhf: Download last 32 bits version of "Raspberry Pi OS"
--arch arm32: Same as 'armhf'
--arch arm64: Download last 64 bits version of "Raspberry Pi OS"
(Parameter is ignored if --url is used)
--desktop, Same as --full (deprecated)
--expected-img IMG Expected image filename (without path) - if specified when using --url allow
......@@ -85,7 +87,8 @@ EOF
function build_last_version_url_for_raspbian {
local -r os_type="$1"
local lite=
local lite=
if [ "${os_type}" = 'lite' ] ; then
lite='lite_'
fi
......@@ -104,8 +107,8 @@ function build_last_version_url_for_raspbian {
function build_last_version_url_for_raspberry_pi_os {
local -r arch_type="$1"
local -r os_type="$2"
local identifier=
local identifier=
case "${os_type}" in
'lite')
identifier="lite_${arch_type}_latest";
......@@ -128,7 +131,7 @@ function build_last_version_url_for_raspberry_pi_os {
function download_if_needed {
if is_download_needed ; then
download
download || return $?
fi
}
......@@ -147,16 +150,16 @@ function is_download_needed {
}
function download {
wget "${LAST_VERSION_URL}" -O "${EXPECTED_ZIP_FILE}" || exit 1
wget "${LAST_VERSION_URL}" -O "${EXPECTED_ZIP_FILE}" || return $?
if [ -z "${param_url}" ] ; then
wget "${LAST_VERSION_URL}.sha256" -O "${EXPECTED_ZIP_FILE}.sha256" || exit 1
wget "${LAST_VERSION_URL}.sha256" -O "${EXPECTED_ZIP_FILE}.sha256" || return $?
fi
}
function unzip_if_needed {
if is_unzip_needed ; then
pushd "${param_download_image_directory}" >/dev/null || exit 1
pushd "${param_download_image_directory}" >/dev/null || return $?
if [ "${EXPECTED_ZIP_FILE%*.zip}.zip" = "${EXPECTED_ZIP_FILE}" ] ; then
cat <<EOF >&2
......@@ -167,11 +170,11 @@ EOF
cat <<EOF >&2
gzip --decompress --keep "${EXPECTED_ZIP_FILE}"
EOF
gzip --decompress --keep "${EXPECTED_ZIP_FILE}" || exit 1
gzip --decompress --keep "${EXPECTED_ZIP_FILE}" || return $?
else
echowarn "Don't kown how to unzip: '${EXPECTED_ZIP_FILE}'" >&2
fi
popd >/dev/null || exit 1
popd >/dev/null || return $?
fi
}
......@@ -200,18 +203,18 @@ function check_zip_once {
if [ ! -f "${EXPECTED_ZIP_FILE}.sha256" ] ; then
echofatal "Cannot find '${EXPECTED_ZIP_FILE}.sha256' - Cannot trust zip file."
exit 1
return 100
fi
echoinfo "Verifying checksum of '${EXPECTED_ZIP_FILE}'" >&2
local check256=
check256="$(
cd "$( dirname "${EXPECTED_ZIP_FILE}" )" || exit 1
cd "$( dirname "${EXPECTED_ZIP_FILE}" )" || exit $?
sha256sum "$( basename "${EXPECTED_ZIP_FILE}" )"
)"
)" || return $?
local verify256=
verify256="$( cat "${EXPECTED_ZIP_FILE}.sha256" )"
verify256="$( cat "${EXPECTED_ZIP_FILE}.sha256" )" || return $?
if [ "${check256}" != "${verify256}" ] ; then
echofatal "Wrong sha256sum !"
......@@ -219,7 +222,7 @@ function check_zip_once {
COMPUTED: ${check256}
EXPECTED: ${verify256}
EOF
exit 1
return 100
fi
ZIP_CHECKED='true'
......@@ -260,11 +263,13 @@ function main {
'-T'|'--download-to')
action='DOWNLOAD'
param_download_image_directory="$( P "$@" )" && shift
param_download_image_directory="$( test_P "$@" )" || return $?
shift
;;
'--arch')
param_arch="$( P "$@" )" && shift
param_arch="$( test_P "$@" )" || return $?
shift
;;
'--desktop'|'--full')
...