Wednesday, December 01, 2010

update.sh for Android

After scriptcmd (previous blog post), the next to be called is the update.sh script. The script will setup the file system, data partition, cache partition, and user space. It will install BusyBox for you.



height=22
pointX=30
pointY=100

SDCARD=/mnt/mmcblk0p1

string="Good luck!"
echo $string
gui-echo $pointX $pointY "$string"

if [ -x /mnt/mmcblk0/script/update.sh ] ; then
SDCARD=/mnt/mmcblk0
fi

if [ -f ${SDCARD}/script/android_fs.tar ] ; then
string="Updating file system..."
echo $string
gui-echo $pointX $pointY "$string"
else
string="--- File not found - script/android_fs.tar"
echo $string
gui-echo $pointX $pointY "$string"
pointY=$(($pointY + $height + $height))
string="Failed updating file system!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
fi

# FILE SYSTEM SETUP

pointY=$(($pointY + $height + $height))
string="Cleaning up file system..."
echo $string
gui-echo $pointX $pointY "$string"

flash_eraseall /dev/mtd9
if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height + $height))
string="--- Failed cleaning up file system!"
echo $string
gui-echo $pointX $pointY "$string"
pointY=$(($pointY + $height))
string="Kernel doesn't support NAND flash?"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
else
string="Done cleaning up file system..."
echo $string
gui-echo $pointX $pointY "$string"
fi

mount -t yaffs2 /dev/mtdblock9 /mnt/mtd
if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height + $height))
string="--- Failed mounting file system!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
else
string="File system is now mounted..."
echo $string
gui-echo $pointX $pointY "$string"
fi

pointY=$(($pointY + $height))
string="Now copying system files..."
echo $string
gui-echo $pointX $pointY "$string"

tar xvf ${SDCARD}/script/android_fs.tar -C /mnt/mtd
chmod 777 -R /mnt/mtd
string="Files were copied successfully..."
echo $string
gui-echo $pointX $pointY "$string"
pointY=$(($pointY + $height))

