1#!/usr/bin/env bash
2
3set -euo pipefail
4
5VERSION=$(grep '^version = ' Cargo.toml | sed 's/.*"\([0-9\.]*\)".*/\1/')
6GPG_KEY=EA456E8BAF0109429583EED83578F667F2F3A5FA
7
8declare -a targets=(
9    "x86_64-musl"
10    "i686-musl"
11    "armv7-musleabihf"
12    "arm-musleabi"
13    "arm-musleabihf"
14)
15
16declare -a rusttargets=(
17    "x86_64-unknown-linux-musl"
18    "i686-unknown-linux-musl"
19    "armv7-unknown-linux-musleabihf"
20    "arm-unknown-linux-musleabi"
21    "arm-unknown-linux-musleabihf"
22)
23
24declare -a completions=(
25    "bash"
26    "fish"
27    "zsh"
28)
29
30function docker-download {
31    echo "==> Downloading Docker image: messense/rust-musl-cross:$1"
32    docker pull messense/rust-musl-cross:$1
33}
34
35function docker-build {
36    echo "==> Building target: $1"
37    docker run --rm -it -v "$(pwd)":/home/rust/src messense/rust-musl-cross:$1 cargo build --release
38}
39
40echo -e "==> Version $VERSION\n"
41
42for target in ${targets[@]}; do docker-download $target; done
43echo ""
44for target in ${targets[@]}; do docker-build $target; done
45echo ""
46
47rm -rf "dist-$VERSION"
48mkdir "dist-$VERSION"
49
50for i in ${!targets[@]}; do
51    echo "==> Copying ${targets[$i]}"
52    cp "target/${rusttargets[$i]}/release/tldr" "dist-$VERSION/tldr-linux-${targets[$i]}"
53done
54echo ""
55
56for target in ${targets[@]}; do
57    echo "==> Stripping $target"
58    docker run --rm -it -v "$(pwd)":/home/rust/src messense/rust-musl-cross:$target musl-strip -s /home/rust/src/dist-$VERSION/tldr-linux-$target
59done
60echo ""
61
62for target in ${targets[@]}; do
63    echo "==> Signing $target"
64    gpg -a --output "dist-$VERSION/tldr-linux-$target.sig" --detach-sig "dist-$VERSION/tldr-linux-$target"
65done
66echo ""
67
68for completion in ${completions[@]}; do
69    echo "==> Copying ${completion} completion"
70    cp "${completion}_tealdeer" "dist-$VERSION/completions_${completion}"
71done
72echo ""
73
74echo "==> Copying licenses"
75cp LICENSE-* "dist-$VERSION/"
76
77echo "Done."
78