Created
May 6, 2022 08:27
-
-
Save mak3r/a4f7e3adfaf65f8d0b4ff1039c0ffa64 to your computer and use it in GitHub Desktop.
Copy and unpack an .xz image to a block device - linux
This file contains hidden or 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 -x | |
usage() { | |
echo "Usage:" | |
echo "$0 <url to .xz image> <device e.g. /dev/sda>" | |
echo "" | |
echo "Warning: Make sure you pass the device you really want to overwrite." | |
echo "\tit will get wiped." | |
} | |
# Check that we have 2 arguments | |
if [ -z "$1" ] || [ -z "$2" ]; then | |
usage | |
fi | |
# Preparing the image details | |
URL=$1 | |
DISK=$2 | |
curl -L -O "$URL" | |
XZ=${URL##*/} | |
## Unpack it and keep the xz | |
unxz --keep $XZ | |
IMAGE=$(basename "$XZ" .xz) | |
SIZE=$(find "$PWD/$IMAGE" -printf "%s") | |
## Copy it to the sdcard on /dev/sda | |
sudo /bin/sh -c "dd if=$IMAGE ibs=1M status=none | pv -s "$SIZE" | dd of="$DISK" obs=1M oflag=direct status=none" | |
## Remove the uncompressed image | |
#rm $IMAGE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment