#!/bin/ash
echo save adept data
if [ -f /mnt/mmc0p3/.adept/device.xml ]; then
	cp /mnt/mmc0p3/.adept/device.xml /tmp/device.xml
fi
if [ -f /mnt/mmc0p3/.adept/devicesalt ]; then
	cp /mnt/mmc0p3/.adept/devicesalt /tmp/devicesalt
fi
if [ -f /mnt/mmc0p3/.adept/devicekey ]; then
	cp /mnt/mmc0p3/.adept/devicekey /tmp/devicekey
fi
echo save database data
if [ -f /mnt/mmc0p3/data/calendar.sqlite ]; then
	cp /mnt/mmc0p3/data/calendar.sqlite /tmp/calendar.sqlite
fi
if [ -f /mnt/mmc0p3/data/webfavo.sqlite ]; then
	cp /mnt/mmc0p3/data/webfavo.sqlite /tmp/webfavo.sqlite
fi

echo format mmcblk0p3 to clean rwdata
umount /dev/mmcblk0p3
mkfs.ext3 /dev/mmcblk0p3

echo restore adept data
mount /dev/mmcblk0p3 /mnt/mmc0p3
if [ -f /tmp/device.xml ]; then
	mkdir /mnt/mmc0p3/.adept
	cp /tmp/device.xml /mnt/mmc0p3/.adept/device.xml
fi
if [ -f /tmp/devicesalt ]; then
	mkdir /mnt/mmc0p3/.adept
	cp /tmp/devicesalt /mnt/mmc0p3/.adept/devicesalt
fi
if [ -f /tmp/devicekey ]; then
	mkdir /mnt/mmc0p3/.adept
	cp /tmp/devicekey /mnt/mmc0p3/.adept/devicekey
fi
echo restore database data
if [ -f /tmp/calendar.sqlite ]; then
	mkdir /mnt/mmc0p3/data
	cp /tmp/calendar.sqlite /mnt/mmc0p3/data/calendar.sqlite
fi
if [ -f /tmp/webfavo.sqlite ]; then
	mkdir /mnt/mmc0p3/data
	cp /tmp/webfavo.sqlite /mnt/mmc0p3/data/webfavo.sqlite
fi

echo format mmcblk0p4 to clean private storage
umount /dev/mmcblk0p4
mkfs.ext3 /dev/mmcblk0p4
exit 0