#!/bin/sh
# installs a rootfs tar archive from OpenADK onto 
# a NAND device
# special script for routerboard rb4xx

if [ -z $1 ];then
        printf "Please give your root tar archive as parameter\n"
        exit 1
fi

printf "Preparing mountpoints\n"
mount -t yaffs2 /dev/mtdblock2 /mnt
rm -rf /mnt/* >/dev/null 2>&1
mkdir /mnt/boot
mount -t yaffs2 /dev/mtdblock1 /mnt/boot

printf "Extracting install archive\n"
tar -C /mnt -xzpf $1
if [ $? -ne 0 ];then
	printf "Extracting of install archive failed"
	exit 1
fi

chmod 1777 /mnt/tmp
chmod 4755 /mnt/bin/busybox

sync
umount /mnt/boot
umount /mnt
if [ $? -ne 0 ];then
	printf "Unmounting filesystem failed"
	exit 1
else
	printf "Successfully installed.\n"
	exit 0
fi
