#!/bin/bash

# Decompress Gzip archive, extract cpio filesystem
gzip -cd config.tgz | cpio -idmv

# Create ubifs image from "config/" directory
mkfs.ubifs -r config/ -m 2048 -e 126976 -c 4096 -o config.img

# Prepare image (Small size, increased to max partition size at first access)
ubinize -vv -o config_mtd5.img -m 2048 -s 2048 -p 131072 ubinize.conf


### On WD MyCloud Mirror Gen2 / Ex2 Ultra:
# Clean partition
dd if=/dev/zero of=/dev/mtdblock5 2>/dev/null
# Upload image
dd if=config_mtd5.img of=/dev/mtdblock5 bs=2M
