Skip to content

Instantly share code, notes, and snippets.

@highercomve
Created September 14, 2020 13:23
Show Gist options
  • Save highercomve/f167b61199d120a0434900d153c0de2c to your computer and use it in GitHub Desktop.
Save highercomve/f167b61199d120a0434900d153c0de2c to your computer and use it in GitHub Desktop.
#!/bin/bash
set -x
cpio_file=$(mktemp /tmp/magiccpio.XXXXXXX)
cd $1
find . | cpio -o -H newc > $cpio_file
xz --keep --check=crc32 --lzma2=dict=512KiB $cpio_file
fl=$(stat -c %s $cpio_file.xz)
rem=$(($fl % 4))
fb= ;
if [ $rem = 0 ]; then
fb=$fl
else
fb=$(($fl + 4 - $rem))
fi;
dd if=/dev/zero of=$cpio_file.xz4 bs=1 count=$fb
dd if=$cpio_file.xz of=$cpio_file.xz4 conv=notrunc
cd ~
mv $cpio_file.xz4 $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment