Skip to content

Commit

Permalink
feat: prepare for more then single device
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
  • Loading branch information
glimchb committed Jun 12, 2024
1 parent 54157bc commit abb2d12
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
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

0 comments on commit abb2d12

Please sign in to comment.