Created
April 21, 2021 10:18
-
-
Save ahwayakchih/995ef715352e9d56e74bddddeeaf5c9d to your computer and use it in GitHub Desktop.
Copy a single file or directory into BFS disk image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Simple script that mounts specified BFS disk image file to temporary directory, | |
# copies specified file there, unmounts the image and removes temporary directory. | |
# Usage: cp2bfs my-file-to-copy my-test-disk.bfs | |
MOUNTDIR= | |
FROM=$1 | |
BFSFILE=$2 | |
if [ -z "$BFSFILE" ] || [ ! -f "$BFSFILE" ] ; then | |
echo "BFS image file not specified" >&2 | |
exit 1 | |
fi | |
cleanup () { | |
if [ -z "$MOUNTDIR" ] || [ ! -d "$MOUNTDIR" ] ; then | |
return | |
fi | |
unmount "$MOUNTDIR" &>/dev/null || true | |
rm -rf "$MOUNTDIR" | |
} | |
MOUNTDIR=$(mktemp -d) | |
trap 'cleanup' EXIT INT TERM | |
mount "$BFSFILE" "$MOUNTDIR" || (echo "Could not mount '$BFSFILE', are you sure it's valid?" >&2 && exit 1) | |
cp -a "$FROM" "$MOUNTDIR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment