summaryrefslogtreecommitdiff
path: root/bin/mutt_hooks.sh
blob: 36ecbf657559a52c17433863d5b08dec35941e1e (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
#!/bin/bash

email=$1
patch=/tmp/$$.patch
tempfile=/tmp/item_menu.$$
KERNEL_SOURCE=/home/cmaiolin/Source/kernel/linux.pristine/



clear_repo(){
	dialog --clear --yesno \
	" Wanna reset the git tree?" 0 0

	if [ $? -eq 0 ]; then
		git reset --hard
	fi
}

diff_patch(){

UPSTREAM_PATCH=/tmp/upstream.patch
UPSTREAM_COMMIT=/tmp/upstream.commit

	#get commit from message
	cat $1 | grep "^commit"| awk '{for (I=1;I<=NF;I++) if ($I == "commit") {print $(I+1)};}' | sed 's/)//' > $UPSTREAM_COMMIT

	# commit probably cherry-picked
	if [ -z `cat $UPSTREAM_COMMIT` ]; then

		cat $1 | grep "commit"| awk '{for (I=1;I<=NF;I++) if ($I == "commit") {print $(I+1)};}' | sed 's/)//' > $UPSTREAM_COMMIT

	fi
	#COMMIT=`cat $1 | grep "commit"| awk '{for (I=1;I<=NF;I++) if ($I == "commit") {print $(I+1)};}' | awk -F'|' '{print $1}' | sed 's/)//'`

	COMMIT=`cat $UPSTREAM_COMMIT |head -1`
	echo $COMMIT
	#Extract upstream patch
	echo "Entering source"
	cd $KERNEL_SOURCE
	echo "Extracting patch"
	git format-patch --stdout -1 $COMMIT > $UPSTREAM_PATCH
	echo $UPSTREAM_PATCH
	cd -
	echo "STARTING DIFF"
	vimdiff $patch $UPSTREAM_PATCH

	rm $UPSTREAM_PATCH $UPSTREAM_COMMIT
}

apply_patch(){
	repolist=$(ls $sources | awk '{print $1,$1}')

	dialog --clear --menu "Select repository to apply the patch" 0 0 20 $repolist 2> $tempfile
	#"Select repository to apply the patch" 30 60 20 $repolist 2> $tempfile

	repo=`cat $tempfile`

	echo $repo
	cd $sources/$repo
	git apply $patch
	#diff_patch
	clear_repo
}

clear_env(){
	rm -rf $tempfile
	rm -rf $patch
}

###main

cat $email | formail -I "" > $patch
diff_patch $patch
#cat $email | formail -I "" | awk '/^---/{p=1}p' > /tmp/patch.patch
rm $patch
#apply_patch
#clear_env