@@ -14,6 +14,9 @@ output_file=$6
1414demo_type=$7
1515image_version=$8
1616onie_image_part_size=$9
17+ onie_installer_payload=${10}
18+ cert_file=${11}
19+ key_file=${12}
1720
1821shift 9
1922
@@ -61,6 +64,13 @@ tmp_dir=
6164clean_up ()
6265{
6366 rm -rf $tmp_dir
67+ if [ -n " $2 " ]; then
68+ rm -rf " $2 "
69+ if [ -n " $3 " ]; then
70+ rm -rf " $3 "
71+ fi
72+ echo " Error: CMS signature not created - exiting without signing"
73+ fi
6474 exit $1
6575}
6676
@@ -100,7 +110,7 @@ sed -i -e "s/%%DEMO_TYPE%%/$demo_type/g" \
100110 -e " s@%%OUTPUT_RAW_IMAGE%%@$output_raw_image @" \
101111 $tmp_installdir /install.sh || clean_up 1
102112echo -n " ."
103- cp -r $* $tmp_installdir || clean_up 1
113+ cp -r $onie_installer_payload $tmp_installdir || clean_up 1
104114echo -n " ."
105115[ -r " $platform_conf " ] && {
106116 cp $platform_conf $tmp_installdir || clean_up 1
@@ -130,7 +140,50 @@ cp $installer_dir/sharch_body.sh $output_file || {
130140# Replace variables in the sharch template
131141sed -i -e " s/%%IMAGE_SHA1%%/$sha1 /" $output_file
132142echo -n " ."
143+ tar_size=" $( wc -c < " ${sharch} " ) "
133144cat $sharch >> $output_file
145+ sed -i -e " s|%%PAYLOAD_IMAGE_SIZE%%|${tar_size} |" ${output_file}
146+ echo " secure upgrade flags: SECURE_UPGRADE_MODE = $SECURE_UPGRADE_MODE , \
147+ SECURE_UPGRADE_DEV_SIGNING_KEY = $SECURE_UPGRADE_DEV_SIGNING_KEY , SECURE_UPGRADE_DEV_SIGNING_CERT = $SECURE_UPGRADE_DEV_SIGNING_CERT "
148+
149+ if [ " $SECURE_UPGRADE_MODE " = " dev" -o " $SECURE_UPGRADE_MODE " = " prod" ]; then
150+ CMS_SIG=" ${tmp_dir} /signature.sig"
151+ DIR=" $( dirname " $0 " ) "
152+ scripts_dir=" ${DIR} /scripts"
153+ echo " $0 $SECURE_UPGRADE_MODE signing - creating CMS signature for ${output_file} . Output file ${CMS_SIG} "
154+
155+ if [ " $SECURE_UPGRADE_MODE " = " dev" ]; then
156+ echo " $0 dev keyfile location: ${key_file} ."
157+ . ${scripts_dir} /sign_image_dev.sh || {
158+ echo " dev sign script ${scripts_dir} /sign_image_dev.sh not found"
159+ clean_up 1 ${output_file}
160+ }
161+ sign_image_dev ${cert_file} ${key_file} ${output_file} ${CMS_SIG} || {
162+ echo " CMS sign error $? "
163+ clean_up 1 ${CMS_SIG} ${output_file}
164+ }
165+ else # "$SECURE_UPGRADE_MODE" has to be equal to "prod"
166+ . ${scripts_dir} /sign_image_${machine} .sh || {
167+ echo " prod sign script ${scripts_dir} /sign_image_${machine} .sh not found"
168+ clean_up 1 ${output_file}
169+ }
170+ sign_image_prod ${output_file} ${CMS_SIG} ${SECURE_UPGRADE_MODE} || {
171+ echo " CMS sign error $? "
172+ clean_up 1 ${CMS_SIG} ${output_file}
173+ }
174+ fi
175+
176+ [ -f " $CMS_SIG " ] || {
177+ echo " Error: CMS signature not created - exiting without signing"
178+ clean_up 1
179+ }
180+ # append signature to binary
181+ cat ${CMS_SIG} >> ${output_file}
182+ sudo rm -rf ${CMS_SIG}
183+ elif [ " $SECURE_UPGRADE_MODE " -ne " no_sign" ]; then
184+ echo " SECURE_UPGRADE_MODE not defined or defined as $SECURE_UPGRADE_MODE - build without signing"
185+ fi
186+
134187rm -rf $tmp_dir
135188echo " Done."
136189
0 commit comments