Add blkid-print to delta.tar
[platform/core/system/upgrade-tools.git] / mk_delta / common / bin / mk_part_delta.sh
1 #!/bin/bash
2
3
4 #==================
5 # funtions
6 #==================
7
8 #------------------------------------------------------------------------------
9 # Function :
10 #       fn_print_line
11 #
12
13 fn_print_line()
14 {
15         CHAR=$1
16         NUM=$2
17
18         echo "*******************************************************************"
19 }
20
21 #------------------------------------------------------------------------------
22 # Function :
23 #       fn_extract_mounting_wrapper
24 #
25 # Params :
26 #
27 # Description :
28 #       extract neccessary files/info from binary images,
29 #       by mounting them and calling fn_extract_needed_files()
30 #
31 fn_extract_mounting_wrapper()
32 {
33         if [ "$PART_NAME" != "rootfs" ] && [ "$PART_NAME" != "hal" ]; then
34                 return
35         fi
36         local MNT_PNT_OLD="MNT_PNT_OLD"
37         local MNT_PNT_NEW="MNT_PNT_NEW"
38
39         mkdir -p ${MNT_PNT_OLD}
40         mkdir -p ${MNT_PNT_NEW}
41
42         sudo mount -o loop,ro "${PART_IMG_OLD}" ${MNT_PNT_OLD}
43         sudo mount -o loop,ro "${PART_IMG_NEW}" ${MNT_PNT_NEW}
44
45         fn_extract_needed_files ${MNT_PNT_OLD} ${MNT_PNT_NEW}
46
47         sudo umount ${MNT_PNT_OLD}
48         sudo umount ${MNT_PNT_NEW}
49
50         rm -rf ${MNT_PNT_OLD}
51         rm -rf ${MNT_PNT_NEW}
52 }
53
54 #------------------------------------------------------------------------------
55 # Function :
56 #       fn_extract_needed_files
57 #
58 # Params :
59 #       $1 - mount point of older partiton
60 #       $2 - mount point of newer partition
61 #
62 # Description :
63 #       extract neccessary files/info from already mounted partitions
64 #
65 fn_extract_needed_files()
66 {
67         # mount/umount as rarely as possible
68         local MNT_PNT_OLD=$1
69         local MNT_PNT_NEW=$2
70
71         if [ "$PART_NAME" == "hal" ]; then
72                 local HAL_TARG_NAME="hal-model-conf.xml"
73                 local HAL_MODEL_CONFIG_PATH=${MNT_PNT_OLD}"/etc/config/model-config.xml"
74
75                 # exctarct files/binaries
76                 cp "${HAL_MODEL_CONFIG_PATH}" ./${HAL_TARG_NAME}
77
78         elif [ "$PART_NAME" == "rootfs" ]; then
79                 # TODO names + export
80                 local ROOTFS_TARG_NAME="rootfs-model-config.xml"
81                 local TIZEN_TARG_NAME="tizen-build.conf"
82                 local UPGRADE_SUPPORT="upgrade-support"
83                 local UPGRADE_APPLY="upgrade-apply"
84                 local UPGRADE_APPLY_DELTAFS="upgrade-apply-deltafs"
85                 local DELTA_VERIFIER="delta-verifier"
86                 local BLKID_PRINT="blkid-print"
87
88                 local ROOTFS_MODEL_CONFIG_PATH=${MNT_PNT_OLD}"/etc/config/model-config.xml"
89                 local TIZEN_BUILD_CONFIG_PATH=${MNT_PNT_OLD}"/etc/tizen-build.conf"
90                 local UPGRADE_SUPPORT_PATH=${MNT_PNT_NEW}"/usr/libexec/"${UPGRADE_SUPPORT}
91                 local UPGRADE_APPLY_PATH=${MNT_PNT_NEW}"/usr/bin/"${UPGRADE_APPLY}
92                 local UPGRADE_APPLY_DELTAFS_PATH=${MNT_PNT_NEW}"/usr/bin/"${UPGRADE_APPLY_DELTAFS}
93                 local DELTA_VERIFIER_PATH=${MNT_PNT_NEW}"/usr/bin/"${DELTA_VERIFIER}
94                 local BLKID_PRINT_PATH=${MNT_PNT_NEW}"/usr/bin/"${BLKID_PRINT}
95
96                 # build string building
97                 echo "===== Start writing image versions ====="
98                 local BUILD_STRING_FILE="build_string.txt"
99                 local OLD_BUILD_STRING=`cat ${MNT_PNT_OLD}/etc/info.ini | grep "Date=" | sed "s/Date=//" | sed "s/;$//"`
100                 local NEW_BUILD_STRING=`cat ${MNT_PNT_NEW}/etc/info.ini | grep "Date=" | sed "s/Date=//" | sed "s/;$//"`
101                 echo "${BUILD_STRING_FILE} : ${OLD_BUILD_STRING}@${NEW_BUILD_STRING}"
102                 echo -n ${OLD_BUILD_STRING}@${NEW_BUILD_STRING} > ${BUILD_STRING_FILE}
103                 echo "===== Finish writing image versions ====="
104
105                 # extract files/binaries
106                 cp "${ROOTFS_MODEL_CONFIG_PATH}" ./${ROOTFS_TARG_NAME}
107                 cp "${TIZEN_BUILD_CONFIG_PATH}" ./${TIZEN_TARG_NAME}
108                 cp -r "${UPGRADE_SUPPORT_PATH}" ./${UPGRADE_SUPPORT}
109                 cp "${UPGRADE_APPLY_PATH}" ./${UPGRADE_APPLY}
110                 cp "${UPGRADE_APPLY_DELTAFS_PATH}" ./${UPGRADE_APPLY_DELTAFS}
111                 cp "${DELTA_VERIFIER_PATH}" ./${DELTA_VERIFIER}
112                 cp "${BLKID_PRINT_PATH}" ./${BLKID_PRINT}
113
114         fi
115 }
116
117 #------------------------------------------------------------------------------
118 # Function :
119 #       fn_mk_attribute
120 #
121 # Params :
122 #       $1 - PART_NAME. to descriminate
123 #       $2 - base directory to search files for old partition
124 #       $3 - base directory to search files for new partition
125 #
126 # Description :
127 #       extract attribute information of files on the given partition
128 #
129
130 fn_mk_attribute()
131 {
132         TARGET=$1
133         BASE_DIR_OLD=$2
134         BASE_DIR_NEW=$3
135         V1_ATTR_FILE=${OUTPUT_DIR}/v1_${TARGET}_attr.txt
136         V1_NAME_FILE=${OUTPUT_DIR}/v1_list.txt
137         V2_ATTR_FILE=${OUTPUT_DIR}/v2_${TARGET}_attr.txt
138         V2_NAME_FILE=${OUTPUT_DIR}/v2_list.txtfg
139         V23_NAME_FILE=v23_${TARGET}_attr.txt
140         V13_NAME_FILE=v13_${TARGET}_attr.txt
141         ATTR_CMD=extended_attr.sh
142
143         echo "Attribute generation for ${TARGET} [START] $(date +%T)"
144
145         sudo find ./${BASE_DIR_OLD} -type f -printf '"%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >  ${V1_ATTR_FILE}
146         sudo find ./${BASE_DIR_OLD} -type l -printf '"%P" SymLink 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V1_ATTR_FILE}
147         sudo find ./${BASE_DIR_OLD} -type d -printf '"%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V1_ATTR_FILE}
148
149         sudo find ./${BASE_DIR_NEW} -type f -printf '"%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >  ${V2_ATTR_FILE}
150         sudo find ./${BASE_DIR_NEW} -type l -printf '"%P" SymLink 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V2_ATTR_FILE}
151         sudo find ./${BASE_DIR_NEW} -type d -printf '"%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V2_ATTR_FILE}
152
153         ################ Change user and group permission from '0' to '0000' ############
154         sed -i 's/:   0/:0000/g' ${V1_ATTR_FILE}
155         sed -i 's/:   /:000/g' ${V1_ATTR_FILE}
156         sed -i 's/:  /:00/g' ${V1_ATTR_FILE}
157         sed -i 's/: /:0/g' ${V1_ATTR_FILE}
158
159         sed -i 's/:   0/:0000/g' ${V2_ATTR_FILE}
160         sed -i 's/:   /:000/g' ${V2_ATTR_FILE}
161         sed -i 's/:  /:00/g' ${V2_ATTR_FILE}
162         sed -i 's/: /:0/g' ${V2_ATTR_FILE}
163
164         ################ Change ":./old" to "/" ############
165         sed -i "s/:.\/${BASE_DIR_OLD}\//:/" ${V1_ATTR_FILE}
166         sed -i "s/:.\/${BASE_DIR_OLD}/:/" ${V1_ATTR_FILE}
167
168         sed -i "s/:.\/${BASE_DIR_NEW}\//:/" ${V2_ATTR_FILE}
169         sed -i "s/:.\/${BASE_DIR_NEW}/:/" ${V2_ATTR_FILE}
170
171         echo "Attribute generation for ${TARGET} [END] $(date +%T)"
172 }
173
174 #------------------------------------------------------------------------------
175 # Function :
176 #       fn_mk_full_img
177 #
178
179 fn_mk_full_img()
180 {
181         PART_IMG_ORG=${PART_BIN}
182         PART_IMG_OLD=${PART_IMG_ORG}.old
183         PART_IMG_NEW=${PART_IMG_ORG}.new
184
185         #---- untar partition image and rename for old & new ----
186         if [ ! "z${OLD_TAR_FILE}" = "z" ]; then
187                 echo "untar ${OLD_TAR_FILE}"
188                 tar xvf ${OLD_TAR_DIR}/${OLD_TAR_FILE} ${PART_IMG_ORG}
189                 if [ "$?" != "0" ]; then
190                         return 1;
191                 fi
192                 sudo mv ${PART_IMG_ORG} ${PART_IMG_OLD}
193         fi
194
195         echo "untar ${NEW_TAR_FILE}"
196         tar xvf ${NEW_TAR_DIR}/${NEW_TAR_FILE} ${PART_IMG_ORG}
197         if [ "$?" != "0" ]; then
198                 return 1;
199         fi
200         sudo mv ${PART_IMG_ORG} ${PART_IMG_NEW}
201
202         # after extraction, get neccessary files
203         fn_extract_mounting_wrapper
204
205         if [ ! "z${OLD_TAR_FILE}" = "z" ]; then
206                 #---- check whether the binaries are same ----
207                 sudo diff ${PART_IMG_OLD} ${PART_IMG_NEW}
208                 if [ "$?" = "0" ]; then
209                         echo "[${PART_NAME}] two binaries are same"
210                         sudo rm -rf ${PART_IMG_OLD}
211                         sudo rm -rf ${PART_IMG_NEW}
212                         return 0
213                 fi
214                 sudo python3 ${COMMON_BINDIR}/CreatePatch.py ${UPDATE_TYPE} ${PART_NAME} ${PART_IMG_OLD} ${PART_IMG_NEW} ${OUTPUT_DIR} ${UPDATE_CFG_PATH}
215                 PythonRet=$?
216                 sudo rm ${PART_IMG_OLD}
217
218                 if [ $PythonRet != "0" ]; then
219                         echo "[${PART_NAME}] Failed to generate DELTA"
220                         exit 1
221                 fi
222         fi
223
224         sudo mv ${PART_IMG_NEW} ${OUTPUT_DIR}/${PART_IMG_ORG}
225         sudo chown ${MY_ID}:${MY_ID} ${OUTPUT_DIR}/${PART_IMG_ORG}
226
227         return 0
228 }
229
230 #------------------------------------------------------------------------------
231 # Function :
232 #       fn_mk_delta_img_core
233 #
234 # Description :
235 #       core routine for delta generation
236 #       Image Update Type
237 #
238
239 fn_mk_delta_img_core()
240 {
241
242         START_TIMESTAMP="generation of ${DELTA} [START] $(date +%T)"
243
244         #---- untar partition image and rename for old & new ----
245         echo "untar ${OLD_TAR_FILE}"
246         tar xvf ${OLD_TAR_DIR}/${OLD_TAR_FILE} ${PART_IMG_ORG}
247         if [ "$?" != "0" ]; then
248                 return 1;
249         fi
250         sudo mv ${PART_IMG_ORG} ${PART_IMG_OLD}
251
252         echo "untar ${NEW_TAR_FILE}"
253         tar xvf ${NEW_TAR_DIR}/${NEW_TAR_FILE} ${PART_IMG_ORG}
254         if [ "$?" != "0" ]; then
255                 return 1;
256         fi
257         sudo mv ${PART_IMG_ORG} ${PART_IMG_NEW}
258
259         # after extraction, get neccessary files
260         fn_extract_mounting_wrapper
261
262         #---- check whether the binaries are same ----
263         sudo diff ${PART_IMG_OLD} ${PART_IMG_NEW}
264         if [ "$?" = "0" ]; then
265                 echo "[${PART_NAME}] two binaries are same"
266                 sudo rm -rf ${PART_IMG_OLD}
267                 sudo rm -rf ${PART_IMG_NEW}
268                 return 0
269         fi
270
271         #---- make delta file ----
272         echo "make ${DELTA}"
273         sudo python3 ${COMMON_BINDIR}/CreatePatch.py ${UPDATE_TYPE} ${PART_NAME} ${PART_IMG_OLD} ${PART_IMG_NEW} ${OUTPUT_DIR} ${UPDATE_CFG_PATH}
274         PythonRet=$?
275         #sudo xdelta delta ${PART_IMG_OLD} ${PART_IMG_NEW} ./${OUTPUT_DIR}/${PART_NAME}".delta"
276
277         #---- remove files & directories ----
278         echo "remove temp files/directory & move delta/log to result directory"
279         sudo rm -rf ${PART_IMG_OLD}
280         sudo rm -rf ${PART_IMG_NEW}
281         sudo rm -rf x
282
283         if [ $PythonRet != "0" ]; then
284                 echo "[${PART_NAME}] Failed to generate DELTA"
285                 exit 1
286         fi
287         END_TIMESTAMP="generation of ${DELTA} [END] $(date +%T)"
288         echo "${START_TIMESTAMP}"
289         echo "${END_TIMESTAMP}"
290
291
292         return 0
293 }
294
295 #------------------------------------------------------------------------------
296 # Function :
297 #       fn_mk_delta_img
298 #
299 # Description :
300 #       generate delta file for image type partition
301 #
302
303 fn_mk_delta_img()
304 {
305         PART_IMG_ORG=${PART_BIN}
306         PART_IMG_OLD=${PART_IMG_ORG}.old
307         PART_IMG_NEW=${PART_IMG_ORG}.new
308
309         DELTA=${DELTA_BIN}
310         DEBUG_DELTA=debug_${DELTA}
311         #CFG_XML=${PART_NAME}_IMG.xml
312         mkdir ${OUTPUT_DIR}/i
313
314         fn_mk_delta_img_core
315         if [ "$?" != "0" ]; then
316                 return 1
317         fi
318
319         return 0
320
321 }
322 #------------------------------------------------------------------------------
323 # Function :
324 #       mk_inter_attrib_file
325 #
326 # Description :
327 #       makes a list of attributes for those files which differ between v1 aND V2
328 #manoj:to create intermediate attribute list
329 fn_mk_inter_attrib_file()
330 {
331         V1ref_ATTR_FILE=${OUTPUT_DIR}/v1_${TARGET}_attr.txt
332         V2ref_ATTR_FILE=${OUTPUT_DIR}/v2_${TARGET}_attr.txt
333 }
334
335 #------------------------------------------------------------------------------
336 # Function :
337 #       fn_mk_delta_fs_core
338 #
339 # Description :
340 #       core routine for delta generation
341 #       File System Update Type (DELTA_FS)
342 #
343
344 fn_mk_delta_fs_core()
345 {
346         START_TIMESTAMP="generation of ${DELTA} [START] $(date +%T)"
347         FS=ext4
348
349         if [ "${DELTA}" = "boot.img/" ]; then
350                 FS=vfat
351         fi
352
353         #---- untar partition image and rename for old & new ----
354         echo "untar ${OLD_TAR_FILE}"
355         tar xvf ${OLD_TAR_DIR}/${OLD_TAR_FILE} ${PART_IMG_ORG}
356         if [ "$?" != "0" ]; then
357                 return 1;
358         fi
359         sudo mv ${PART_IMG_ORG} ${PART_IMG_OLD}
360
361         echo "untar ${NEW_TAR_FILE}"
362         tar xvf ${NEW_TAR_DIR}/${NEW_TAR_FILE} ${PART_IMG_ORG}
363         if [ "$?" != "0" ]; then
364                 return 1;
365         fi
366         sudo mv ${PART_IMG_ORG} ${PART_IMG_NEW}
367
368         #---- check whether the binaries are same ----
369         sudo diff ${PART_IMG_OLD} ${PART_IMG_NEW}
370         if [ "$?" = "0" ]; then
371                 echo "[${PART_NAME}] two binaries are same"
372                 sudo rm -rf ${PART_IMG_OLD}
373                 sudo rm -rf ${PART_IMG_NEW}
374                 sudo rm -rf ${OUTPUT_DIR}
375                 return 0
376         fi
377
378         #---- make mount point ----
379         mkdir -p ${MNT_PNT_OLD}
380         mkdir -p ${MNT_PNT_NEW}
381
382         #---- mount partition image to mount point  ----
383         echo "mount ${PART_IMG_OLD} & ${PART_IMG_NEW}"
384         sudo mount -o loop ${PART_IMG_OLD} ${MNT_PNT_OLD}
385         if [ "$?" != "0" ]; then
386                 return 1;
387         fi
388         sudo mount -o loop ${PART_IMG_NEW} ${MNT_PNT_NEW}
389         if [ "$?" != "0" ]; then
390                 return 1;
391         fi
392
393         # after mounting
394         fn_extract_needed_files "${MNT_PNT_OLD}" "${MNT_PNT_NEW}"
395
396         #---- remove unnecessary files & directories  ----
397         for ff in ${EXCLUDE_FILES}
398         do
399                 sudo rm -rf ${MNT_PNT_OLD}/${ff}
400                 sudo rm -rf ${MNT_PNT_NEW}/${ff}
401         done
402
403         #---- make attribute ----
404         fn_mk_attribute ${PART_NAME} ${BASE_OLD} ${BASE_NEW}
405
406         #PART_IMG_ORG parameter should match with DELTA name that is part of default config file. Which will be used to update MAX size file that is present in respective partition.
407         sudo python3 ${COMMON_BINDIR}/CreatePatch.py ${UPDATE_TYPE} ${PART_NAME} ${BASE_OLD} ${BASE_NEW} ${OUTPUT_DIR} ${UPDATE_CFG_PATH} \
408         --attr_old ${V1_ATTR_FILE} --attr_new ${V2_ATTR_FILE}
409         PythonRet=$?
410
411         #---- unmount partition image ----
412         echo "umount ${MNT_PNT_OLD} & ${MNT_PNT_NEW}"
413         sudo umount ${MNT_PNT_OLD}
414         sudo umount ${MNT_PNT_NEW}
415
416         #---- remove files & directories ----
417         echo "remove temp files/directory & move delta/log to result directory"
418         sudo rm -rf ${PART_IMG_OLD}
419         sudo rm -rf ${PART_IMG_NEW}
420         sudo rm -rf ${BASE_OLD} ${BASE_NEW}
421         sudo rm -rf x
422
423         #---- extra cleanup ----
424         sudo mv ./file_attr_updated_image.txt ${OUTPUT_DIR}/${PART_NAME}_file_attr_updated_image.txt
425
426         if [ $PythonRet != "0" ]; then
427                 echo "[${PART_NAME}] Failed to generate DELTA"
428                 exit 1
429         fi
430         END_TIMESTAMP="generation of ${DELTA} [END] $(date +%T)"
431         echo "${START_TIMESTAMP}"
432         echo "${END_TIMESTAMP}"
433
434         return 0
435 }
436
437 #------------------------------------------------------------------------------
438 # Function :
439 #       fn_mk_delta_fs
440 #
441 # Description :
442 #       generate delta file for filesystem type partition
443 #
444
445 fn_mk_delta_fs()
446 {
447         PART_IMG_ORG=${PART_BIN}
448         PART_IMG_OLD=${PART_IMG_ORG}.old
449         PART_IMG_NEW=${PART_IMG_ORG}.new
450
451         DELTA=${DELTA_BIN}
452         DEBUG_DELTA=debug_${DELTA}
453         #CFG_XML=${PART_NAME}_FS.xml
454
455         BASE_OLD=${PART_NAME}_OLD
456         BASE_NEW=${PART_NAME}_NEW
457
458         #--- !!! this should be modified according to partition ---
459         case "${PART_NAME}" in
460         "rootfs" )
461                 EXCLUDE_FILES="lost+found dev proc tmp var sys csa"
462                 ;;
463         "ramdisk1" | "ramdisk" )
464                 EXCLUDE_FILES="lost+found dev proc tmp sys"
465                 ;;
466         "ramdisk2" | "ramdisk-recovery" )
467                 EXCLUDE_FILES="lost+found"
468                 ;;
469         "user" )
470                 EXCLUDE_FILES="lost+found"
471                 ;;
472         "system-data" )
473                 EXCLUDE_FILES="lost+found"
474                 ;;
475         "kernel" | "boot" )
476                 EXCLUDE_FILES=""
477                 ;;
478         "hal" )
479                 EXCLUDE_FILES=""
480                 ;;
481
482         * )
483                 echo "${PART_NAME} not supported !!!"
484                 return 1
485                 ;;
486         esac
487
488         MNT_PNT_OLD=${BASE_OLD}/
489         MNT_PNT_NEW=${BASE_NEW}/
490
491         fn_mk_delta_fs_core
492         if [ "$?" != "0" ]; then
493                 return 1
494         fi
495
496         return 0
497 }
498
499 #------------------------------------------------------------------------------
500 # Function :
501 #       fn_mk_flash_img
502 #
503
504 fn_mk_flash_img()
505 {
506         PART_IMG_NEW=${PART_BIN}
507
508         #---- untar partition image and rename for old & new ----
509         echo "untar ${NEW_TAR_FILE}"
510         tar xvf ${NEW_TAR_DIR}/${NEW_TAR_FILE} ${PART_IMG_NEW}
511         if [ "$?" != "0" ]; then
512                 return 1;
513         fi
514
515         sudo mv ${PART_IMG_NEW} ${OUTPUT_DIR}/${PART_BIN}
516         sudo chown ${MY_ID}:${MY_ID} ${OUTPUT_DIR}/${PART_BIN}
517
518         return 0
519 }
520
521
522
523 #------------------------------------------------------------------------------
524 # Function :
525 #       get_tar_file_names
526 #
527 # Description :
528 #       find tar file name (without path) that contains given partition binary
529 #
530
531 fn_get_tar_file_names()
532 {
533         BIN_TO_FIND=$1
534
535         cd ${DATA_DIR}/${OLD_TAR_DIR}
536         OLD_TAR_LIST=`ls *.tar *.tar.gz *.tgz *.tar.md5 2>/dev/null`
537         cd ${CUR_DIR}
538
539         cd ${DATA_DIR}/${NEW_TAR_DIR}
540         NEW_TAR_LIST=`ls *.tar *.tar.gz *.tgz *.tar.md5 2>/dev/null`
541         cd ${CUR_DIR}
542
543         #--- find which tar contains the binary ---
544         for tar_file in ${OLD_TAR_LIST}
545         do
546                 result=`tar -tvf ${DATA_DIR}/${OLD_TAR_DIR}/${tar_file} | grep " ${BIN_TO_FIND}$"`
547                 if [ "$?" = "0" ]; then
548                         OLD_TAR_FILE=${tar_file}
549                         break
550                 fi
551         done
552
553         for tar_file in ${NEW_TAR_LIST}
554         do
555                 result=`tar -tvf ${DATA_DIR}/${NEW_TAR_DIR}/${tar_file} | grep " ${BIN_TO_FIND}$"`
556                 if [ "$?" = "0" ]; then
557                         NEW_TAR_FILE=${tar_file}
558                         break
559                 fi
560         done
561
562 }
563
564 ###############################################################################
565 #==================
566 # Main Start
567 #==================
568
569 fn_print_line - 80
570
571 #--- assign input params to internal variables ---
572 param_num=$#
573 if [ "${param_num}" != "4" ]; then
574         echo "Invalid param num"
575         echo "[Usage] $0 PART_NAME UPDATE_TYPE PART_BIN DELTA_BIN"
576         exit 1
577 fi
578
579 PART_NAME=$1
580 UPDATE_TYPE=$2
581 PART_BIN=$3
582 DELTA_BIN=$4
583
584 #--- set some default variables ---
585 MY_ID=`whoami`
586 CUR_DIR=`pwd`
587 DATA_DIR=./data
588 CFG_DIR=./cfg
589 #XML_DIR=./xml
590 COMMON_BINDIR=${CUR_DIR}/../common/bin
591 UPDATE_CFG_PATH=./cfg/update.cfg
592
593 #--- check if the current working directory is the parent directory of bin, data, cfg, xml ---
594 TEST_DIR=${DATA_DIR}
595 if [ ! -d ${TEST_DIR} ]; then
596         echo "Invalid working directory. ${TEST_DIR} does not exist"
597         exit 1
598 fi
599
600 TEST_DIR=${CFG_DIR}
601 if [ ! -d ${TEST_DIR} ]; then
602         echo "Invalid working directory. ${TEST_DIR} does not exist"
603         exit 1
604 fi
605
606 #TEST_DIR=${XML_DIR}
607 #if [ ! -d ${TEST_DIR} ]; then
608 #       echo "Invalid working directory. ${TEST_DIR} does not exist"
609 #       exit 1
610 #fi
611
612 #--- get old/new tar file which includes $PART_BIN ---
613 if [ "z${OLD_TAR_DIR}" = "z" ]; then
614         OLD_TAR_DIR="old_tar"
615 fi
616 if [ "z${NEW_TAR_DIR}" = "z" ]; then
617         NEW_TAR_DIR="new_tar"
618 fi
619 OLD_TAR_FILE=
620 NEW_TAR_FILE=
621
622 fn_get_tar_file_names ${PART_BIN}
623
624 if [ "z${OLD_TAR_FILE}" = "z" ]; then
625         UPDATE_TYPE_S=(${UPDATE_TYPE//:/ })
626         if [ ! "${UPDATE_TYPE_S[0]}" = "FULL_IMAGE" ]; then
627                 echo "[old] tar file does not exist in ${DATA_DIR}/${OLD_TAR_DIR} which contains ${PART_BIN}"
628                 #exit 0, cos this is not an error.
629                 exit 0
630         fi
631 fi
632
633 if [ "z${NEW_TAR_FILE}" = "z" ]; then
634         echo "[new] tar file does not exist in ${DATA_DIR}/${NEW_TAR_DIR} which contains ${PART_BIN}"
635         exit 0
636 fi
637
638 if [ ! "z${OLD_TAR_FILE}" = "z" ]; then
639         echo "[old] ${OLD_TAR_FILE} contains ${PART_BIN}"
640 fi
641 echo "[new] ${NEW_TAR_FILE} contains ${PART_BIN}"
642
643
644 #--- generate delta binary ---
645
646 cd ${DATA_DIR} || exit 1
647
648 OUTPUT_DIR=${PART_NAME}_OUT
649 if [ ! -d ${OUTPUT_DIR} ]; then
650         if [ -f ${OUTPUT_DIR} ]; then
651                 sudo rm -f ${OUTPUT_DIR}
652         fi
653         mkdir ${OUTPUT_DIR}
654 fi
655
656 UPDATE_TYPE_S=(${UPDATE_TYPE//:/ })
657 if [ "${UPDATE_TYPE_S[0]}" = "FULL_IMAGE" ]; then
658         fn_mk_full_img
659 elif [ "${UPDATE_TYPE_S[0]}" = "DELTA_IMAGE" ]; then
660         fn_mk_delta_img
661 elif [ "${UPDATE_TYPE_S[0]}" = "DELTA_FS" ]; then
662         fn_mk_delta_fs
663 else
664         echo "Invalid update type"
665         exit 1
666 fi
667
668 exit 0