if [ -d ${SDCARD}/script/driver ] ; then
echo "Now copying device drivers..."
if [ ! -d /mnt/mtd/.driver ] ; then
mkdir /mnt/mtd/.driver
fi
cp -a ${SDCARD}/script/driver/* /mnt/mtd/.driver

string="Files were copied successfully..."
echo $string
gui-echo $pointX $pointY "$string"
fi

boardID=`getenv wmt.model`
if [ $? -eq 0 ] ; then
if [ $boardID = "8088b_90_20k" ] || [ $boardID = "8088b_90_1k" ] || [ $boardID = "8088b_90_1k" ] ; then
boardID=8088b
fi
special_driver=${SDCARD}/script/driver_$boardID
if [ -d $special_driver ] ; then
echo "Now copying special device drivers..."
if [ ! -d /mnt/mtd/.driver ] ; then
mkdir /mnt/mtd/.driver
fi
cp -a ${special_driver}/* /mnt/mtd/.driver
string="Done copying special device drivers..."
echo $string
gui-echo $pointX $pointY "$string"
fi
fi

if [ -f ${SDCARD}/script/busybox_1.17.tar ] && [ ! -x /mnt/mtd/system/bin/sh-org ] ; then
string="Now copying BusyBox..."
echo $string
gui-echo $pointX $pointY "$string"
tar xvf ${SDCARD}/script/busybox_1.17.tar -C /mnt/mtd
string="Done copying BusyBox..."
echo $string
gui-echo $pointX $pointY "$string"
pointY=$(($pointY + $height))

if [ -x /mnt/mtd/busybox/bin/ash ] ; then
mv /mnt/mtd/system/bin/sh /mnt/mtd/system/bin/sh-org
ln -s /busybox/bin/busybox /mnt/mtd/system/bin/sh
rm /mnt/mtd/system/bin/busybox
cp /busybox/bin/busybox /mnt/mtd/system/bin/
if [ ! -d /mnt/mtd/bin ] ; then
mkdir /mnt/mtd/bin
fi
ln -s /busybox/bin/busybox /mnt/mtd/bin/sh
fi
fi

if [ -d ${SDCARD}/script/pre_root_disk ] || [ -f ${SDCARD}/script/data.tar ] || [ -f ${SDCARD}/script/cache.tar ] ; then
string="Now copying additional files..."
echo $string
gui-echo $pointX $pointY "$string"

if [ -d ${SDCARD}/script/pre_root_disk ] ; then
cp -a ${SDCARD}/script/pre_root_disk/* /mnt/mtd
if [ -d /mnt/mtd/restore ] ; then
if [ -d /mnt/mtd/.restore ] ; then
cp -a /mnt/mtd/restore/* /mnt/mtd/.restore/
rm -rf /mnt/mtd/restore
else
mv /mnt/mtd/restore /mnt/mtd/.restore
fi
fi
fi

if [ -f ${SDCARD}/script/data.tar ] ; then
if [ ! -d /mnt/mtd/.restore ] ; then
mkdir /mnt/mtd/.restore
fi
cp -rf ${SDCARD}/script/data.tar /mnt/mtd/.restore

if [ -d ${SDCARD}/script/pre_data_disk/app ] ; then
cp -rf ${SDCARD}/script/pre_data_disk/app /mnt/mtd/.restore
fi
fi

if [ -f ${SDCARD}/script/cache.tar ] ; then
if [ ! -d /mnt/mtd/.restore ] ; then
mkdir /mnt/mtd/.restore
fi
cp ${SDCARD}/script/cache.tar /mnt/mtd/.restore
fi

if [ -d /mnt/mtd/.restore ] ; then
if [ -f ${SDCARD}/script/etc/touchcal ] ; then
cp -a ${SDCARD}/script/etc/touchcal /mnt/mtd/.restore/
fi
boardID=`getenv wmt.model`
if [ $? -eq 0 ] ; then
special_touchcal_file=${SDCARD}/script/etc/touchcal_$boardID
if [ -f ${special_touchcal_file} ] ; then
cp -a ${special_touchcal_file} /mnt/mtd/.restore/touchcal
fi
fi
fi

string="Done copying additional files..."
echo $string
gui-echo $pointX $pointY "$string"
pointY=$(($pointY + $height))
fi

string="Setting file system permissions..."
echo $string
gui-echo $pointX $pointY "$string"

chmod 755 -R /mnt/mtd
chmod 750 /mnt/mtd/init.rc
chmod 750 /mnt/mtd/init.goldfish.rc
chmod 750 /mnt/mtd/init
chmod 644 /mnt/mtd/default.prop
chmod 700 /mnt/mtd/root
chmod 750 /mnt/mtd/sbin
chmod 751 /mnt/mtd/bin
chmod 751 /mnt/mtd/busybox
chmod 750 /mnt/mtd/lib

string="File system permissions were set..."
echo $string
gui-echo $pointX $pointY "$string"
pointY=$(($pointY + $height))

if [ -f /mnt/mtd/system/bin/preboot ] ; then
chown root:0 /mnt/mtd/system/bin/preboot
chmod a-w /mnt/mtd/system/bin/preboot
chmod a+rxs /mnt/mtd/system/bin/preboot
fi
chmod 777 -R /mnt/mtd
mv /mnt/mtd/busybox/bin/su /mnt/mtd/busybox/bin/su.bak
chown root:root /mnt/mtd/system/bin/su
chmod 4777 /mnt/mtd/system/bin/su

sync
umount /mnt/mtd

if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height))
string="Failed dismounting file system!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
fi

# DATA PARTITION SETUP

if [ -d ${SDCARD}/script/etc ] || [ -f ${SDCARD}/script/data.tar ] || [ -d ${SDCARD}/script/pre_data_disk ] ; then
string="Erasing data partition..."
echo $string
gui-echo $pointX $pointY "$string"

flash_eraseall /dev/mtd10
if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height + $height))
string="Failed erasing data partition!"
echo $string
gui-echo $pointX $pointY "$string"
pointY=$(($pointY + $height))
string="Kernel doesn't support NAND flash?"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
else
string="Done erasing data partition..."
echo $string
gui-echo $pointX $pointY "$string"
fi

mount -t yaffs2 /dev/mtdblock10 /mnt/mtd
if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height + $height))
string="Failed mounting data partition!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
else
string="Data partition mounted successully..."
echo $string
gui-echo $pointX $pointY "$string"
fi
pointY=$(($pointY + $height))

string="Now copying files to data partition..."
echo $string
gui-echo $pointX $pointY "$string"

if [ -f ${SDCARD}/script/data.tar ] ; then
tar xvf ${SDCARD}/script/data.tar -C /mnt/mtd
fi

if [ -d ${SDCARD}/script/etc ] ; then
if [ ! -d /mnt/mtd/wmtpref ] ; then
mkdir /mnt/mtd/wmtpref
fi
cp -a ${SDCARD}/script/etc/* /mnt/mtd/wmtpref/

boardID=`getenv wmt.model`
if [ $? -eq 0 ] ; then
special_touchcal_file=${SDCARD}/script/etc/touchcal_$boardID
if [ -f ${special_touchcal_file} ] ; then
cp -a ${special_touchcal_file} /mnt/mtd/wmtpref/touchcal
fi
fi
fi

if [ -d ${SDCARD}/script/app ] ; then
if [ -d /mnt/mtd/app ] ; then
echo "The app folder exists in the data partition. We don't want it there!"
else
cp -a ${SDCARD}/script/app /mnt/mtd/
fi
fi

if [ -d ${SDCARD}/script/pre_data_disk ] ; then
cp -a ${SDCARD}/script/pre_data_disk/* /mnt/mtd
fi

if [ -d ${SDCARD}/script/pre_root_disk/restore/etc ] ; then
cp -a ${SDCARD}/script/pre_root_disk/restore/etc /mnt/mtd/wmtpref/
fi

string="Done copying files to data partition..."
echo $string
gui-echo $pointX $pointY "$string"
pointY=$(($pointY + $height))

chmod 777 -R /mnt/mtd
sync
umount /mnt/mtd

if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height))
string="Failed to dismount data partition!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
fi
fi

# CACHE PARTITION SETUP

if [ -f ${SDCARD}/script/cache.tar ] || [ -d ${SDCARD}/script/pre_cache_disk ] ; then
string="Erasing cache partition..."
echo $string
gui-echo $pointX $pointY "$string"

flash_eraseall /dev/mtd11
if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height + $height))
string="Failed to erase cache partition!"
echo $string
gui-echo $pointX $pointY "$string"
pointY=$(($pointY + $height))
string="Kernel doesn't support NAND flash?"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
else
string="Done erasing cache partition..."
echo $string
gui-echo $pointX $pointY "$string"
fi

mount -t yaffs2 /dev/mtdblock11 /mnt/mtd
if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height + $height))
string="Failed mounting data partition!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
else
string="Cache partition mounted successfully..."
echo $string
gui-echo $pointX $pointY "$string"
fi
pointY=$(($pointY + $height))

string="Now copying files to cache partition..."
echo $string
gui-echo $pointX $pointY "$string"

if [ -f ${SDCARD}/script/cache.tar ] ; then
tar xvf ${SDCARD}/script/chache.tar -C /mnt/mtd
fi

if [ -d ${SDCARD}/script/pre_cache_disk ] ; then
cp -a ${SDCARD}/script/pre_cache_disk/* /mnt/mtd
fi

string="Done copying files to cache partition..."
echo $string
gui-echo $pointX $pointY "$string"
pointY=$(($pointY + $height))

chmod 777 -R /mnt/mtd
sync
umount /mnt/mtd

if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height))
string="Failed to dismount cache partition!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
fi
fi

string="File system updated successfully!"
echo $string
gui-echo $pointX $pointY "$string"
pointY=$(($pointY + $height + $height))

# USER SPACE SETUP

if [ -f ${SDCARD}/script/driver/g_file_storage.ko ] ; then
string="Erasing user space..."
echo $string
gui-echo $pointX $pointY "$string"

flash_eraseall /dev/mtd12

if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height + $height))
string="Failed to erase user space!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
else
string="Done erasing user space..."
echo $string
gui-echo $pointX $pointY "$string"
fi
mount -t yaffs2 /dev/mtdblock12 /mnt/mtd

if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height + $height))
string="Failed to mount user space!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
else
string="Done mounting user space..."
echo $string
gui-echo $pointX $pointY "$string"
fi

pointY=$(($pointY + $height))
string="Creating loop file..."
echo $string
gui-echo $pointX $pointY "$string"

create_loopfile mtd12 /mnt/mtd/vfat.bin bs=524288

if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height + $height))
string="Failed to create loop file!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
else
if [ -f /mnt/mtd/vfat.bin ] ; then
string="Loop file created..."
echo $string
gui-echo $pointX $pointY "$string"
else
pointY=$(($pointY + $height + $height))
string="Failed to create loop file!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
fi
fi
pointY=$(($pointY + $height))

string="Formatting loop file..."
echo $string
gui-echo $pointX $pointY "$string"

mkdosfs /mnt/mtd/vfat.bin

if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height + $height))
string="Failed formatting loop file!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
else
string="Loop file formatted..."
echo $string
gui-echo $pointX $pointY "$string"
fi

if [ -d ${SDCARD}/script/DemoFile ] || [ -d ${SDCARD}/script/pre_local_disk ] ; then

losetup /dev/loop/0 /mnt/mtd/vfat.bin
if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height))
string="Command losetup failed!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
fi
mkdir /LocalDisk
mount -o iocharset=gb2312 -t vfat /dev/loop/0 /LocalDisk
if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height))
string="Mounting /dev/loop/0 to /LocalDisk failed!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
fi

if [ -d ${SDCARD}/script/DemoFile ] ; then
string="Now copying demo Files to user space..."
echo $string
gui-echo $pointX $pointY "$string"

cp -a ${SDCARD}/script/DemoFile /LocalDisk

string="Demo files were copied to user space successfully..."
echo $string
gui-echo $pointX $pointY "$string"
fi

if [ -d ${SDCARD}/script/pre_local_disk ] ; then
string="Now copying files to user space..."
echo $string
gui-echo $pointX $pointY "$string"

cp -a ${SDCARD}/script/pre_local_disk/* /LocalDisk

string="Done copying files to user space..."
echo $string
gui-echo $pointX $pointY "$string"
fi

chmod 777 -R /LocalDisk
sync
umount /LocalDisk
if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height))
string="Failed dismounting LocalDisk!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
fi
losetup -d /dev/loop/0
if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height))
string="Command losetup -d /dev/loop/0 failed!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
fi
fi

chmod 777 -R /mnt/mtd
sync
umount /mnt/mtd

if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height + $height))
string="Failed dismounting user space!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
fi

pointY=$(($pointY + $height + $height))
else
if [ -d ${SDCARD}/script/DemoFile ] || [ -d ${SDCARD}/script/pre_local_disk ] ; then
string="Erasing user space..."
echo $string
gui-echo $pointX $pointY "$string"

flash_eraseall /dev/mtd12

if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height + $height))
string="Failed erasing user space!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
else
string="Done erasing user space..."
echo $string
gui-echo $pointX $pointY "$string"
fi
mount -t yaffs2 /dev/mtdblock12 /mnt/mtd

if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height + $height))
string="Failed mounting user space!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
else
string="Done mounting user space..."
echo $string
gui-echo $pointX $pointY "$string"
fi

pointY=$(($pointY + $height))

if [ -d ${SDCARD}/script/DemoFile ] ; then
string="Now copying demo files to user space..."
echo $string
gui-echo $pointX $pointY "$string"

cp -a ${SDCARD}/script/DemoFile /mnt/mtd

string="Done copying demo files to user space..."
echo $string
gui-echo $pointX $pointY "$string"
fi

if [ -d ${SDCARD}/script/pre_local_disk ] ; then
string="Now copying files to user space..."
echo $string
gui-echo $pointX $pointY "$string"

cp -a ${SDCARD}/script/pre_local_disk/* /mnt/mtd

string="Done copying files to user space..."
echo $string
gui-echo $pointX $pointY "$string"
fi

chmod 777 -R /mnt/mtd
sync
umount /mnt/mtd

if [ $? -ne 0 ] ; then
pointY=$(($pointY + $height + $height))
string="Failed dismounting user space!"
echo $string
gui-echo $pointX $pointY "$string"
exit 0
fi

pointY=$(($pointY + $height + $height))
fi
fi

echo 0 > /proc/boot-splash
cleanlcd
remove_sd

string="Please remove SD card..."
while [ -x /bin/ls ]
do
if [ -x ${SDCARD}/script/update.sh ] ; then
echo $string
sleep 1
else
break
fi
done

cleanlcd
hint_shutdown
string="Shutting down..."
echo $string
poweroff

No comments: