| 1 |
#!/bin/sh |
| 2 |
# Copyright (C) The libssh2 project and its contributors. |
| 3 |
# SPDX-License-Identifier: BSD-3-Clause |
| 4 |
# |
| 5 |
# Script to build release-archives with. Note that this requires a checkout |
| 6 |
# from git and you should first run 'autoreconf -fi' and './configure'. |
| 7 |
# |
| 8 |
|
| 9 |
set -eu |
| 10 |
|
| 11 |
export LC_ALL=C |
| 12 |
export TZ=UTC |
| 13 |
|
| 14 |
version="${1:-}" |
| 15 |
|
| 16 |
if [ -z "$version" ]; then |
| 17 |
echo "Specify a version number!" |
| 18 |
exit |
| 19 |
fi |
| 20 |
|
| 21 |
if [ "only" = "${2:-}" ]; then |
| 22 |
echo "Setup version number only!" |
| 23 |
only=1 |
| 24 |
else |
| 25 |
only= |
| 26 |
fi |
| 27 |
|
| 28 |
libversion="$version" |
| 29 |
|
| 30 |
major=$(echo "$libversion" | cut -d. -f1 | sed -e "s/[^0-9]//g") |
| 31 |
minor=$(echo "$libversion" | cut -d. -f2 | sed -e "s/[^0-9]//g") |
| 32 |
patch=$(echo "$libversion" | cut -d. -f3 | cut -d- -f1 | sed -e "s/[^0-9]//g") |
| 33 |
|
| 34 |
numeric="$(printf "%02x%02x%02x\n" "$major" "$minor" "$patch")" |
| 35 |
|
| 36 |
HEADER=include/libssh2.h |
| 37 |
|
| 38 |
if test -z "$only"; then |
| 39 |
ext=".dist" |
| 40 |
# when not setting up version numbers locally |
| 41 |
for a in $HEADER; do |
| 42 |
cp "$a" "$a$ext" |
| 43 |
done |
| 44 |
HEADER="$HEADER$ext" |
| 45 |
fi |
| 46 |
|
| 47 |
# requires a date command that knows + for format and -d for date input |
| 48 |
timestamp=${SOURCE_DATE_EPOCH:-$(date +"%s")} |
| 49 |
datestamp=$(date -d "@$timestamp") |
| 50 |
filestamp=$(date -d "@$timestamp" +"%Y%m%d%H%M.%S") |
| 51 |
|
| 52 |
# Replace version number in header file: |
| 53 |
sed -i.bak \ |
| 54 |
-e "s/^#define LIBSSH2_VERSION .*/#define LIBSSH2_VERSION \"$libversion\"/g" \ |
| 55 |
-e "s/^#define LIBSSH2_VERSION_NUM .*/#define LIBSSH2_VERSION_NUM 0x$numeric/g" \ |
| 56 |
-e "s/^#define LIBSSH2_VERSION_MAJOR .*/#define LIBSSH2_VERSION_MAJOR $major/g" \ |
| 57 |
-e "s/^#define LIBSSH2_VERSION_MINOR .*/#define LIBSSH2_VERSION_MINOR $minor/g" \ |
| 58 |
-e "s/^#define LIBSSH2_VERSION_PATCH .*/#define LIBSSH2_VERSION_PATCH $patch/g" \ |
| 59 |
-e "s/^#define LIBSSH2_TIMESTAMP .*/#define LIBSSH2_TIMESTAMP \"$datestamp\"/g" \ |
| 60 |
"$HEADER" |
| 61 |
rm -f "$HEADER.bak" |
| 62 |
|
| 63 |
if test -n "$only"; then |
| 64 |
# done! |
| 65 |
exit |
| 66 |
fi |
| 67 |
|
| 68 |
echo "libssh2 version $libversion" |
| 69 |
echo "libssh2 numerical $numeric" |
| 70 |
echo "datestamp $datestamp" |
| 71 |
|
| 72 |
findprog() { |
| 73 |
file="$1" |
| 74 |
for part in $(echo "$PATH" | tr ':' ' '); do |
| 75 |
path="$part/$file" |
| 76 |
if [ -x "$path" ]; then |
| 77 |
# there it is! |
| 78 |
return 1 |
| 79 |
fi |
| 80 |
done |
| 81 |
|
| 82 |
# no such executable |
| 83 |
return 0 |
| 84 |
} |
| 85 |
|
| 86 |
############################################################################ |
| 87 |
# |
| 88 |
# automake is needed to run to make a non-GNU Makefile.in if Makefile.am has |
| 89 |
# been modified. |
| 90 |
# |
| 91 |
|
| 92 |
if { findprog automake >/dev/null 2>/dev/null; } then |
| 93 |
echo "- Could not find or run automake, I hope you know what you are doing!" |
| 94 |
else |
| 95 |
echo "Runs automake --include-deps" |
| 96 |
automake --include-deps Makefile >/dev/null |
| 97 |
fi |
| 98 |
|
| 99 |
############################################################################ |
| 100 |
# |
| 101 |
# Generate the changelog |
| 102 |
# |
| 103 |
echo "generate NEWS" |
| 104 |
git log --pretty=fuller --no-color --date=short --decorate=full -1000 | ./git2news.pl > NEWS.dist |
| 105 |
|
| 106 |
############################################################################ |
| 107 |
# |
| 108 |
# Now run make dist to generate a tar.gz archive |
| 109 |
# |
| 110 |
|
| 111 |
echo "make dist" |
| 112 |
targz="libssh2-$version.tar.gz" |
| 113 |
make -s dist "VERSION=$version" |
| 114 |
res=$? |
| 115 |
|
| 116 |
if test "$res" != 0; then |
| 117 |
echo "make dist failed" |
| 118 |
exit 2 |
| 119 |
fi |
| 120 |
|
| 121 |
retar() { |
| 122 |
tempdir=$1 |
| 123 |
rm -rf "$tempdir" |
| 124 |
mkdir "$tempdir" |
| 125 |
cd "$tempdir" |
| 126 |
gzip -dc "../$targz" | tar -xf - |
| 127 |
find libssh2-* -depth -exec touch -c -t "$filestamp" '{}' + |
| 128 |
tar --create --format=ustar --owner=0 --group=0 --numeric-owner --sort=name libssh2-* | gzip --best --no-name > out.tar.gz |
| 129 |
mv out.tar.gz ../ |
| 130 |
cd .. |
| 131 |
rm -rf "$tempdir" |
| 132 |
} |
| 133 |
|
| 134 |
retar ".tarbuild" |
| 135 |
echo "replace $targz with out.tar.gz" |
| 136 |
mv out.tar.gz "$targz" |
| 137 |
|
| 138 |
############################################################################ |
| 139 |
# |
| 140 |
# Now make a bz2 archive from the tar.gz original |
| 141 |
# |
| 142 |
|
| 143 |
bzip2="libssh2-$version.tar.bz2" |
| 144 |
echo "Generating $bzip2" |
| 145 |
gzip -dc "$targz" | bzip2 --best > "$bzip2" |
| 146 |
|
| 147 |
############################################################################ |
| 148 |
# |
| 149 |
# Now make an xz archive from the tar.gz original |
| 150 |
# |
| 151 |
|
| 152 |
xz="libssh2-$version.tar.xz" |
| 153 |
echo "Generating $xz" |
| 154 |
gzip -dc "$targz" | xz -6e - > "$xz" |
| 155 |
|
| 156 |
############################################################################ |
| 157 |
# |
| 158 |
# Now make a zip archive from the tar.gz original |
| 159 |
# |
| 160 |
makezip() { |
| 161 |
rm -rf "$tempdir" |
| 162 |
mkdir "$tempdir" |
| 163 |
cd "$tempdir" |
| 164 |
gzip -dc "../$targz" | tar -xf - |
| 165 |
find . | sort | zip -9 -X "$zip" -@ >/dev/null |
| 166 |
mv "$zip" ../ |
| 167 |
cd .. |
| 168 |
rm -rf "$tempdir" |
| 169 |
} |
| 170 |
|
| 171 |
zip="libssh2-$version.zip" |
| 172 |
echo "Generating $zip" |
| 173 |
tempdir=".builddir" |
| 174 |
makezip |
| 175 |
|
| 176 |
# Set deterministic timestamp |
| 177 |
touch -c -t "$filestamp" "$targz" "$bzip2" "$xz" "$zip" |
| 178 |
|
| 179 |
echo "------------------" |
| 180 |
echo "maketgz report:" |
| 181 |
echo "" |
| 182 |
ls -l "$targz" "$bzip2" "$xz" "$zip" |
| 183 |
sha256sum "$targz" "$bzip2" "$xz" "$zip" |
| 184 |
|
| 185 |
echo "Run this:" |
| 186 |
echo "gpg -b -a '$targz' && gpg -b -a '$bzip2' && gpg -b -a '$xz' && gpg -b -a '$zip'" |