#!/bin/sh

if [ $# -ne 2 ]; then
    echo "usage: $0 <partition> <updatefile.zip>"
    exit 1
fi

partition=$1
upfile=$2

cp_upfile=/userdata/`basename $upfile`

#0 copy file to CP
hbipc-utils put $upfile $cp_upfile
if [ $? -ne 0 ]; then
    echo "copy file to X2 fail"
    exit 2
fi

#1. exec otaupdate
hbipc-utils run "otaupdate $partition $cp_upfile"
ret=$?
if [ $ret -ne 0 ]; then
    echo "update fail, error code: $ret"
    exit 3
fi

exit 0
