yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | echo $# |
| 4 | |
| 5 | if [ $# -lt 3 ]; then |
| 6 | echo "$0 app_list_file rootfs_dir kernel_dir" |
| 7 | exit 1 |
| 8 | fi |
| 9 | APP_LIST_FILE=$1 |
| 10 | ROOTFS_DIR=$2 |
| 11 | KERNEL_DIR=$3 |
| 12 | |
| 13 | if [ ! -f $APP_LIST_FILE ]; then |
| 14 | echo "$APP_LIST_FILE NOT exist" |
| 15 | exit 2 |
| 16 | fi |
| 17 | |
| 18 | if [ ! -d $KERNEL_DIR ]; then |
| 19 | echo "$KERNEL_DIR NOT exist" |
| 20 | exit 3 |
| 21 | fi |
| 22 | |
| 23 | if [ ! -d $ROOTFS_DIR ]; then |
| 24 | echo "$ROOTFS_DIR NOT exist" |
| 25 | exit 4 |
| 26 | fi |
| 27 | VERIFY_APP_HEADER=$KERNEL_DIR/include/linux/verify_app.h |
| 28 | |
| 29 | file_array=() |
| 30 | hash_array=() |
| 31 | file_cnt=0 |
| 32 | while read file_item; do |
| 33 | if [ -f ${ROOTFS_DIR}${file_item} ]; then |
| 34 | hash_val=`sha256sum ${ROOTFS_DIR}${file_item} | awk '{ print $1 }'` |
| 35 | echo "${file_item} $hash_val ok" |
| 36 | file_array+=("$file_item") |
| 37 | hash_array+=("$hash_val") |
| 38 | let "file_cnt=file_cnt+1" |
| 39 | else |
| 40 | echo "regular file ${ROOTFS_DIR}${file_item} NOT exist" |
| 41 | exit 9 |
| 42 | fi |
| 43 | done < "${APP_LIST_FILE}" |
| 44 | |
| 45 | # 打印数组中的数据 |
| 46 | |
| 47 | echo "#ifndef __VERIFY_APP_H" > $VERIFY_APP_HEADER |
| 48 | echo "#define __VERIFY_APP_H" >> $VERIFY_APP_HEADER |
| 49 | echo "" >> $VERIFY_APP_HEADER |
| 50 | |
| 51 | echo "const int g_verify_app_cnt = $file_cnt;" >> $VERIFY_APP_HEADER |
| 52 | echo "const char *g_verify_file_array[] = {" >> $VERIFY_APP_HEADER |
| 53 | for element in "${file_array[@]}"; do |
| 54 | echo " \"$element\"," >> $VERIFY_APP_HEADER |
| 55 | done |
| 56 | echo "};" >> $VERIFY_APP_HEADER |
| 57 | |
| 58 | echo "const char *g_verify_hash_array[] = {" >> $VERIFY_APP_HEADER |
| 59 | for element in "${hash_array[@]}"; do |
| 60 | echo " \"$element\"," >> $VERIFY_APP_HEADER |
| 61 | done |
| 62 | echo "};" >> $VERIFY_APP_HEADER |
| 63 | |
| 64 | echo "" >> $VERIFY_APP_HEADER |
| 65 | echo "#endif" >> $VERIFY_APP_HEADER |