commit | author | age
|
849fbd
|
1 |
#!/bin/bash |
G |
2 |
# Description: This shell script used to generate patch file |
|
3 |
# Author: guowenxue <guowenxue@gmail.com> |
|
4 |
# Version: 1.0.0 |
|
5 |
|
|
6 |
# this project absolute path |
|
7 |
PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd) |
|
8 |
|
|
9 |
# top project absolute path |
|
10 |
TOP_PATH=$(realpath $PRJ_PATH/..) |
|
11 |
|
|
12 |
# config file path |
|
13 |
CONF_FILE=$TOP_PATH/config.json |
|
14 |
|
|
15 |
# shell script will exit once get command error |
|
16 |
#set -e |
|
17 |
|
|
18 |
#+-------------------------+ |
|
19 |
#| Shell script functions | |
|
20 |
#+-------------------------+ |
|
21 |
|
|
22 |
function pr_error() { |
|
23 |
echo -e "\033[40;31m $1 \033[0m" |
|
24 |
} |
|
25 |
|
|
26 |
function pr_warn() { |
|
27 |
echo -e "\033[40;33m $1 \033[0m" |
|
28 |
} |
|
29 |
|
|
30 |
function pr_info() { |
|
31 |
echo -e "\033[40;32m $1 \033[0m" |
|
32 |
} |
|
33 |
|
|
34 |
# parser configure file and export environment variable |
|
35 |
function export_env() |
|
36 |
{ |
|
37 |
export SRC=$(basename $1) |
|
38 |
export BSP_VER=`jq -r ".bsp.version" $CONF_FILE | tr 'A-Z' 'a-z'` |
|
39 |
export PATCH=$SRC-$BSP_VER |
|
40 |
} |
|
41 |
|
|
42 |
function do_patch() |
|
43 |
{ |
|
44 |
if [ ! -d $PRJ_PATH/$SRC ] ; then |
|
45 |
pr_error "\nERROR: source code $SRC not exist, exit now\n\n" |
|
46 |
exit; |
|
47 |
fi |
|
48 |
|
|
49 |
pr_info "generate patch file" |
|
50 |
|
|
51 |
cd $PRJ_PATH/$SRC |
|
52 |
|
|
53 |
git add .gitignore |
|
54 |
git add * 2> /dev/null |
|
55 |
|
|
56 |
git diff --cached > $PRJ_PATH/$PATCH.patch |
|
57 |
} |
|
58 |
|
|
59 |
if [ $# != 1 ] ; then |
|
60 |
pr_info "$0 usage example:" |
|
61 |
pr_info "$0 linux-imx/" |
|
62 |
exit |
|
63 |
fi |
|
64 |
|
|
65 |
export_env $1 |
|
66 |
do_patch |