Skip to content

Commit 16ddf8c

Browse files
committed
Add generate_tarball.sh
1 parent 4108b87 commit 16ddf8c

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

SOURCES/generate_tarball.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/sh
2+
3+
# This script should be run from the kernel-src-tree directory
4+
# It reads the tarfile name from the spec file and creates the tarball
5+
6+
# Determine dist-git directory paths
7+
# Assuming this script is in dist-git/SOURCES/
8+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
9+
DISTGIT_ROOT="$(dirname "$SCRIPT_DIR")"
10+
SOURCE_DIR="$DISTGIT_ROOT/SOURCES"
11+
SPEC_FILE="$DISTGIT_ROOT/SPECS/kernel.spec"
12+
13+
# Extract version information from spec file
14+
TARFILE_RELEASE=$(grep '^%define tarfile_release' "$SPEC_FILE" | awk '{print $3}')
15+
SPEC_VERSION=$(grep '^%define specversion' "$SPEC_FILE" | awk '{print $3}')
16+
17+
if [ -z "$TARFILE_RELEASE" ]; then
18+
echo "Error: Could not extract tarfile_release from $SPEC_FILE"
19+
exit 1
20+
fi
21+
22+
if [ -z "$SPEC_VERSION" ]; then
23+
echo "Error: Could not extract specversion from $SPEC_FILE"
24+
exit 1
25+
fi
26+
27+
# Get current git tag and extract version
28+
CURRENT_TAG=$(git describe --tags --abbrev=0 2>/dev/null)
29+
if [ -z "$CURRENT_TAG" ]; then
30+
echo "Error: Could not determine current git tag"
31+
exit 1
32+
fi
33+
34+
TAG_VERSION=${CURRENT_TAG/ciq_kernel-/}
35+
GIT_VERSION=${TAG_VERSION%%-*}
36+
37+
# Verify that git version matches spec version
38+
if [ "$GIT_VERSION" != "$SPEC_VERSION" ]; then
39+
echo "Error: Version mismatch!"
40+
echo " Git version: $GIT_VERSION (from tag: $CURRENT_TAG)"
41+
echo " Spec version: $SPEC_VERSION"
42+
echo ""
43+
echo "Please either:"
44+
echo " 1. Run update_spec.sh to update the spec to match current git checkout, or"
45+
echo " 2. Check out the correct git tag that matches the spec version"
46+
exit 1
47+
fi
48+
49+
TARBALL="$SOURCE_DIR/linux-$TARFILE_RELEASE.tar.xz"
50+
XZ_THREADS="--threads 4"
51+
ARCH=$(arch)
52+
XZ_OPTIONS=""
53+
54+
if [ "$ARCH" != "x86_64" ]
55+
then
56+
XZ_OPTIONS="-M 3G"
57+
fi
58+
59+
# convert from shortened git sha to standard 40 digit git sha
60+
_GITID="$(git rev-parse HEAD)"
61+
62+
if [ -f "$TARBALL" ]; then
63+
TARID=$(xzcat -qq "$TARBALL" | git get-tar-commit-id 2>/dev/null)
64+
if [ "$_GITID" = "$TARID" ]; then
65+
echo "$(basename "$TARBALL") unchanged..."
66+
exit 0
67+
fi
68+
rm -f "$TARBALL"
69+
fi
70+
71+
echo "Creating $(basename "$TARBALL")..."
72+
trap 'rm -vf "$TARBALL"' INT
73+
git archive --prefix="linux-$TARFILE_RELEASE"/ --format=tar "$_GITID" | xz $XZ_OPTIONS $XZ_THREADS > "$TARBALL";
74+
75+
echo "Tarball created: $TARBALL"

0 commit comments

Comments
 (0)