Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prepare for more then single device #367

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sztp-server/config/sztpd.running.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"image-verification": [
{
"hash-algorithm": "ietf-sztp-conveyed-info:sha-256",
"hash-value": "$BOOT_IMG_HASH_VAL"
"hash-value": "$MY_BOOT_IMG_HASH_VAL"
}
]
}
Expand All @@ -148,13 +148,13 @@
"pre-configuration-script": [
{
"name": "my-pre-configuration-script",
"script": "$PRE_SCRIPT_B64"
"script": "$MY_PRE_SCRIPT_B64"
}
],
"post-configuration-script": [
{
"name": "my-post-configuration-script",
"script": "$POST_SCRIPT_B64"
"script": "$MY_POST_SCRIPT_B64"
}
]
},
Expand All @@ -163,7 +163,7 @@
{
"name": "my-configuration",
"configuration-handling": "merge",
"config": "$CONFIG_B64"
"config": "$MY_CONFIG_B64"
}
]
},
Expand Down
32 changes: 22 additions & 10 deletions sztp-server/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -e -u -x

wait_curl () {
Expand All @@ -17,17 +17,29 @@ wait_curl () {

env

# shellcheck disable=SC2016
PRE_SCRIPT_B64=$(openssl enc -base64 -A -in /mnt/my-pre-configuration-script.sh) \
POST_SCRIPT_B64=$(openssl enc -base64 -A -in /mnt/my-post-configuration-script.sh) \
CONFIG_B64=$(openssl enc -base64 -A -in /mnt/my-configuration.xml) \
envsubst '$PRE_SCRIPT_B64,$POST_SCRIPT_B64,$CONFIG_B64' < /mnt/sztpd."${SZTPD_OPI_MODE}".json.template > /tmp/"${SZTPD_OPI_MODE}".json.configs
diff /mnt/sztpd."${SZTPD_OPI_MODE}".json.template /tmp/"${SZTPD_OPI_MODE}".json.configs || true
declare -a names

# files and configs

# shellcheck disable=SC2043
for vendor in my
do
names+=("${vendor^^}_BOOT_IMG_HASH_VAL" "${vendor^^}_CONFIG_B64")
export ${vendor^^}_BOOT_IMG_HASH_VAL="$(openssl dgst -sha256 -c ./media/${vendor,,}-boot-image.img | awk '{print $2}')"
export ${vendor^^}_CONFIG_B64="$(openssl enc -base64 -A -in /mnt/${vendor,,}-configuration.xml)"
for item in pre post
do
names+=("${vendor^^}_${item^^}_SCRIPT_B64")
export ${vendor^^}_${item^^}_SCRIPT_B64="$(openssl enc -base64 -A -in /mnt/${vendor,,}-${item,,}-configuration-script.sh)"
done
done

export "${names[@]}"
# shellcheck disable=SC2016
BOOT_IMG_HASH_VAL=$(openssl dgst -sha256 -c /media/my-boot-image.img | awk '{print $2}') \
envsubst '$BOOT_IMG_HASH_VAL' < /tmp/"${SZTPD_OPI_MODE}".json.configs > /tmp/"${SZTPD_OPI_MODE}".json.images
diff /tmp/"${SZTPD_OPI_MODE}".json.configs /tmp/"${SZTPD_OPI_MODE}".json.images || true
envsubst "$(printf '${%s} ' "${names[@]}")" < /mnt/sztpd."${SZTPD_OPI_MODE}".json.template > /tmp/"${SZTPD_OPI_MODE}".json.images

# check what changed
diff /mnt/sztpd."${SZTPD_OPI_MODE}".json.template /tmp/"${SZTPD_OPI_MODE}".json.images || true

# shellcheck disable=SC2016
SBI_PRI_KEY_B64=$(openssl enc -base64 -A -in /certs/private_key.der) \
Expand Down
Loading