-
Notifications
You must be signed in to change notification settings - Fork 0
/
autogen.sh
executable file
·181 lines (137 loc) · 4.05 KB
/
autogen.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
#!/bin/bash
exname="$(basename "$0")"
##
## Functions
##
function get_path() {
local type
type="$(type -t "$1")"
case $type in
("file")
type -p "$1"
return 0
;;
("function" | "builtin" )
echo "$1"
return 0
;;
esac
return 1
}
function print_exit() {
echo $@
exit 1
}
function print_syntax_error() {
[ "$*" ] || print_syntax_error "$FUNCNAME: no arguments"
print_exit "${ERROR}script error:${NORMAL} $@" >&2
}
function print_syntax_warning() {
[ "$*" ] || print_syntax_error "$FUNCNAME: no arguments."
[ "$exname" ] || print_syntax_error "$FUNCNAME: 'exname' var is null or not defined."
echo "$exname: ${WARNING}script warning:${NORMAL} $@" >&2
}
function print_error() {
[ "$*" ] || print_syntax_warning "$FUNCNAME: no arguments."
[ "$exname" ] || print_exit "$FUNCNAME: 'exname' var is null or not defined." >&2
print_exit "$exname: ${ERROR}error:${NORMAL} $@" >&2
}
function depends() {
local i tr path
tr=$(get_path "tr")
test "$tr" ||
print_error "dependency check : couldn't find 'tr' command."
for i in $@ ; do
if ! path=$(get_path $i); then
new_name=$(echo $i | "$tr" '_' '-')
if [ "$new_name" != "$i" ]; then
depends "$new_name"
else
print_error "dependency check : couldn't find '$i' command."
fi
else
if ! test -z "$path" ; then
export "$(echo $i | "$tr" '-' '_')"=$path
fi
fi
done
}
function die() {
[ "$*" ] || print_syntax_warning "$FUNCNAME: no arguments."
[ "$exname" ] || print_exit "$FUNCNAME: 'exname' var is null or not defined." >&2
print_exit "$exname: ${ERROR}error:${NORMAL} $@" >&2
}
##
## Code
##
depends git grep date
## BSD / GNU sed compatibility layer
if (type -p sed && sed --version) >/dev/null 2>&1; then
sed="$(type -p sed)"
else
if (type -p gsed && gsed --version) >/dev/null 2>&1; then
sed="$(type -p gsed)"
else
print_error "$exname: required GNU sed not found"
fi
fi
## BSD / GNU date compatibility layer
if (type -p date && date --version) >/dev/null 2>&1 ; then
date="$(type -p date)"
else
if (type -p gdate && gdate --version) >/dev/null 2>&1; then
date="$(type -p gdate)"
else
print_error "$exname: required GNU date not found"
fi
fi
gitchangelog=./gitchangelog.py
if ! test -e "setup.py" >/dev/null 2>&1; then
die "No 'setup.py'... this script is meant to work with a python project"
fi
if ! "$git" describe >/dev/null 2>&1; then
die "Didn't find a git repository. autogen.sh uses git to create changelog \
and version information."
fi
function matches() {
echo "$1" | "$grep" -E "^$2\$" >/dev/null 2>&1
}
long_tag="[0-9]+\.[0-9]+(\.[0-9]+)?-[0-9]+-[0-9a-f]+"
short_tag="[0-9]+\.[0-9]+(\.[0-9]+)?"
get_short_tag="s/^($short_tag).*\$/\1/g"
function get_current_git_date_timestamp() {
"$git" show -s --pretty=format:%ct
}
function dev_version_tag() {
"$date" -d "@$(get_current_git_date_timestamp)" +%Y%m%d%H%M
}
function get_current_version() {
version=$("$git" describe --tags)
if matches "$version" "$short_tag"; then
echo "$version"
else
version=$(echo "$version" | "$sed" -r "$get_short_tag")
echo "${version}.1dev_r$(dev_version_tag)"
fi
}
function set_version_setup_py() {
version=$(get_current_version)
short_version=$(echo "$version" | cut -f 1,2,3 -d ".")
"$sed" -ri "s/%%version%%/$version/g" setup.py \
CHANGELOG.rst &&
"$sed" -ri "s/%%short-version%%/${short_version}/g" \
setup.py \
CHANGELOG.rst &&
echo "Version updated to $version."
}
GITCHANGELOG_CONFIG_FILENAME=./gitchangelog.rc.sample "$gitchangelog" > CHANGELOG.rst
if [ "$?" != 0 ]; then
(echo -n "Changelog NOT generated. "
echo "An error occured while running \`\`gitchangelog\`\`." )>&2
else
echo "Changelog generated."
fi
set_version_setup_py
if [ "$?" != 0 ]; then
print_error "Error while updating version information."
fi