Extracting/Rebuilding MyPassport Wireless firmware images

If anyone wants to play the firmware images, here are two quick&dirty scripts to extract and rebuild binary images:

extract_fw:

#!/bin/sh

img=$1
if [ ! -e "$img" ]; then
    echo "usage: fakeroot ./extract_fw <img file>"
    exit 1
fi

if [ $(id -u) != 0 ]; then
    echo "you should run it with fakeroot:"
    echo "  fakeroot $0 $*"
    exit 1
fi


img=$(realpath $img)

rm -rf tmp
mkdir tmp
cd tmp
tar xf $img

cd ..
rm -rf rootfs
mkdir -p rootfs
cd rootfs
tar xf ../tmp/rootfs.tar.gz

rebuild_fw:

#!/bin/bash

if [ $(id -u) != 0 ]; then
    echo "you should run it with fakeroot:"
    echo "  fakeroot $0 $*"
    exit 1
fi

version=$1
if [ -z "$version" ]; then
    echo "usage: fakeroot ./rebuild_fw <version>"
    exit 1
fi

cd rootfs
echo "$version" > etc/version
echo "building rootfs tarfile"
tar cf ../tmp/rootfs.tar .

cd ../tmp
gzip -f -v rootfs.tar
echo "$version" > fw.version
echo "updating md5 file"
rm -f fw.md5
md5sum $(find -type f|sed -e 's#\./##'|sort) > fw.md5

echo "building img"
tar cf ../MyPassportWirelessGen2_${version}.bin . --transform 's#^\./##'

cd ..
echo "done."

usage:

$ fakeroot ./extract_fw MyPassportWirelessGen2_1.04.17.bin 
[...] make the changes you want under rootfs/
$ fakeroot ./rebuild_fw 1.04.17-fix-test-1

Hope this helps,
Gilles.