bump product version to 5.0.4.1
[LibreOffice.git] / bin / lo-generate-source-tarball
blob2cb53986d6e428be8e59288269adc9c5ff97850b
1 #!/usr/bin/env bash
3 if [ -n "$debug" ] ; then
4 set -x
5 fi
7 BIN_DIR=$(dirname "$0")
8 CORE_DIR=$(realpath "$BIN_DIR/..")
9 GEN_BZ2=false
10 GEN_MD5=false
11 GEN_XZ=false
12 OUT_DIR="${CORE_DIR?}"
13 VERSION=
15 usage()
17 cat <<EOF
18 Usage: $0 [ --xz ] [ --bz2 ] [ --md5 ] [ --output-dir=<output location> ]
19 [ --core-dir=<core-repo-location ] [--version=<package_version] label
21 --xz generate a package compressed with xz (default)
22 --bz2 generate a package compressed with bz2. Note if you specify
23 both --cz and --bz2, both are created. If you specify neither
24 --xz is implied.
25 --md5 generate a md5 signature for the generated package(s)
26 --output-dir where to put the generated packages
27 --core-dir location of the core repo to extract sources from.
28 By default this is one directory up from the position
29 of this script.
30 --version version string used to generate the name of the package
31 the source package name is libreoffice-<version>.tar.[bz2|xz]
33 EOF
35 while [ "${1}" != "" ]; do
36 parm=${1%%=*}
37 arg=${1#*=}
38 has_arg=
39 if [ "${1}" != "${parm?}" ] ; then
40 has_arg=1
41 else
42 arg=""
44 # echo "parm=!${parm}!"
45 # echo "arg=!${arg}!"
46 case "${parm}" in
47 -2|--bz2)
48 GEN_BZ2=true
50 -x|--xz)
51 GEN_XZ=true
53 -5|--md5)
54 GEN_MD5=true
56 -o|--output-dir)
57 if [ -z "${has_arg}" ] ; then
58 shift;
59 arg="$1"
61 if [ -z "${arg}" ] ; then
62 echo "Missing argument for option $parm" 1>&2
63 exit -1
64 else
65 OUT_DIR="$arg"
68 -v|--version)
69 if [ -z "${has_arg}" ] ; then
70 shift;
71 arg="$1"
73 if [ -z "${arg}" ] ; then
74 echo "Missing argument for option $parm" 1>&2
75 exit -1
76 else
77 VERSION="$arg"
80 -h|--help)
81 usage
82 exit 0
84 -*)
85 echo "Invalid option $1" 1>&2
86 exit -1
89 if [ -z "${LABEL}" ] ; then
90 LABEL="$parm"
91 else
92 echo "Too many arguments.. $@" 1>&2
93 exit -1
96 esac
97 shift
98 done
100 # we need a label
101 if [ -z "${LABEL}" ] ; then
102 echo "Missing argument. We need a git label as source" 1>&2
103 exit 1
106 # default to xz compression
107 if ! ${GEN_BZ2?} && ! ${GEN_XZ?} ; then
108 GEN_XZ=true
111 # --version= is mandatory
112 if [ -z "${VERSION}" ] ; then
113 VERSION="${LABEL?}"
116 base_name="libreoffice-${VERSION}"
118 # --output-dir default to core-dir
119 if [ -z "${OUT_DIR}" ] ; then
120 OUT_DIR="$CORE_DIR?}"
123 if [ ! -d "${CORE_DIR?}" ] ; then
124 echo "Core repo directory $CORE_DIR does not exist or is not a directory" 1>&2
125 exit 1
128 if [ ! -d "${CORE_DIR?}/.git" ] ; then
129 echo "Core repo $CORE_DIR is not a git repo" 1>&2
130 exit 1
133 if [ ! -d "${OUT_DIR?}" ] ; then
134 echo "Output directory $OUT_DIR does not exist or is not a directory" 1>&2
135 exit 1
139 pushd "${CORE_DIR}" > /dev/null
142 echo "archiving core..."
143 git archive --format=tar --prefix="${base_name?}/" -o "${OUT_DIR}/${base_name}.tar" ${LABEL?}
146 concatenate_list=
147 for module in dictionaries helpcontent2 translations ; do
148 if [ ! -f ${module?}/.git ] ; then
149 echo "Warning: module $module is not present" 1>&2
150 else
151 echo "archiving ${module?}..."
152 git archive --format=tar --prefix="${base_name?}/${module?}" -o "${OUT_DIR}/${base_name}-${module?}.tar" ${LABEL?}
153 concatenate_list="${concatenate_list?} ${OUT_DIR}/${base_name}-${module?}.tar"
155 done
157 if [ -n "${concatenate_list?}" ] ; then
158 tar --concatenate --file="${OUT_DIR}/${base_name}.tar" ${concatenate_list?}
159 rm ${concatenate_list?}
162 if ${GEN_BZ2?} ; then
163 echo "bzip2 compression..."
164 bzip2 -fkz "${OUT_DIR}/${base_name}.tar"
165 if ${GEN_MD5?} ; then
166 echo "md5sum..."
167 md5sum "${OUT_DIR}/${base_name}.tar.bz2" > "${OUT_DIR}/${base_name}.tar.bz2.md5"
171 if ${GEN_XZ?} ; then
172 echo "xz compression..."
173 xz -fz "${OUT_DIR}/${base_name}.tar"
174 if ${GEN_MD5?} ; then
175 echo "md5sum..."
176 md5sum "${OUT_DIR}/${base_name}.tar.xz" > "${OUT_DIR}/${base_name}.tar.zx.md5"
178 else
179 rm "${OUT_DIR}/${base_name}.tar"
182 echo "Done."