2019-01-11 22:34:03 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Creates a release tarball directly from git
|
|
|
|
|
|
|
|
# Note that the tarball contents might not exactly match
|
|
|
|
# a particular git commit, particularly for untagged
|
|
|
|
# commits.
|
|
|
|
#
|
|
|
|
# An alternative approach would be to generate source tarballs
|
|
|
|
# using CPack. That would remove our dependency on git, but if
|
|
|
|
# Autotools is any indication it would require continuous
|
|
|
|
# maintenance.
|
|
|
|
#
|
|
|
|
# Copyright 2011 Balint Reczey <balint@balintreczey.hu>
|
|
|
|
#
|
|
|
|
# Wireshark - Network traffic analyzer
|
|
|
|
# By Gerald Combs <gerald@wireshark.org>
|
|
|
|
# Copyright 1998 Gerald Combs
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2021-01-08 19:04:00 +00:00
|
|
|
set -e -u -o pipefail
|
2019-01-11 22:34:03 +00:00
|
|
|
|
|
|
|
DESTDIR=.
|
|
|
|
|
|
|
|
while getopts "d:" OPTCHAR ; do
|
|
|
|
case $OPTCHAR in
|
|
|
|
d) DESTDIR=$OPTARG ;;
|
|
|
|
*) printf "Unknown option %s\n" "$OPTCHAR" ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(( OPTIND - 1 ))
|
|
|
|
|
|
|
|
# The remaining parameter, if set, is a package version such as 3.4.5
|
|
|
|
# or 3.4.5-67-gabcd4321
|
2022-07-11 14:44:23 +00:00
|
|
|
# By default the version from make-version.py + CMake is used.
|
2022-06-07 22:51:24 +00:00
|
|
|
PROJECT_VERSION=@PROJECT_VERSION@
|
2021-01-08 19:04:00 +00:00
|
|
|
if test -n "${1-}"; then
|
2022-06-07 22:51:24 +00:00
|
|
|
PROJECT_VERSION="$1"
|
2019-01-11 22:34:03 +00:00
|
|
|
fi
|
|
|
|
|
2022-06-07 22:51:24 +00:00
|
|
|
TARBALL="${DESTDIR}/wireshark-${PROJECT_VERSION}.tar.xz"
|
2022-04-26 22:24:03 +00:00
|
|
|
|
2022-04-27 11:42:34 +00:00
|
|
|
# A tarball produced by 'git archive' will have the $Format string
|
|
|
|
# substituted due to the use of 'export-subst' in .gitattributes.
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
COMMIT='$Format:%H$'
|
|
|
|
|
|
|
|
if [[ $COMMIT != \$F* ]] ; then
|
|
|
|
# This file was extracted from a tarball produced by git archive
|
|
|
|
# and so we are not in a git repository.
|
|
|
|
if [[ -f "$TARBALL" ]] ; then
|
|
|
|
# git get-tar-commit-id works outside a git repo, as it
|
|
|
|
# only reads the first 1024 bytes of the tar extended header.
|
|
|
|
if [[ $(git get-tar-commit-id < <(xzcat "$TARBALL")) == "$COMMIT" ]] ; then
|
|
|
|
echo "$TARBALL commit ID matches $COMMIT."
|
|
|
|
else
|
|
|
|
# Allow people to make changes to a downloaded source tarball
|
|
|
|
# and re-tar it?
|
|
|
|
echo "WARNING: $TARBALL is not the original git archive."
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "The build system cannot produce a source tarball outside of a git repository."
|
|
|
|
echo "If you are trying to build an RPM package from source extracted from a tarball,"
|
2022-06-07 22:51:24 +00:00
|
|
|
echo "copy it (i.e., wireshark-${PROJECT_VERSION}.tar.xz) to"
|
2022-04-27 11:42:34 +00:00
|
|
|
echo "$DESTDIR"
|
|
|
|
echo "and run the build command again."
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-05-11 18:05:40 +00:00
|
|
|
STASH_ID=$(git stash create || echo "")
|
2022-10-20 22:33:38 +00:00
|
|
|
|
|
|
|
if [[ -n "${CI_COMMIT_SHA-}" ]] ; then
|
|
|
|
echo "Setting commit from CI_COMMIT_SHA"
|
|
|
|
COMMIT="$CI_COMMIT_SHA"
|
|
|
|
elif [[ -n "$STASH_ID" ]] ; then
|
|
|
|
echo "Setting commit from stash"
|
2022-04-26 22:24:03 +00:00
|
|
|
COMMIT="$STASH_ID"
|
2022-10-20 22:33:38 +00:00
|
|
|
else
|
|
|
|
COMMIT="HEAD"
|
2021-08-27 17:55:30 +00:00
|
|
|
fi
|
|
|
|
|
2022-04-26 22:24:03 +00:00
|
|
|
if [ -f "$TARBALL" ] ; then
|
2022-05-11 18:05:40 +00:00
|
|
|
printf "Found %s\\n" "$TARBALL"
|
2022-04-26 22:24:03 +00:00
|
|
|
if TARBALL_ID=$(git get-tar-commit-id < <(xzcat "$TARBALL")) && COMMIT_ID=$(git rev-parse --verify "$COMMIT") ; then
|
|
|
|
if [[ $TARBALL_ID == "$COMMIT_ID" ]] ; then
|
|
|
|
echo "$TARBALL commit ID matches $COMMIT."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
2019-01-11 22:34:03 +00:00
|
|
|
fi
|
|
|
|
|
2022-04-26 22:24:03 +00:00
|
|
|
echo "Creating $TARBALL from $COMMIT"
|
2019-01-11 22:34:03 +00:00
|
|
|
|
2021-08-27 17:55:30 +00:00
|
|
|
XZ_OPTS=
|
2019-01-11 22:34:03 +00:00
|
|
|
echo . | xz --threads=0 > /dev/null 2>&1 && XZ_OPTS=--threads=0
|
|
|
|
|
2022-06-07 22:51:24 +00:00
|
|
|
git archive --prefix="wireshark-${PROJECT_VERSION}/" "$COMMIT" | xz $XZ_OPTS > "$TARBALL"
|