升级包自动生成脚本
时间:2010-10-18 来源:jiangjqian
升级包自动生成脚本如下:
#!/bin/sh
# Description: this is used to generate upgrade package
# Usage: package_generate.sh dirname [package_name]
#
#######################################################################
# USER DEFINITION
#######################################################################
# default package_name
package_name=apollo-sw-$(date +%Y-%m-%d-%H-%M)
# list images to be update, [<filename> <image_location>]...
image_list="
linux-2.6.28.10/vmlinux.bin mtd4
appfs.jffs2.nand mtd5
rootfs.arm.jffs2.nand mtd6
"
######################################################################
# INPUT PROCESS
######################################################################
############### Get dirname ###########
if [ $# -lt 1 ]
then
echo "Usage: sh $0 dirname [package_name]"
exit
fi
dir=$1
############### Get package name #######
if [ $# -gt 1 ]
then
package_name=$2
fi
############## Check files exist && image_location #######
item="FILE"
# Check files exist
for i in $image_list; do
if [ $item = "FILE" ]; then
item="TARGET"
#check file exist
if [ ! -f $dir/$i ]; then
echo "ERR: $dir/$i is not a file\n"
exit
fi
else
item="FILE"
match=$(expr match "$i" '\(mtd[0-9][0-9]*\)') #extract $substring at the begin of $i
if [ -z $match ]; then
echo "ERR: invalid image location $i"
exit
fi
if [ $match != $i ]; then
echo "ERR: invalid image location $i"
exit
fi
fi
done
######################################################################
# PROCESS PER LINE
######################################################################
bury_copy()
{
mkdir -p $(dirname $2) && cp $1 $2
}
targetdir=${package_name}_dir
rm -rf $targetdir
mkdir $targetdir
echo "#!/bin/sh" > $targetdir/autorun.sh
item="FILE"
# Check files exist
for i in $image_list; do
if [ $item = "FILE" ]; then
item="TARGET"
file=$i
else
item="FILE"
#copy file to dirs
bury_copy $dir/$file $targetdir/$file
#generate command of image_update
dev=/dev/$i
cksum=$(cksum $dir/$file)
crc=$(expr "$cksum" : '\([0-9][0-9]*\)')
cksum=${cksum#$crc}
len=$(expr "$cksum" : '\(.[0-9][0-9]*\)')
echo image_update -d $dev -m $file -c $crc -l $len >> $targetdir/autorun.sh
fi
done
chmod +x $targetdir/autorun.sh
mkcramfs $targetdir $package_name