-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbranchHelper.sh
executable file
·224 lines (214 loc) · 5.56 KB
/
branchHelper.sh
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash
#
# branch4release.sh
#
#
# 2011 nubecoder
# http://www.nubecoder.com/
#
#define version string
CURRENT_VERSION="nubernel-2.6.32_v1.0.1"
VERSION_STRING="nubernel-2.6.32_v"
# defaults
RELEASE="n"
FEATURE="n"
VERBOSE="n"
# define vars
NEW_VERSION=
FEATURE_NAME=
ERROR_MSG=
# functions
SHOW_HELP()
{
echo "=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]"
echo "Usage options for $0:"
echo "-f : Checkout a new feature branch."
echo " Example: -f overclock"
echo "-h : Print this help info."
echo "-r : Checkout a new release branch."
echo " Example: -r 0.0.1."
echo "-v : Verbose mode."
echo "=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]"
exit 1
}
SHOW_SETTINGS()
{
echo "=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]"
if [ "$RELEASE" = "y" ]
then
echo "Old Version == $CURRENT_VERSION"
echo "Vew Version == ${VERSION_STRING}$NEW_VERSION"
echo "Verbose Mode == $VERBOSE"
fi
if [ "$FEATURE" = "y" ]
then
echo "Feature Name == $FEATURE_NAME"
echo "Verbose Mode == $VERBOSE"
fi
echo "=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]"
echo "*"
}
SHOW_COMPLETED()
{
echo "=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]"
echo "Script completed."
echo "=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]"
exit
}
SHOW_ERROR()
{
if [ -n "$ERROR_MSG" ] ; then
echo "=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]"
echo "$ERROR_MSG"
fi
}
BRANCH_RELEASE()
{
echo "=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]"
# start time
local T1=$(date +%s)
echo "Begin release branch..." && echo ""
# checkout new branch (always from dev)
local RESULT=$(git checkout -b release-v${NEW_VERSION} dev 2>&1 >/dev/null)
# check for errors
local FIND_ERR="error: "
if [ "$RESULT" != "${RESULT/$FIND_ERR/}" ]
then
ERROR_MSG=${RESULT/$FIND_ERR/}
SHOW_ERROR
SHOW_COMPLETED
fi
# update files
local PATTERN="$CURRENT_VERSION"
local REPLACEMENT="${VERSION_STRING}$NEW_VERSION"
if [ "$VERBOSE" = "y" ]
then
sed -i "s/$PATTERN/$REPLACEMENT/g" build_kernel.sh
sed -i "s/$PATTERN/$REPLACEMENT/g" initramfs/default.prop
sed -i "s/$PATTERN/$REPLACEMENT/g" update/META-INF/com/google/android/updater-script
sed -i "s/$PATTERN/$REPLACEMENT/g" update/META-INF/com/android/metadata
sed -i "s/$PATTERN/$REPLACEMENT/g" ncBuildHelper.sh
sed -i "s/$PATTERN/$REPLACEMENT/g" featurelist
sed -i "s/$PATTERN/$REPLACEMENT/g" changelog
sed -i "s/$PATTERN/$REPLACEMENT/g" README
sed -i "s/$PATTERN/$REPLACEMENT/g" $0
else
sed -i "s/$PATTERN/$REPLACEMENT/g" build_kernel.sh
sed -i "s/$PATTERN/$REPLACEMENT/g" initramfs/default.prop >/dev/null 2>&1
sed -i "s/$PATTERN/$REPLACEMENT/g" update/META-INF/com/google/android/updater-script >/dev/null 2>&1
sed -i "s/$PATTERN/$REPLACEMENT/g" update/META-INF/com/android/metadata >/dev/null 2>&1
sed -i "s/$PATTERN/$REPLACEMENT/g" ncBuildHelper.sh >/dev/null 2>&1
sed -i "s/$PATTERN/$REPLACEMENT/g" featurelist >/dev/null 2>&1
sed -i "s/$PATTERN/$REPLACEMENT/g" changelog >/dev/null 2>&1
sed -i "s/$PATTERN/$REPLACEMENT/g" README >/dev/null 2>&1
sed -i "s/$PATTERN/$REPLACEMENT/g" $0 >/dev/null 2>&1
fi
# git add changes
if [ "$VERBOSE" = "y" ]
then
git add build_kernel.sh
git add initramfs/default.prop
git add update/META-INF/com/google/android/updater-script
git add update/META-INF/com/android/metadata
git add ncBuildHelper.sh
git add featurelist
git add changelog
git add README
git add $0
else
git add build_kernel.sh >/dev/null 2>&1
git add initramfs/default.prop >/dev/null 2>&1
git add update/META-INF/com/google/android/updater-script >/dev/null 2>&1
git add update/META-INF/com/android/metadata >/dev/null 2>&1
git add ncBuildHelper.sh >/dev/null 2>&1
git add featurelist >/dev/null 2>&1
git add changelog >/dev/null 2>&1
git add README >/dev/null 2>&1
git add $0 >/dev/null 2>&1
fi
# show some info
echo "git status -s:"
git status -s
echo "git branch:"
git branch
# git commit
local BRANCH_MSG="Branched to 'release-v${NEW_VERSION}'."
echo "Commit:"
git commit -m "$BRANCH_MSG"
echo "$BRANCH_MSG"
# end time
local T2=$(date +%s)
echo "" && echo "Release branch took $(($T2 - $T1)) seconds."
echo "=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]"
echo "*"
}
BRANCH_FEATURE()
{
echo "=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]"
# start time
local T1=$(date +%s)
echo "Begin feature branch..." && echo ""
# checkout new branch (always from dev)
local RESULT=$(git checkout -b feature-${FEATURE_NAME} dev 2>&1 >/dev/null)
# check for errors
local FIND_ERR="error: "
if [ "$RESULT" != "${RESULT/$FIND_ERR/}" ]
then
ERROR_MSG=${RESULT/$FIND_ERR/}
SHOW_ERROR
SHOW_COMPLETED
fi
# show some info
echo "git status -s:"
git status -s
echo "git branch:"
git branch
echo "Branched to 'feature-${FEATURE_NAME}'."
# end time
local T2=$(date +%s)
echo "" && echo "Feature branch took $(($T2 - $T1)) seconds."
echo "=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]=]"
echo "*"
}
# main
while getopts ":f:hr:v" flag
do
case "$flag" in
f)
FEATURE="y"
RELEASE="n"
FEATURE_NAME="$OPTARG"
;;
h)
SHOW_HELP
;;
r)
FEATURE="n"
RELEASE="y"
NEW_VERSION="$OPTARG"
;;
v)
VERBOSE="y"
;;
*)
ERROR_MSG="Error:: problem with option '$OPTARG'"
SHOW_ERROR
SHOW_HELP
;;
esac
done
if [ "$RELEASE" = "y" ]
then
SHOW_SETTINGS
BRANCH_RELEASE
fi
if [ "$FEATURE" = "y" ]
then
SHOW_SETTINGS
BRANCH_FEATURE
fi
if [ "$RELEASE" = "n" -a "$FEATURE" = "n" ]
then
SHOW_HELP
fi
SHOW_COMPLETED