OXYGENHUB
# 135bdcadec4a oxygen / scripts / dist.sh
6.2 KiB · Bourne Again Shell (bash) · executable · last changed Releases carry their source: oxy-VERSION-src.tar.gz, reproducible; haikuports recipes for oxy and oh written from release source tarballs (refs #157) 7 days ago source blame history raw
25c6adfa Andy McCall ↶ 1
#!/usr/bin/env bash
2
# Build release archives of one binary for every platform from Linux:
3
#   Linux x86_64 and arm64 (glibc 2.28 and later): .tar.gz and .deb
4
#   macOS x86_64 and arm64: .tar.gz
5
#   Windows x86_64: .zip
6
# plus SHA256SUMS, in target/dist/VERSION.
7
#
8
#   scripts/dist.sh [VERSION]    (default: the package version)
1931724b Andy McCall ↶ 9
#   ONLY=linux-x86_64 scripts/dist.sh   builds one platform (a glob)
25c6adfa Andy McCall ↶ 10
#
11
# Needs: rustup targets x86_64-pc-windows-gnu, aarch64-unknown-linux-gnu,
12
# x86_64-apple-darwin and aarch64-apple-darwin; cargo-zigbuild and zig on
13
# PATH (Linux with an old glibc, and macOS without Apple's SDK); the
14
# MinGW-w64 gcc (Windows); dpkg-deb and zip.
15
set -euo pipefail
16
17
PKG=oxy                  # the cargo package
18
BIN=oxy                  # the binary it builds
19
DEB_NAME=oxy             # the Debian package
1931724b Andy McCall ↶ 20
OTHER_DEB=oh            # the other package sharing the apt repository files
25c6adfa Andy McCall ↶ 21
SUMMARY="Oxygen version control: a distributed, commutative VCS"
22
DESCRIPTION="Oxygen is a version control system in which changes commute: a
23
 state is a set of changes, merges need no merge commits, conflicts are
24
 recorded and resolved like any other change, and every change is signed
25
 by its author."
26
HOMEPAGE="https://oxygenhub.io/andymccall/oxygen"
27
MAINTAINER="Andy McCall <[email protected]>"
28
DOCS=(README.md LICENSE)
29
30
cd "$(dirname "$0")/.."
31
VERSION="${1:-$(cargo metadata --no-deps --format-version 1 | python3 -c "import json,sys; print(next(p['version'] for p in json.load(sys.stdin)['packages'] if p['name']=='$PKG'))")}"
32
VERSION="${VERSION#v}"
33
OUT="target/dist/$VERSION"
34
rm -rf "$OUT" && mkdir -p "$OUT"
35
export PATH="$HOME/.local/opt/zig:$PATH"
36
# Stripped, with no debug info: these are for people, not for debugging.
37
export CARGO_PROFILE_RELEASE_DEBUG=0 CARGO_PROFILE_RELEASE_STRIP=true CARGO_INCREMENTAL=0
38
# The version the binary reports.
39
export OXY_BUILD="v$VERSION"
40
41
# target triple | platform name | build tool | Debian architecture
42
PLATFORMS=(
43
  "x86_64-unknown-linux-gnu.2.28|linux-x86_64|zig|amd64"
44
  "aarch64-unknown-linux-gnu.2.28|linux-arm64|zig|arm64"
45
  "x86_64-apple-darwin|macos-x86_64|zig|"
46
  "aarch64-apple-darwin|macos-arm64|zig|"
47
  "x86_64-pc-windows-gnu|windows-x86_64|cargo|"
48
)
49
50
for p in "${PLATFORMS[@]}"; do
51
  IFS='|' read -r target platform tool deb <<<"$p"
52
  triple="${target%%.2.*}"
1931724b Andy McCall ↶ 53
  # ONLY=linux-x86_64 (a glob) builds just the platforms it matches.
54
  if [ -n "${ONLY:-}" ] && [[ "$platform" != $ONLY ]]; then continue; fi
25c6adfa Andy McCall ↶ 55
  echo "== $platform ($target)"
56
  if [ "$tool" = zig ]; then
57
    cargo zigbuild -q --release --locked --target "$target" -p "$PKG"
58
  else
59
    cargo build -q --release --locked --target "$target" -p "$PKG"
60
  fi
61
  exe="$BIN"
62
  [[ "$triple" == *windows* ]] && exe="$BIN.exe"
63
  built="target/$triple/release/$exe"
64
  name="$BIN-$VERSION-$platform"
65
  stage="$OUT/stage/$name"
66
  mkdir -p "$stage"
67
  cp "$built" "$stage/"
68
  cp "${DOCS[@]}" "$stage/"
69
  if [[ "$triple" == *windows* ]]; then
70
    (cd "$OUT/stage" && zip -qr "../$name.zip" "$name")
71
  else
72
    tar -C "$OUT/stage" -czf "$OUT/$name.tar.gz" "$name"
73
  fi
74
  if [ -n "$deb" ]; then
75
    root="$OUT/stage/deb-$deb"
76
    mkdir -p "$root/DEBIAN" "$root/usr/bin" "$root/usr/share/doc/$DEB_NAME"
77
    install -m 0755 "$built" "$root/usr/bin/$BIN"
78
    cp README.md "$root/usr/share/doc/$DEB_NAME/"
79
    cp LICENSE "$root/usr/share/doc/$DEB_NAME/copyright"
1931724b Andy McCall ↶ 80
    # The apt repository at oxygenhub.io (oxygenhub#85): the package ships
81
    # the archive's key and, on its first install, adds the repository, so
82
    # apt upgrade keeps it current. oxy and oh share the files they write.
83
    mkdir -p "$root/usr/share/$DEB_NAME"
84
    install -m 0644 packaging/oxygenhub-archive-keyring.gpg "$root/usr/share/$DEB_NAME/"
85
    sed "s/@PKG@/$DEB_NAME/" >"$root/DEBIAN/postinst" <<'EOF'
86
#!/bin/sh
87
set -e
88
if [ "$1" = configure ]; then
89
  # The key is refreshed on every install, so a new one reaches everyone.
90
  install -m 0644 /usr/share/@PKG@/oxygenhub-archive-keyring.gpg /usr/share/keyrings/oxygenhub-archive-keyring.gpg
91
  # The repository is added on the first install only: removing it
92
  # keeps it removed.
93
  L=/etc/apt/sources.list.d/oxygenhub.sources
94
  if [ -z "$2" ] && [ ! -e "$L" ] && ! grep -rqs "oxygenhub.io/apt" /etc/apt/sources.list /etc/apt/sources.list.d; then
95
    cat >"$L" <<SRC
96
Types: deb
97
URIs: https://oxygenhub.io/apt
98
Suites: stable
99
Components: main
100
Signed-By: /usr/share/keyrings/oxygenhub-archive-keyring.gpg
101
SRC
102
  fi
103
fi
104
EOF
105
    sed "s/@OTHER@/$OTHER_DEB/" >"$root/DEBIAN/postrm" <<'EOF'
106
#!/bin/sh
107
set -e
108
if [ "$1" = purge ] && ! dpkg-query -W -f='${Status}' @OTHER@ 2>/dev/null | grep -q "ok installed"; then
109
  rm -f /etc/apt/sources.list.d/oxygenhub.sources /usr/share/keyrings/oxygenhub-archive-keyring.gpg
110
fi
111
EOF
112
    chmod 0755 "$root/DEBIAN/postinst" "$root/DEBIAN/postrm"
25c6adfa Andy McCall ↶ 113
    cat >"$root/DEBIAN/control" <<EOF
114
Package: $DEB_NAME
115
Version: $VERSION
116
Architecture: $deb
117
Maintainer: $MAINTAINER
118
Depends: libc6 (>= 2.28)
119
Section: vcs
120
Priority: optional
121
Homepage: $HOMEPAGE
122
Installed-Size: $(du -sk "$root/usr" | cut -f1)
123
Description: $SUMMARY
124
 $DESCRIPTION
125
EOF
126
    dpkg-deb --build --root-owner-group -Zxz "$root" "$OUT/${DEB_NAME}_${VERSION}_$deb.deb" >/dev/null
127
  fi
128
done
129
04534029 Andy McCall ↶ 130
# The source as released (oxygen#157): the oxygen tree,
131
# under oxygen-VERSION/, for packagers (haikuports) to fetch from the
132
# release at a fixed checksum. Reproducible: sorted, fixed times and
133
# owners, gzip without a timestamp.
134
if [ -z "${ONLY:-}" ] || [[ src == $ONLY ]]; then
135
  echo "== src"
136
  tar --sort=name --mtime='1970-01-01 00:00:00Z' --owner=0 --group=0 --numeric-owner \
137
    --mode='u+rwX,go+rX,go-w' --exclude=./target --exclude=.oxy \
138
    --transform "s|^\.|oxygen-$VERSION|" -cf - . | gzip -9n >"$OUT/$BIN-$VERSION-src.tar.gz"
139
fi
140
25c6adfa Andy McCall ↶ 141
rm -rf "$OUT/stage"
1931724b Andy McCall ↶ 142
(cd "$OUT" && shopt -s nullglob && sha256sum -- *.tar.gz *.zip *.deb >SHA256SUMS)
b66a5c47 Andy McCall ↶ 143
# DIST_FLAT=DIR: the same files again under names without the version, for
144
# a pipeline whose artifacts are fixed paths (the OxygenFlow dist job); the
145
# bytes are the release's, so its assets show as built by that job.
146
if [ -n "${DIST_FLAT:-}" ]; then
147
  mkdir -p "$DIST_FLAT"
148
  for f in "$OUT"/*.tar.gz "$OUT"/*.zip "$OUT"/*.deb "$OUT"/SHA256SUMS; do
149
    [ -e "$f" ] || continue
150
    b=$(basename "$f"); b=${b/-$VERSION-/-}; b=${b/_${VERSION}_/_}
151
    cp "$f" "$DIST_FLAT/$b"
152
  done
153
fi
25c6adfa Andy McCall ↶ 154
echo "== $OUT"
155
ls -l "$OUT"