Skip to content
Snippets Groups Projects
Commit ab61f20e authored by Nico Dechesne (Stage)'s avatar Nico Dechesne (Stage)
Browse files

signlk: remove bashisms


The script can now work with bash and POSIX shell (dash).

Signed-off-by: default avatarNicolas Dechesne <nicolas.dechesne@linaro.org>
parent 55e86bb4
No related branches found
No related tags found
No related merge requests found
#!/bin/sh
################################################################################
# Copyright (c) 2016, The Linux Foundation. All rights reserved. #
# #
......@@ -75,7 +76,7 @@ case $i in
esac
done
if [ "$INFILE" == "" ]; then
if [ "$INFILE" = "" ]; then
echo "signlk -i=input_file_name [-o=output_file_name]"
exit 2
fi
......@@ -83,7 +84,7 @@ fi
INFILE_filename=$(echo $INFILE | rev | cut -f 2- -d '.' | rev)
INFILE_extension=$(echo $INFILE | rev | cut -f 1 -d '.' | rev)
if [ "$INFILE_extension" == "" ]; then
if [ "$INFILE_extension" = "" ]; then
echo "input file must be an elf or mbn file"
exit 3
fi
......@@ -93,7 +94,7 @@ if [ "$INFILE_extension" != "elf" ] && [ "$INFILE_extension" != "mbn" ] && [ "$
exit 4
fi
if [ "$OUTFILE" == "" ]; then
if [ "$OUTFILE" = "" ]; then
OUTFILE=$INFILE_filename"_signed.mbn"
fi
......@@ -159,25 +160,26 @@ openssl x509 -in $tmpdir/atte_cert.PEM -inform PEM -outform DER -out $ATT 2>/dev
openssl pkeyutl -sign -inkey $tmpdir/atte_key.PEM -in $CODE -out $SIG 2>/dev/null
data_file_size=$( cut -d ' ' -f 1 <<< $(du -b $DATA | tr '[:blank:]' ' '))
code_file_size=$( cut -d ' ' -f 1 <<< $(du -b $CODE | tr '[:blank:]' ' ') )
sig_file_size=$( cut -d ' ' -f 1 <<< $(du -b $SIG | tr '[:blank:]' ' ') )
atte_file_size=$( cut -d ' ' -f 1 <<< $(du -b $ATT | tr '[:blank:]' ' ') )
root_file_size=$( cut -d ' ' -f 1 <<< $(du -b $ROOT | tr '[:blank:]' ' ') )
hash_seg_file_size=$( cut -d ' ' -f 1 <<< $(du -b $tmpdir/hashSeg | tr '[:blank:]' ' ') )
data_file_size=$(du -b $DATA | tr '[:blank:]' ' ' | cut -d ' ' -f 1)
code_file_size=$(du -b $CODE | tr '[:blank:]' ' ' | cut -d ' ' -f 1)
sig_file_size=$(du -b $SIG | tr '[:blank:]' ' ' | cut -d ' ' -f 1)
atte_file_size=$(du -b $ATT | tr '[:blank:]' ' ' | cut -d ' ' -f 1)
root_file_size=$(du -b $ROOT | tr '[:blank:]' ' ' | cut -d ' ' -f 1)
hash_seg_file_size=$(du -b $tmpdir/hashSeg | tr '[:blank:]' ' ' | cut -d ' ' -f 1)
hash_seg_offset=4096
mi_hdr_size=40
dd if=$TMPOUTFILE of=$OUTFILE 2>/dev/null
dd if=$DATA of=$OUTFILE bs=1 count=$data_file_size seek=$[hash_seg_offset+$mi_hdr_size] 2>/dev/null
dd if=$SIG of=$OUTFILE count=$sig_file_size bs=1 seek=$[$hash_seg_offset+$mi_hdr_size+$data_file_size] 2>/dev/null
dd if=$ATT of=$OUTFILE count=$atte_file_size bs=1 seek=$[$hash_seg_offset+$mi_hdr_size+$data_file_size+$sig_file_size] 2>/dev/null
dd if=$ROOT of=$OUTFILE count=$root_file_size bs=1 seek=$[$hash_seg_offset+$mi_hdr_size+$data_file_size+$sig_file_size+$atte_file_size] 2>/dev/null
dd if=$tmpdir/hashSeg of=$OUTFILE bs=1 skip=$[$mi_hdr_size+$data_file_size+$sig_file_size+$atte_file_size+$root_file_size] seek=$[$hash_seg_offset+$mi_hdr_size+$data_file_size+$sig_file_size+$atte_file_size+$root_file_size] 2>/dev/null
dd if=$TMPOUTFILE of=$OUTFILE bs=1 skip=$[$hash_seg_offset+$hash_seg_file_size] seek=$[$hash_seg_offset+$hash_seg_file_size] 2>/dev/null
if ! [[ $- =~ x ]]; then
rm -rf $tmpdir
dd if=$DATA of=$OUTFILE bs=1 count=$data_file_size seek=$((hash_seg_offset+$mi_hdr_size)) 2>/dev/null
dd if=$SIG of=$OUTFILE count=$sig_file_size bs=1 seek=$(($hash_seg_offset+$mi_hdr_size+$data_file_size)) 2>/dev/null
dd if=$ATT of=$OUTFILE count=$atte_file_size bs=1 seek=$(($hash_seg_offset+$mi_hdr_size+$data_file_size+$sig_file_size)) 2>/dev/null
dd if=$ROOT of=$OUTFILE count=$root_file_size bs=1 seek=$(($hash_seg_offset+$mi_hdr_size+$data_file_size+$sig_file_size+$atte_file_size)) 2>/dev/null
dd if=$tmpdir/hashSeg of=$OUTFILE bs=1 skip=$(($mi_hdr_size+$data_file_size+$sig_file_size+$atte_file_size+$root_file_size)) seek=$(($hash_seg_offset+$mi_hdr_size+$data_file_size+$sig_file_size+$atte_file_size+$root_file_size)) 2>/dev/null
dd if=$TMPOUTFILE of=$OUTFILE bs=1 skip=$(($hash_seg_offset+$hash_seg_file_size)) seek=$(($hash_seg_offset+$hash_seg_file_size)) 2>/dev/null
# no cleanup in debug mode
if ! echo "$-" | grep -q 'x'; then
rm -rf $tmpdir
fi
echo done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment