Skip to content

Commit

Permalink
Wrote a script that can take hexadecimal bytes from a file and write …
Browse files Browse the repository at this point in the history
…them to an output file and an sd card.
  • Loading branch information
JacobPease committed Nov 2, 2024
1 parent c197d4a commit 2a8e213
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions linux/sdcard/write-bytes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# This file writes a bunch of bytes to the flash card based on a text
# file input with bytes written in hexadecimal.

INPUTFILE=""
OUTPUTFILE=""

ARGS=()
while [ $OPTIND -le "$#" ] ; do
if getopts "hi:o:" arg ; then
case "${arg}" in
h) help
;;
i) INPUTFILE=${OPTARG}
;;
o) OUTPUTFILE=${OPTARG}
;;
esac
else
ARGS+=("${!OPTIND}")
((OPTIND++))
fi
done

SDCARD=${ARGS[0]}

if [ ! -e $INPUTFILE ] ; then
echo -e "Error: Input file $INPUTFILE does not exist."
exit 1
fi

if [ -e $OUTPUTFILE ] ; then
echo -e "Error: Output file $OUTPUTFILE already exists."
exit 1
fi

for word in $(cat "$INPUTFILE")
do
echo -en "\x$word" >> $OUTPUTFILE
done

dd if=$OUTPUTFILE of="$SDCARD"

0 comments on commit 2a8e213

Please sign in to comment.