summaryrefslogtreecommitdiffstats
path: root/bashrc
blob: 4389b83ed86b1a1bcfe1eb219176e99f2d67457f (plain) (blame)
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
#!/bin/bash

# error
eecho() {
	case "x${NOCOLOR}" in
		x[y,Y][e,E][s,S]|x-[t,T][r,R][u,U][e,E]|x)
			echo -ne '\e[1;31m * \e[0m';;
		x*)
			echo -n " * ";;
	esac

	echo "$*"
}

# warning
wecho() {
	case "x${NOCOLOR}" in
		x[y,Y][e,E][s,S]|x-[t,T][r,R][u,U][e,E]|x)
			echo -ne '\e[1;33m * \e[0m';;
		x*)
			echo -n " * ";;
	esac

	echo "$*"
}

# positiv echo
pecho() {
	case "x${NOCOLOR}" in
		x[y,Y][e,E][s,S]|x-[t,T][r,R][u,U][e,E]|x)
			echo -ne '\e[1;32m * \e[0m';;
		x*)
			echo -n " * ";;
	esac

	echo "$*"
}

# info
iecho() {
	echo ">>> $*"
}

autopatch() {
	local diff level p patches patched 

	[[ ! -d "$PATCH_OVERLAY" ]] && return 0

	patches=$(ls -1 ${PATCH_OVERLAY}/${CATEGORY}/${PN}/${PN}-*.{patch,diff} 2>/dev/null)
	[[ $patches == "" ]] && return 0

	if ! cd ${S}; then
		eecho "FAILED TO cd $S"
		return 1
	fi

	for p in ${patches}; do
		p=$(basename $p)
		diff=${PATCH_OVERLAY}/${CATEGORY}/${PN}/${p}
		if [[ -e $diff ]] && [ ! -e ${S}/.${p} ]; then
			patched=0
			for level in 0 1 2 3 4; do
				if [[ $patched == 0 ]]; then
					patch -g0 --dry -p${level} >/dev/null < $diff
					if [ $? = 0 ]; then
						pecho "auto patching (-p${level}) ${p}"
						patch -g0 -p${level} < $diff > /dev/null && patched=1
						touch ${S}/.${p}
					fi
				fi
			done
			[[ $patched != 1 ]] && eecho "FAILED auto patching $p"
		else
			[[ ! -e $diff ]] && eecho "$diff does not exist, unable to auto patch"
		fi
	done
	cd $OLDPWD
}

#wecho "at $EBUILD_PHASE"

case $EBUILD_PHASE in
	compile)	
		if [[ ! -d "$PATCH_OVERLAY" ]]; then
			eecho "PATCH_OVERLAY=$PATCH_OVERLAY is not a dir"
		else
			iecho "Checking for auto patches in ${PATCH_OVERLAY}/${CATEGORY}/${PN} ..."
			PATH=$PATH:/usr/sbin:/usr/bin:/bin:/sbin
			autopatch
		fi
	;;
esac