libtpms/tests/base64decode.sh
Stefan Berger 1fe484ce67 scripting: Use #!/usr/bin/env bash rather than /bin/bash
On some systems /bin/bash does not exists but is somewhere else and can
be invoked with /usr/bin/env.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-10 16:33:34 +00:00

41 lines
709 B
Bash
Executable File

#!/usr/bin/env bash
input=$(mktemp)
binary=$(mktemp)
trap "rm -f $input $binary" EXIT
if [ -z "$(type -p seq)" ]; then
function seq()
{
for ((i = $1; i < $2; i++)); do
echo $i
done
}
fi
function do_base64()
{
if [ -n "$(type -p base64)" ]; then
base64 $1
elif [ -n "$(type -p uuencode)" ]; then
uuencode -m $1 data | sed 1d | sed '$d'
else
echo "No tool found for base64 encoding." >&2
exit 1
fi
}
for i in $(seq 1 1024) 2048 10240;
do
echo $i
dd if=/dev/urandom of=$binary bs=1 count=$i &>/dev/null
echo "-----BEGIN INITSTATE-----" > $input
do_base64 $binary >> $input
echo "-----END INITSTATE-----" >> $input
./base64decode $input $binary
if [ $? -ne 0 ]; then
exit 1
fi
done