forked from NLnetLabs/nsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makedist.sh
executable file
·244 lines (201 loc) · 6.94 KB
/
makedist.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/bin/sh
# Build a NSD distribution tar from the git repository.
# Abort script on unexpected errors.
set -e
# Remember the current working directory.
cwd=`pwd`
# Utility functions.
usage () {
cat >&2 <<EOF
Usage $0: [-h] [-s] [-u git_url] [-b git_branch]
Generate a distribution tar file for NSD.
-h This usage information.
-s Build a snapshot distribution file. The current date is
automatically appended to the current NSD version number.
-rc <nr> Build a release candidate, the given string will be added
to the version number (nsd-<version>rc<number>).
-u git_url Retrieve the NSD source from the specified repository.
If not specified, the url is detected from the
working directory.
-b git_branch Retrieve the specified branch or tag.
If not specified, the current branch is detected from the
working directory.
EOF
exit 1
}
info () {
echo "$0: info: $1"
}
error () {
echo "$0: error: $1" >&2
exit 1
}
question () {
printf "%s (y/n) " "$*"
read answer
case "$answer" in
[Yy]|[Yy][Ee][Ss])
return 0
;;
*)
return 1
;;
esac
}
# Only use cleanup and error_cleanup after generating the temporary
# working directory.
cleanup () {
info "Deleting temporary working directory."
cd $cwd && rm -rf $temp_dir
}
error_cleanup () {
echo "$0: error: $1" >&2
cleanup
exit 1
}
replace_text () {
(cp "$1" "$1".orig && \
sed -e "s/$2/$3/g" < "$1".orig > "$1" && \
rm "$1".orig) || error_cleanup "Replacement for $1 failed."
}
replace_all () {
info "Updating '$1' with the version number."
replace_text "$1" "@version@" "$version"
info "Updating '$1' with today's date."
replace_text "$1" "@date@" "`date +'%b %e, %Y'`"
}
SNAPSHOT="no"
RC="no"
# Parse the command line arguments.
while [ "$1" ]; do
case "$1" in
"-h")
usage
;;
"-u")
GITREPO="$2"
shift
;;
"-b")
GITBRANCH="$2"
shift
;;
"-rc")
RC="$2"
shift
;;
"-s")
SNAPSHOT="yes"
;;
*)
error "Unrecognized argument -- $1"
;;
esac
shift
done
# Check if GITREPO is specified.
if [ -z "$GITREPO" ]; then
if git status 2>&1 | grep "not a git repository" >/dev/null; then
error "GITREPO must be specified (using -u) or use settings detected by starting from working copy directory"
else
GITREPO="`git config --get remote.origin.url`"
fi
fi
if [ -z "$GITBRANCH" ]; then
if git status 2>&1 | grep "not a git repository" >/dev/null; then
error "specify branch (using -b) or use settings detected by starting from working copy directory"
else
GITBRANCH="`git branch | grep '^\*' | sed -e 's/^\* //'`"
fi
fi
# Start the packaging process.
info "GITREPO is $GITREPO"
info "GITBRANCH is $GITBRANCH"
info "SNAPSHOT is $SNAPSHOT"
info "RELEASE CANDIDATE is $RC"
#question "Do you wish to continue with these settings?" || error "User abort."
# Creating temp directory
info "Creating temporary working directory"
temp_dir=`mktemp -t -d nsd-dist-XXXXXX`
info "Directory '$temp_dir' created."
cd $temp_dir
info "Exporting source from git."
# --depth=1 and --no-tags reduce the download size.
info "git clone --depth=1 --no-tags -b $GITBRANCH $GITREPO nsd"
git clone --depth=1 --no-tags -b $GITBRANCH $GITREPO nsd || error_cleanup "git clone command failed"
cd nsd || error_cleanup "NSD not exported correctly from git"
git submodule update --init || error_cleanup "Could not fetch submodule"
rm -rf .git .cirrus.yml .github .gitignore || error_cleanup "Failed to remove .git tracking and ci information"
rm -rf simdzone/.git simdzone/.github simdzone/.gitignore \
simdzone/cmake simdzone/CMakeLists.txt simdzone/simdzoneConfig.cmake.in \
simdzone/conanfile.txt simdzone/tests simdzone/.readthedocs.yaml \
simdzone/doc simdzone/scripts || \
error_cleanup "Failed to remove simdzone .git tracking and ci information"
info "Building configure script (autoreconf)."
autoreconf -i || error_cleanup "Autoconf failed."
info "Building config.h.in (autoheader)."
autoheader || error_cleanup "Autoheader failed."
rm -r autom4te* || error_cleanup "Failed to remove autoconf cache directory."
rm -r simdzone/autom4te* || error_cleanup "Failed to remove simdzone autoconf cache directory."
rm -f simdzone/src/config.h.in~ || echo "ignore absence of simdzone/src/config.h.in~ file"
info "Building lexer and parser."
echo "#include \"config.h\"" > configlexer.c || error_cleanup "Failed to create configlexer"
flex -P c_ -i -t configlexer.lex >> configlexer.c || error_cleanup "Failed to create configlexer"
bison -y -d -p c_ -o configparser.c configparser.y || error_cleanup "Failed to create configparser"
find . -name .c-mode-rc.el -exec rm {} \;
find . -name .cvsignore -exec rm {} \;
rm makedist.sh || error_cleanup "Failed to remove makedist.sh."
info "Determining NSD version."
version=`./configure --version | head -1 | awk '{ print $3 }'` || \
error_cleanup "Cannot determine version number."
info "NSD version: $version"
if [ "$RC" != "no" ]; then
info "Building NSD release candidate."
version="${version}rc$RC"
info "Release candidate version number: $version"
fi
if [ "$SNAPSHOT" = "yes" ]; then
info "Building NSD snapshot."
version="$version-`date +%Y%m%d`"
info "Snapshot version number: $version"
fi
replace_all doc/README
replace_all nsd.8.in
replace_all nsd-control.8.in
replace_all nsd-checkconf.8.in
replace_all nsd-checkzone.8.in
replace_all nsd.conf.5.in
info "Renaming NSD directory to nsd-$version."
cd ..
mv nsd nsd-$version || error_cleanup "Failed to rename NSD directory."
tarfile="$cwd/nsd-$version.tar.gz"
if [ -f $tarfile ]; then
(question "The file $tarfile already exists. Overwrite?" \
&& rm -f $tarfile) || error_cleanup "User abort."
fi
info "Deleting the tpkg directory"
rm -rf nsd-$version/tpkg/
info "Creating tar nsd-$version.tar.gz"
tar czf $tarfile nsd-$version || error_cleanup "Failed to create tar file."
info "Checking for required auxiliary files"
cd nsd-$version
CC=./non-existent-cc ./configure --quiet --no-create 2>&1 | head -n 1 | grep auxiliary && \
error_cleanup "Required auxiliary files not available"
cleanup
case $OSTYPE in
FreeBSD*)
sha=`sha1 $tarfile | awk '{ print $5 }'`
sha256=`sha256 $tarfile | awk '{ print $5 }'`
;;
*)
sha=`sha1sum $tarfile | awk '{ print $1 }'`
sha256=`sha256sum $tarfile | awk '{ print $1 }'`
;;
esac
echo $sha > $cwd/nsd-$version.tar.gz.sha1
echo $sha256 > $cwd/nsd-$version.tar.gz.sha256
echo "create nsd-$version.tar.gz.asc with:"
echo " gpg --armor --detach-sign --digest-algo SHA256 nsd-$version.tar.gz"
info "NSD distribution created successfully."
info "SHA1sum: $sha"
info "SHA256sum: $sha256"