Skip to content

Instantly share code, notes, and snippets.

@ahwayakchih
Created April 21, 2021 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahwayakchih/995ef715352e9d56e74bddddeeaf5c9d to your computer and use it in GitHub Desktop.
Save ahwayakchih/995ef715352e9d56e74bddddeeaf5c9d to your computer and use it in GitHub Desktop.
Copy a single file or directory into BFS disk image
#!/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