summaryrefslogtreecommitdiffstats
path: root/scripts/check-patchlist.sh
blob: 134e41e971d389472e2ceeed20b8ada8ab99865b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#! /bin/sh
# This script was created in a effort to make patch management a bit easier.
# It list all the patches in the current tree and identifies if they are
# present in the kernel.spec, PatchList.txt, both files or neither.
#
# eg. ./check-patchlist.sh [optional flag]

function usage(){
    echo "List all the patches currently in the tree. It also helps identify"
    echo "if the patch is present in kernel.spec or PatchList.txt.          "
    echo "-h, --help                                                        "
    echo "-t, --tracked       patches in both kernel.spec and PatchList.txt "
    echo "-p, --patchlist     patches added to PatchList.txt.               "
    echo "-s, --specfile      patches added to kernel.spec.                 "
    echo "-n, --not-tracked   patches in the tree but not  in PatchList.txt "
    echo "                     or kernel.spec                               "
}

BASEDIR=$(dirname "$( cd $(dirname $BASH_SOURCE[0]) && pwd)")
pushd $BASEDIR > /dev/null

function list_all(){
    echo "===========Legend==========================="
    echo ".   In kernel.spec                          "
    echo "*   In PatchList.txt                        "
    echo "+   In PatchList.txt & Kernel.spec          "
    echo "-   Neither in PatchList.txt nor kernel.spec"
    echo "============================================"
    for patch in $(ls *.patch); do
	if [ ! -z "$(grep $patch PatchList.txt)" ] && [ ! -z "$(grep $patch kernel.spec)" ]
	then
	    echo "+ ${patch}" # Patches in kernel.spec and PatchList.txt

	elif [ ! -z "$(grep $patch PatchList.txt)" ] && [ -z "$(grep $patch kernel.spec)" ]
	then
	     echo "* ${patch}" # Patches in PatchList.txt but not in kernel.spec

	elif [ -z "$(grep $patch PatchList.txt)" ] && [ ! -z "$(grep $patch kernel.spec)" ]
	then
	    echo ". ${patch}" # Patches in kernel.spec but not in PatchList.txt

	else
	    echo "- ${patch}" # Neither in PatchList.txt nor kernel.spec

	fi
    done
}

function list_present_not_added(){
    for patch in $(ls *.patch); do
	if [ -z "$(grep $patch PatchList.txt)" ] && [ -z "$(grep $patch kernel.spec)" ]
	then
	    echo $patch
	fi
    done
}

function list_present_added(){
    for patch in $(ls *.patch); do
	if [ ! -z "$(grep $patch PatchList.txt)" ] && [ ! -z "$(grep $patch kernel.spec)" ]
	then
	    echo $patch
	fi
    done
}

function list_patchList(){
    for patch in $(ls *.patch); do
	if [ ! -z "$(grep $patch PatchList.txt)" ] && [ -z "$(grep $patch kernel.spec)" ]
	then
	    echo $patch
	fi
    done

}
function list_specfile(){
    for patch in $(ls *.patch); do
	if [ -z "$(grep $patch PatchList.txt)" ] && [ ! -z "$(grep $patch kernel.spec)" ]
	then
	    echo $patch
	fi
    done
}

if [ -z "$@" ]; then
    list_all
else

    for opt in "$@"; do
	case $opt in
	    -t|--tracked)
		list_present_added
		;;
	    -s|--specfile)
		list_specfile
		;;
	    -h|--help)
		usage
		;;
	    -n|--not-added)
		list_present_not_added
		;;
	    -p|--patchlist)
		list_patchList
		;;
	    *)
		usage
		;;
	esac
    done
fi

popd > /dev/null