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