new order controller to view orders, lots of bugfixes
[smr.git] / devel-tools / make-package.sh
blobb412fa87ef9d7036b3bf332f3693a4293aaf9d32
1 #!/bin/bash
3 # Create a SMR packages from git Repository.
5 # The basic procedure is:
6 # - work on a specific branch of tag in the git repo
7 # - search for debug code and warn
8 # - generate GNU ChangeLog files
9 # - make documentation
10 # - create tarball(s)
12 # Note: this script is 'raw' code and should only be used by developers.
15 # load configuration
16 . config
18 # check and assign params
19 if [ "$1" = '--help' ] || [ "$1" = '-h' ]; then
20 echo -e "usage: $0 [ TAG ] [ PREV_TAG ]\n\n"
21 echo -e " TAG - package code from this tag\n"
22 echo -e " PREV_TAG - use this tag as starting point for ChangeLog files\n"
23 exit 1
26 if [ -n "$1" ]; then
27 tag=$1
30 if [ -n "$2" ]; then
31 prev_tag=$2
34 ###############################################################################
36 # Functions
38 abort() {
39 echo -e "\n--> removing temp directory"
40 rm -rf $TMP
41 echo "--> exit"
42 exit
45 # usage: $1 = tag or branch name (or whatever else got show understands)
46 get_git_commit() {
47 REPLY=`$git show $1 | head -1 |cut -d" " -f 2`
48 if [ -n "$REPLY" ]; then
49 return 0
50 else
51 return 1
55 # usage: $1 = Ruby filename
56 # $2 = constant name
57 get_constant() {
58 REPLY=`grep -e ".*${2}.*=.*" ${1} |cut -d "'" -f 2`
60 if [ -n "$REPLY" ]; then
61 return 0
62 else
63 return 1
68 ###############################################################################
70 # Script Code
73 # initialize some paths
74 oldpwd=`pwd`
75 git=`which git`
76 git2cl=git2cl
77 rake=`which rake`
79 cd ${SMR_REPO}
81 # checkout tag (if given) and determine current commit
82 if [ -n "${tag}" ]; then
83 $git checkout ${tag}
84 else
85 tag=''
86 echo "--> no tag given - using whatever commit we are in"
87 fi
89 # make sure our store is there
90 package_store=${oldpwd}/${SMR_PACKAGES}
91 if [ ! -d $package_store ]; then
92 echo "--> create package store ${package_store}"
93 mkdir --parents $package_store
96 TMP=`mktemp -d /tmp/devel-tools.XXXXXX`
97 echo "--> temp dir is ${TMP}"
99 # determine the commit we are in
100 get_git_commit
101 commit=$REPLY
102 echo "--> discovered commit $commit"
104 echo "--> exporting code to temp dir"
105 $git archive $commit | tar --totals -x -C ${TMP}
107 ###############################################################################
109 # inspect the exported code tree
111 echo -e "\n==> INSPECTING SOURCE TREE in ${TMP}/"
112 cd ${TMP}
114 if [ ! -d "${SMR_GUI}" ] ; then
115 echo "--> exported dir structure is not as expected. Did the repository structure change?"
116 abort
120 if [ -d ${SMR_DAEMON} ]; then
121 echo "--> found Daemon directory. Will be packaged separately."
122 _build_daemon=1
125 if [ -d ${SMR_MANUAL} ]; then
126 echo "--> found Manual directory. Will be packaged separately."
127 _build_manual=1
128 else
129 echo " -> Manual directory not present, create it and attempt to build anyway"
130 mkdir manual/
131 _build_manual=1
134 if [ -d ${SMR_PLATFORM} ]; then
135 echo "--> found platform directory. Will be added to the raw source package."
136 _build_platform=1
140 # get version from sourcecode
141 if [ -e ${SMR_GUI}/config/application.rb ]; then
142 smr_config=${SMR_GUI}/config/application.rb
143 else
144 echo "!!> could not find config file with VERSION constant"
145 echo "!!> Note: versions until 0.5 did not have a version tag."
146 echo "!!> Therefore this script does not work for them."
147 abort
150 get_constant ${smr_config} VERSION
151 version="${REPLY}"
153 if [ -n "${version}" ]; then
154 echo "--> discovered version=${version} (from ${smr_config})"
155 else
156 echo "!!> could not extract release version from ${smr_config}"
157 abort
160 # rename config file templates
161 #if [ $_build_daemon ]; then
162 # if [ -e ${SMR_DAEMON}/smrd.conf.template ]; then
163 # echo "--> renaming Daemon config file template..."
164 # mv ${SMR_DAEMON}/smrd.conf.template ${SMR_DAEMON}/smrd.conf
166 # echo "--> updating release version in daemon code..."
167 # sed -i "s/__VERSION__/${version}/" ${SMR_DAEMON}/lib/SMR/Config.pm
168 # fi
171 # walk back into the repository
172 cd $GITREPO
174 # count FIXMEs
175 echo "--> count things to be fixed: "
176 for i in ${TMP}/${SMR_GUI} ${TMP}/${SMR_DAEMON}; do
177 echo " -> looking through $i"
178 grep --count --recursive -e 'FIXME' $i/* \
179 | awk -F':' '{s=s+$2; if($2>0){l++}} END{print s, "FIXMEs in", l, "files"}'
180 done
182 ###############################################################################
184 # make ChangeLog file(s)
186 echo -e "\n==> GENERATE CHANGELOGS"
187 if [ -n "$tag" ] && [ -n "${commit}" ]; then
188 echo "--> this release is: ${tag} -> commit ${commit}"
189 else
190 echo "--> this release is: *** untagged *** -> commit ${commit}"
193 if [ -z "${prev_tag}" ]; then
194 # figure what the previous tag *could* be
195 # - pretty trivial, but works most of the time.
196 # - if the result is not sufficient, specify the previous tag as second
197 # parameter
198 base=`echo $tag | sed 's/_[0-9]*$//'`
199 patchlevel=`echo $tag | sed 's/RELEASE_[0-9]*_[0-9]*_//'`
201 patchlevel=$((patchlevel-1))
203 if [ $patchlevel -gt -1 ]; then
204 prev_tag="${base}_${patchlevel}"
208 if [ -n "${prev_tag}" ]; then
209 get_git_commit ${prev_tag}
210 prev_commit=$REPLY
211 echo "--> previous release is: ${prev_tag} -> commit ${prev_commit}"
212 else
213 # fall back to when we went public
214 prev_commit=43496b57d517aca217d452317a34ab2401d9c330
215 echo "--> previous release is: *** unknown *** -> commit ${prev_commit} (assumed)"
218 echo "--> writing $SMR_GUI/CHANGELOG"
219 cd $SMR_REPO
220 $oldpwd/$git2cl $prev_commit $commit $SMR_GUI > $TMP/$SMR_GUI/CHANGELOG
222 if [ -n "$_build_daemon" ]; then
223 echo "--> writing $SMR_DAEMON/CHANGELOG"
224 $oldpwd/$git2cl $prev_commit $commit $SMR_DAEMON > $TMP/$SMR_DAEMON/CHANGELOG
227 ###############################################################################
229 # compile user & developer manual
231 if [ -n "$_build_manual" ] && [ -z "$rake" ]; then
232 echo "!!> rake command not found. Check that it is installed."
233 abort
236 if [ -n "$_build_manual" ]; then
237 echo -e "\n==> COMPILE MANUAL"
238 cd "$TMP/$SMR_GUI"
239 $rake doc:app &
240 wait
241 mv ./doc/* "$TMP/$SMR_MANUAL/"
242 rmdir ./doc
245 ###############################################################################
247 # build packages
248 # - one for the gui (rails app)
249 # - one for the daemon
250 # - one for the manual
251 echo -e "\n==> BUILD PACKAGES"
253 cd $TMP
254 if [ -n "${tag}" ]; then
255 package_src="${SMR_PACKAGE_SOURCE}-$version.tar.gz"
256 package_gui="${SMR_PACKAGE_GUI}-$version.tar.gz"
258 if [ -n "$_build_daemon" ]; then
259 package_daemon="${SMR_PACKAGE_DAEMON}-$version.tar.gz"
261 if [ -n "$_build_manual" ]; then
262 package_manual="${SMR_PACKAGE_MANUAL}-$version.tar.gz"
264 else
265 package_src="${SMR_PACKAGE_SOURCE}-${commit}.tar.gz"
266 package_gui="${SMR_PACKAGE_GUI}-${commit}.tar.gz"
268 if [ -n "$_build_daemon" ]; then
269 package_daemon="${SMR_PACKAGE_DAEMON}-${commit}.tar.gz"
271 if [ -n "$_build_manual" ]; then
272 package_manual="${SMR_PACKAGE_MANUAL}-${commit}.tar.gz"
276 echo "--> GUI package is: ${package_gui}"
277 tar --totals -zcf $package_store/$package_gui ${SMR_GUI}
279 if [ -n "$_build_daemon" ]; then
280 echo "--> Daemon package is: ${package_daemon}"
281 tar --totals -zcf $package_store/$package_daemon ${SMR_DAEMON}
284 if [ -n "$_build_manual" ]; then
285 echo "--> Manual package is: ${package_manual}"
286 tar --totals -zcf $package_store/$package_manual ${SMR_MANUAL}
289 ###############################################################################
291 # finally build the raw source package
292 # - this one is for further packaging (RPM, Deb, ...)
293 # - add platform specific files here
294 # - tradition says that raw sources should be stamped with versions to avoid
295 # conflicts on development systems and during further packaging... we do so
296 echo "--> SOURCE package is: ${package_src}"
297 echo "--> stamping versions..."
298 mv ${SMR_GUI} ${SMR_GUI}-${version}
300 if [ $_build_daemon ]; then
301 mv ${SMR_DAEMON} ${SMR_DAEMON}-${version}
304 if [ $_build_manual ]; then
305 mv ${SMR_MANUAL} ${SMR_MANUAL}-${version}
308 if [ $_build_platform ]; then
309 mv ${SMR_PLATFORM} ${SMR_PLATFORM}-${version}
312 # a little reminder...
314 echo
315 echo " SMR Raw Source Package"
316 echo
317 echo "This tarball contains raw sourcecode prepared for further packaging. It should"
318 echo "ONLY be used as basis for creating RPMs, Debs, ... or similar packages."
319 echo
320 echo "Please do NOT use it for PRODUCTION installations. Take one (or all) of the files"
321 echo "below for manual installation:"
322 echo
323 echo " - ${package_gui}"
324 echo " - ${package_daemon}"
325 echo " - ${package_manual}"
326 echo
327 echo "or just use the final RPM, Deb, ... packages."
328 echo
329 } > IMPORTANT
331 tar --totals --exclude=devel-tools -zcf $package_store/$package_src *
333 # we are done
334 abort