tools/release-tarball.sh: full script rewrite
[nautilus-actions.git] / tools / release-tarball.sh
blobb66d8648c9b9470f3e3282b421e9cacd0ee5f308
1 #!/bin/sh
2 # Nautilus-Actions
3 # A Nautilus extension which offers configurable context menu actions.
5 # Copyright (C) 2005 The GNOME Foundation
6 # Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7 # Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
9 # This Program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; either version 2 of
12 # the License, or (at your option) any later version.
14 # This Program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public
20 # License along with this Library; see the file COPYING. If not,
21 # write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307, USA.
24 # Authors:
25 # Frederic Ruaudel <grumz@grumz.net>
26 # Rodrigo Moya <rodrigo@gnome-db.org>
27 # Pierre Wieser <pwieser@trychlos.org>
28 # ... and many others (see AUTHORS)
30 errs=0 # will be the exit code of the script
31 my_cmd="${0}" # e.g. "./make-ks.sh"
32 my_parms="$*" # e.g. "-host toaster"
33 my_cmdline="${my_cmd} ${my_parms}"
34 me="$(basename ${my_cmd})" # e.g. "make-ks.sh"
35 # used in msg and msgerr functions
36 my_tmproot="/tmp/$(echo ${me} | sed 's?\..*$??').$$"
37 # e.g. "/tmp/make-ks.1978"
39 # These three functions must be defined using the name() syntax in order
40 # to share traps with the caller process (cf. man (1) ksh).
42 trap_exit()
44 clear_tmpfiles
45 [ "${opt_verbose}" = "yes" -o ${errs} -gt 0 ] && msg "exiting with code ${errs}"
46 exit ${errs}
49 trap_int()
51 msg "quitting on keyboard interrupt"
52 let errs+=1
53 exit
56 trap_term()
58 [ "${opt_verbose}" = "yes" ] && msg "quitting on TERM signal"
59 exit
62 # setup the different trap functions
63 trap 'trap_term' TERM
64 trap 'trap_int' INT
65 trap 'trap_exit' EXIT
67 function clear_tmpfiles
69 \rm -f ${my_tmproot}.*
72 function msg
74 typeset _eol="\n"
75 [ $# -ge 2 ] && _eol="${2}"
76 printf "[%s] %s${_eol}" ${me} "${1}"
77 return 0
80 function msgerr
82 msg "error: ${1}" 1>&2
83 return $?
86 function msgwarn
88 msg "warning: ${1}" 1>&2
89 return $?
92 function msg_help
94 msg_version
95 echo "
96 This script releases a new Nautilus-Actions version.
98 Usage: ${my_cmd} [options]
99 --[no]help print this message, and exit [${opt_help_def}]
100 --[no]version print script version, and exit [${opt_version_def}]
101 --[no]dummy dummy execution [${opt_dummy_def}]
102 --[no]verbose runs verbosely [${opt_verbose_def}]
103 --tarname=<tarname> the tarname to be released [${opt_tarname_def}]
104 --[no]stable whether this is a stable version [${opt_stable_def}]"
107 function msg_version
109 pck_name=$(grep '^PACKAGE_NAME' Makefile 2>/dev/null | awk '{ print $3 }')
110 pck_version=$(grep '^PACKAGE_VERSION' Makefile 2>/dev/null | awk '{ print $3 }')
111 echo "
112 ${pck_name} v ${pck_version}
113 Copyright (C) 2010, 2011 Pierre Wieser."
116 # initialize common command-line options
117 nbopt=$#
118 opt_help=
119 opt_help_def="no"
120 opt_dummy=
121 opt_dummy_def="yes"
122 opt_version=
123 opt_version_def="no"
124 opt_verbose=
125 opt_verbose_def="no"
127 # a first loop over command line arguments to detect verbose mode
128 while :
130 # break when all arguments have been read
131 case $# in
133 break
135 esac
137 # get and try to interpret the next argument
138 _option=$1
139 shift
141 # make all options have two hyphens
142 _orig_option=${_option}
143 case ${_option} in
144 --*)
147 _option=-${_option}
149 esac
151 # now process options and their argument
152 case ${_option} in
153 --noverb | --noverbo | --noverbos | --noverbose)
154 opt_verbose="no"
156 --verb | --verbo | --verbos | --verbose)
157 opt_verbose="yes"
159 esac
160 done
162 [ "${opt_verbose}" = "yes" ] && msg "setting opt_verbose to 'yes'"
164 # we have scanned all command-line arguments in order to detect an
165 # opt_verbose option;
166 # reset now arguments so that they can be scanned again in main script
167 set -- ${my_parms}
169 # interpreting command-line arguments
170 product="$(grep -e '^PACKAGE_TARNAME' Makefile 2>/dev/null | awk '{ print $3 }')"
171 version="$(grep PACKAGE_VERSION Makefile 2>/dev/null | awk '{ print $3 }')"
172 opt_tarname=
173 opt_tarname_def="${product}-${version}.tar.gz"
175 opt_stable=
176 minor=$(echo ${version} | cut -d. -f2)
177 let rest=${minor}%2
178 [ ${rest} -eq 0 ] && opt_stable_def="yes" || opt_stable_def="no"
180 # loop over command line arguments
181 pos=0
182 while :
184 # break when all arguments have been read
185 case $# in
187 break
189 esac
191 # get and try to interpret the next argument
192 option=$1
193 shift
195 # make all options have two hyphens
196 orig_option=${option}
197 case ${option} in
198 --*)
201 option=-${option}
203 esac
205 # split and extract argument for options that take one
206 case ${option} in
207 --*=*)
208 optarg=$(echo ${option} | sed -e 's/^[^=]*=//')
209 option=$(echo ${option} | sed 's/=.*//')
211 # these options take a mandatory argument
212 # since, we didn't find it in 'option', so it should be
213 # next word in the command line
214 --t | --ta | --tar | --tarn | --tarna | --tarnam | --tarname)
215 optarg=$1
216 shift
218 esac
220 # now process options and their argument
221 case ${option} in
222 --d | --du | --dum | --dumm | --dummy)
223 [ "${opt_verbose}" = "yes" ] && msg "setting opt_dummy to 'yes'"
224 opt_dummy="yes"
226 --h | --he | --hel | --help)
227 [ "${opt_verbose}" = "yes" ] && msg "setting opt_help to 'yes'"
228 opt_help="yes"
230 --nod | --nodu | --nodum | --nodumm | --nodummy)
231 [ "${opt_verbose}" = "yes" ] && msg "setting opt_dummy to 'no'"
232 opt_dummy="no"
234 --noh | --nohe | --nohel | --nohelp)
235 [ "${opt_verbose}" = "yes" ] && msg "setting opt_help to 'no'"
236 opt_help="no"
238 --nos | --nost | --nosta | --nostab | --nostabl | --nostable)
239 [ "${opt_verbose}" = "yes" ] && msg "setting opt_stable to 'no'"
240 opt_stable="no"
242 --noverb | --noverbo | --noverbos | --noverbose)
244 --novers | --noversi | --noversio | --noversion)
245 [ "${opt_verbose}" = "yes" ] && msg "setting opt_version to 'no'"
246 opt_version="no"
248 --s | --st | --sta | --stab | --stabl | --stable)
249 [ "${opt_verbose}" = "yes" ] && msg "setting opt_stable to 'yes'"
250 opt_stable="yes"
252 --t | --ta | --tar | --tarn | --tarna | --tarnam | --tarname)
253 [ "${opt_verbose}" = "yes" ] && msg "setting opt_tarname to '${optarg}'"
254 opt_tarname="${optarg}"
256 --verb | --verbo | --verbos | --verbose)
258 --vers | --versi | --versio | --version)
259 [ "${opt_verbose}" = "yes" ] && msg "setting opt_version to 'yes'"
260 opt_version="yes"
262 --*)
263 msgerr "unrecognized option: '${orig_option}'"
264 let errs+=1
266 # positional parameters
268 let pos+=1
269 #if [ ${pos} -eq 1 ]; then
270 # [ "${opt_verbose}" = "yes" ] && msg "setting opt_output to '${option}'"
271 # opt_output=${option}
272 #else
273 msgerr "unexpected positional parameter #${pos}: '${option}'"
274 let errs+=1
277 esac
278 done
280 # set option defaults
281 # does not work with /bin/sh ??
282 #set | grep -e '^opt_' | cut -d= -f1 | while read _name; do
283 # if [ "$(echo ${_name} | sed 's/.*\(_def\)/\1/')" != "_def" ]; then
284 # _value="$(eval echo "$"${_name})"
285 # if [ "${_value}" = "" ]; then
286 # eval ${_name}="$(eval echo "$"${_name}_def)"
287 # fi
288 # fi
289 #done
291 opt_help=${opt_help:-${opt_help_def}}
292 opt_dummy=${opt_dummy:-${opt_dummy_def}}
293 opt_verbose=${opt_verbose:-${opt_verbose_def}}
294 opt_version=${opt_version:-${opt_version_def}}
296 opt_tarname=${opt_tarname:-${opt_tarname_def}}
297 opt_stable=${opt_stable:-${opt_stable_def}}
299 if [ "${opt_help}" = "yes" -o ${nbopt} -eq 0 ]; then
300 msg_help
301 echo ""
302 exit
305 if [ "${opt_version}" = "yes" ]; then
306 msg_version
307 echo ""
308 exit
311 if [ ! -f "${opt_tarname}" ]; then
312 msgerr "${opt_tarname} not found, do you have 'make distcheck' ?"
313 let errs+=1
316 if [ ${errs} -gt 0 ]; then
317 msg "${errs} error(s) have been detected"
318 msg "try '${my_cmd} --help' for usage"
319 exit
322 # returns the last return code which happens to be the eval one
324 function command
326 typeset _cmd="${1}"
327 typeset -i _ret=0
329 if [ "${opt_dummy}" = "yes" -o "${opt_verbose}" = "yes" ]; then
330 typeset _prefix=""
331 [ "${opt_dummy}" = "yes" ] && _prefix="[dummy] "
332 msg " ${_prefix}${_cmd}..." " "
335 if [ "${opt_dummy}" = "no" ]; then
336 eval ${_cmd}
339 if [ "${opt_verbose}" = "yes" ]; then
340 eval ${_cmd}
341 let _ret=$?
344 if [ "${opt_dummy}" = "yes" -o "${opt_verbose}" = "yes" ]; then
345 [ ${_ret} -eq 0 ] && echo "OK" || echo "NOT OK"
348 let errs+=${_ret}
349 return ${_ret}
352 # ---------------------------------------------------------------------
353 # MAIN CODE
355 [ "${opt_stable}" = "yes" ] && lib_stable="stable" || lib_stable="unstable"
356 msg "releasing ${lib_stable} ${opt_tarname}"
358 msg " are you OK to release (y/N) ?" " "
359 while [ 1 ]; do
360 read -n1 -s key
361 key=$(echo $key | tr '[:upper:]' '[:lower:]')
362 [ "$key" = "y" -o "$key" = "n" -o "$key" = "" ] && break
363 done
364 [ "$key" = "y" ] && echo "Yes" || echo "No"
365 [ "$key" != "y" ] && exit
367 # are we local ?
368 destdir="/net/data/tarballs/${product}"
369 desthost="stormy.trychlos.org"
370 [ "$(ls ${destdir} 2>/dev/null)" = "" ] && local="no" || local="yes"
371 [ "${local}" = "yes" ] && lib_desthost="" || lib_desthost="${desthost}:"
372 [ "${opt_verbose}" = "yes" ] && msg "stormy tarballs repository is local: ${local}"
374 # installing on stormy tarballs repository
375 msg "installing in ${lib_desthost}${destdir}"
376 cmd="mkdir -p "${destdir}""
377 [ "${local}" = "yes" ] && command "${cmd}" || command "ssh ${desthost} '${cmd}'"
378 command "scp -v "${opt_tarname}" "${lib_desthost}${destdir}/""
379 cmd="sha1sum ${destdir}/${opt_tarname} > ${destdir}/${opt_tarname}.sha1sum"
380 [ "${local}" = "yes" ] && command "${cmd}" || command "ssh ${desthost} '${cmd}'"
381 if [ "${opt_stable}" = "yes" ]; then
382 msg "updating ${lib_desthost}${destdir}/latest.tar.gz"
383 cmd="(cd ${destdir}; rm -f latest.tar.gz; ln -s ${opt_tarname} latest.tar.gz; ls -l latest.tar.gz ${opt_tarname}*)"
384 [ "${local}" = "yes" ] && command "${cmd}" || command "ssh ${desthost} '${cmd}'"
387 # installing on gnome.org
388 msg "installing on gnome.org"
389 command "scp "${opt_tarname}" pwieser@master.gnome.org:"
390 command "ssh pwieser@master.gnome.org install-module -u ${opt_tarname}"
392 # installing on kimsufi
393 msg "installing on kimsufi"
394 destdir="/home/www/${product}/tarballs"
395 command "scp "${opt_tarname}" maintainer@kimsufi:${destdir}/"
396 command "ssh maintainer@kimsufi 'sha1sum ${destdir}/${opt_tarname} > ${destdir}/${opt_tarname}.sha1sum'"
397 if [ "${opt_stable}" = "yes" ]; then
398 msg "updating kimsufi:${destdir}/latest.tar.gz"
399 command "ssh maintainer@kimsufi 'cd ${destdir}; rm -f latest.tar.gz; ln -s ${opt_tarname} latest.tar.gz; ls -l latest.tar.gz ${opt_tarname}*'"
402 # tagging git
403 msg "tagging git"
404 tag="$(echo ${product}-${version} | tr '[:lower:]' '[:upper:]' | sed -e 's/-/_/g' -e 's/\./_/g')"
405 msg="Releasing $(grep PACKAGE_NAME Makefile | awk '{ print $3 }') ${version}"
406 msg "git tag -s ${tag} -m ${msg}"
407 command "git tag -s '${tag}' -m '${msg}'"
408 command "git pull --rebase && git push && git push --tags"
410 # compressing git local repository
411 msg "compressing local git repository"
412 command "git gc"
414 msg "Successfully ended. You may now send your mail."
416 exit