scripts/shell/mksector.sh
2024-03-20 12:09:54 -05:00

39 lines
679 B
Bash
Executable file

#!/usr/bin/env bash
#
# Script for https://sectordisk.pw
# usage: ./mksector.sh in.txt out.dat
#
# vim -> :set nofixendofline
# or
# vim -b <file>
# :set noeol
# :wq
#
# in.txt should be 16x32 text (~543 bytes)
# out.dat should be a 512 byte sector
#
# SPDX-License-Identifier: MIT
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <input file> <output file>"
exit 1
fi
IN="$1"
OUT="$2"
if [[ "${IN}" == "${OUT}" ]]; then
echo "Input and output files should not be the same name"
exit 2
fi
# requires GNU sed
echo
echo "Processing ${IN} to ${OUT}"
cat "${IN}" | sed ':a;N;$!ba;s/\n//g' > "${OUT}"
_SZ=$(stat -c %B "${OUT}")
echo "Bytes: ${_SZ}"
echo
hexdump -Cv "${OUT}"