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