#!/bin/bash # Description: This shell script used to generate patch file # Author: guowenxue # Version: 1.0.0 # this project absolute path PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd) # top project absolute path TOP_PATH=$(realpath $PRJ_PATH/..) # config file path CONF_FILE=$TOP_PATH/config.json # download taballs path TARBALL_PATH=$PRJ_PATH/tarballs # shell script will exit once get command error #set -e #+-------------------------+ #| Shell script functions | #+-------------------------+ function pr_error() { echo -e "\033[40;31m $1 \033[0m" } function pr_warn() { echo -e "\033[40;33m $1 \033[0m" } function pr_info() { echo -e "\033[40;32m $1 \033[0m" } # decompress a packet to destination path function do_unpack() { tarball=$1 dstpath=`pwd` if [[ $# == 2 ]] ; then dstpath=$2 fi pr_info "decompress $tarball => $dstpath" mkdir -p $dstpath case $tarball in *.tar.gz) tar -xzf $tarball -C $dstpath ;; *.tar.bz2) tar -xjf $tarball -C $dstpath ;; *.tar.xz) tar -xJf $tarball -C $dstpath ;; *.tar.zst) tar -I zstd -xf $tarball -C $dstpath ;; *.tar) tar -xf $tarball -C $dstpath ;; *.zip) unzip -qo $tarball -d $dstpath ;; *) pr_error "decompress Unsupport packet: $tarball" return 1; ;; esac } # parser configure file and export environment variable function export_env() { export SRC=$(basename $1) export BOARD=`jq -r ".bsp.board" $CONF_FILE | tr 'A-Z' 'a-z'` export BSP_VER=`jq -r ".bsp.version" $CONF_FILE | tr 'A-Z' 'a-z'` export CROSS_COMPILE=`jq -r ".bsp.crosstool" $CONF_FILE` export PATCH=$SRC-$BSP_VER.patch } function do_clean() { cd $SRC make mrproper CROSS_COMPILE=${CROSS_COMPILE} cd $PRJ_PATH } function do_patch() { if [ ! -d $PRJ_PATH/$SRC ] ; then pr_error "\nERROR: source code $SRC not exist, exit now\n\n" exit; fi # rename new source code mv ${SRC} ${SRC}-${BOARD} # decompress orignal soruce code packet do_unpack ${TARBALL_PATH}/${SRC}.tar.xz pr_info "generate patch file $PATCH" # generate patch file diff -Nuar ${SRC} ${SRC}-${BOARD} > $PATCH # remove orignal soruce code rm -rf ${SRC} # recover new source code mv ${SRC}-${BOARD} ${SRC} } if [ $# != 1 ] ; then pr_info "$0 usage example:" pr_info "$0 at91bootstrap" pr_info "$0 u-boot-at91" exit fi export_env $1 do_clean do_patch