Skip to content

Commit

Permalink
add stream-helper.sh script
Browse files Browse the repository at this point in the history
  • Loading branch information
embetrix committed Jan 30, 2025
1 parent bb891c6 commit 6717ef4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ curl -u user:password sftp://hostname/path/to/image.bmap > image.bmap
curl -u user:password sftp://hostname/path/to/image.gz | bmap-writer - image.bmap /dev/sdX
```

Note: the [stream-helper.sh](stream-helper.sh) script can be used for stream processing tasks.

## Yocto Integration

`bmap-writer` is already available in [meta-openembedded](https://github.com/openembedded/meta-openembedded/blob/master/meta-oe/recipes-support/bmap-writer/bmap-writer_git.bb).
Expand Down
2 changes: 1 addition & 1 deletion bmap-writer-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ echo "## Write the file with bmap-writer and zstd from HTTP server"
python3 -m http.server -d $(pwd) -b 127.0.0.1 8987 &
SERVER_PID=$!
sleep 2
wget -q -O - http://127.0.0.1:8987/test.img.zst | ./bmap-writer - test.img.bmap test5.zst.img.out
./stream-helper.sh http://127.0.0.1:8987/test.img.zst test5.zst.img.out
cmp test.img.out test5.zst.img.out
kill $SERVER_PID
29 changes: 29 additions & 0 deletions stream-helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash -ex

export PATH=$PWD:$PATH

IMAGE_URL=$(echo "$1" | grep -P '^(https?|s?ftp)://([\da-zA-Z\.-]+)(:\d+)?(/[^\s]*)?$' > /dev/null && echo "$1" || echo "")
DEVICE=$2

WGET=$(which wget)
BMAP_WRITER=$(which bmap-writer)

if [ -z "$IMAGE_URL" ]; then
echo "Usage: $0 <url> <device>"
exit 1
fi

if [ -z "$WGET" ] && [ -z "$BMAP_WRITER" ]; then
echo "Please install wget/bmap-writer"
exit 1
fi

BMAP_URL=$(echo "$IMAGE_URL" | sed 's/\.[^.]*$/.bmap/')
BMAP_FILE=$(echo "$BMAP_URL" | sed 's/.*\///')

BMAP_FILE="${BMAP_FILE}_"
echo "Downloading $BMAP_URL to $BMAP_FILE"
$WGET -q $BMAP_URL -O $BMAP_FILE
echo "Streaming $IMAGE_URL to $DEVICE"
$WGET -q $IMAGE_URL -O - | $BMAP_WRITER - $BMAP_FILE $DEVICE
exit 0

0 comments on commit 6717ef4

Please sign in to comment.