summaryrefslogtreecommitdiff
path: root/maintainer/create-release.sh
blob: 6aa4cc8861fe70c2288d0ea5bd9d917e8b6bf6fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash

# Configurable portions
docs_git=https://github.com/crosstool-ng/crosstool-ng.github.io.git
docs_subdir=_pages/docs
formats=( "bz2" "xz" )
declare -A tar_opt=( ["bz2"]=j ["xz"]=J )
digests=( md5 sha1 sha512 )
use_gpg=yes

do_trace()
{
    echo "  --> $@" >&2
}

do_abort()
{
    echo "ERROR: $@" >&2
    exit 1
}

# Go to the top-level
topdir=`git rev-parse --show-toplevel`
if [ -z "${topdir}" ]; then
    do_abort "Not in the Git clone"
fi
cd "${topdir}"

# Determine the version. Replace the dashes with dots, as packaging
# systems don't expect dashes in versions, but they're ok in package
# name.
version=`git describe | sed -r -e 's,-,.,g' -e 's,^crosstool\.ng\.,crosstool-ng-,'`
do_trace "Creating release for ${version}"

# Create the base working directory
if [ -e "release" -a ! -d "release" ]; then
    do_abort "File 'release' already exists but is not a directory"
fi
mkdir -p "release"

# Copy the base stuff
do_trace "Copying crosstool-NG"
rm -rf "release/${version}"
git archive --prefix="${version}/" HEAD | tar xf - -C "release"

# Clone a repository for docs. Github does not support 'git archive --remote='.
do_trace "Checking out docs"
rm -rf "release/site"
git clone --depth=1 "${docs_git}" "release/site"

# The rest of modifications are inside the release directory
cd "release/${version}"

# Copy the docs instead of the MANUAL_ONLINE placeholder
do_trace "Replacing docs"
rm "docs/MANUAL_ONLINE"
mkdir -p "docs/manual"
for i in "../site/${docs_subdir}/"*.md; do
    awk '
BEGIN   { skip=0; }
        {
            if ($0=="---") {
                if (NR==1) {
                    skip=1
                    next
                }
                else if (skip) {
                    skip=0
                    next
                }
            }
            if (!skip) {
                print $0
            }
        }
' < "${i}" > "docs/manual/${i##*/}"
done

# Run bootstrap before it is removed
do_trace "Bootstrapping"
./bootstrap
rm -f bootstrap

# Remove other things not for the end user
do_trace "Removing unreleased files"
rm -f .travis.*
find -name .gitignore | xargs rm
rm -rf autom4te.cache maintainer

# Go back to top level
cd ../..

# Package up
do_trace "Packaging"
for fmt in "${formats[@]}"; do
    tar c${tar_opt[$fmt]}f "release/${version}.tar.${fmt}" -C "release" "${version}"
    for h in "${digests[@]}"; do
        (cd "release" && ${h}sum "${version}.tar.${fmt}") > "release/${version}.tar.${fmt}.${h}"
    done
    if [ "${use_gpg}" = "yes" ]; then
        (cd "release" && gpg --detach-sign "${version}.tar.${fmt}")
    fi
done