OXYGENHUB
# 851a26a2a6d1 oxygenhub / scripts / dist.sh
5.5 KiB · Bourne Again Shell (bash) · executable · last changed oh works in PowerShell: ohub.exe and install.ps1, which respects the execution policy (closes #319); the images page tells peer-held images apart (refs #342); a queued job's reason names CPUs 9 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 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)
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
# 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=oh                   # the cargo package
18
BIN=oh                   # the binary it builds
19
DEB_NAME=oh              # the Debian package
20
OTHER_DEB=oxy            # the other package sharing the apt repository files
21
SUMMARY="OxygenHub from the command line"
22
DESCRIPTION="oh talks to an OxygenHub (such as https://oxygenhub.io): issues,
23
 proposals and their reviews, releases, Flow runs and checks, from the
24
 terminal. It works alongside oxy, the Oxygen version control client."
25
HOMEPAGE="https://oxygenhub.io/andymccall/oxygenhub"
26
MAINTAINER="Andy McCall <[email protected]>"
27
DOCS=(README.md LICENSE docs/oh.md)
28
29
cd "$(dirname "$0")/.."
30
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'))")}"
31
VERSION="${VERSION#v}"
32
OUT="target/dist/$VERSION"
33
rm -rf "$OUT" && mkdir -p "$OUT"
34
export PATH="$HOME/.local/opt/zig:$PATH"
35
# Stripped, with no debug info: these are for people, not for debugging.
36
export CARGO_PROFILE_RELEASE_DEBUG=0 CARGO_PROFILE_RELEASE_STRIP=true CARGO_INCREMENTAL=0
37
# The version the binary reports.
38
export OXY_BUILD="v$VERSION"
39
40
# target triple | platform name | build tool | Debian architecture
41
PLATFORMS=(
42
  "x86_64-unknown-linux-gnu.2.28|linux-x86_64|zig|amd64"
43
  "aarch64-unknown-linux-gnu.2.28|linux-arm64|zig|arm64"
44
  "x86_64-apple-darwin|macos-x86_64|zig|"
45
  "aarch64-apple-darwin|macos-arm64|zig|"
46
  "x86_64-pc-windows-gnu|windows-x86_64|cargo|"
47
)
48
49
for p in "${PLATFORMS[@]}"; do
50
  IFS='|' read -r target platform tool deb <<<"$p"
51
  triple="${target%%.2.*}"
52
  # ONLY=linux-x86_64 (a glob) builds just the platforms it matches.
53
  if [ -n "${ONLY:-}" ] && [[ "$platform" != $ONLY ]]; then continue; fi
54
  echo "== $platform ($target)"
55
  if [ "$tool" = zig ]; then
56
    cargo zigbuild -q --release --locked --target "$target" -p "$PKG"
57
  else
58
    cargo build -q --release --locked --target "$target" -p "$PKG"
59
  fi
60
  exe="$BIN"
61
  [[ "$triple" == *windows* ]] && exe="$BIN.exe"
62
  built="target/$triple/release/$exe"
63
  name="$BIN-$VERSION-$platform"
64
  stage="$OUT/stage/$name"
65
  mkdir -p "$stage"
66
  cp "$built" "$stage/"
67
  cp "${DOCS[@]}" "$stage/"
68
  if [[ "$triple" == *windows* ]]; then
69
    # PowerShell's built-in alias `oh` (Out-Host) hides oh.exe (#319):
70
    # ohub.exe is the same program under a name nothing hides, and
71
    # install.ps1 puts both on PATH and removes the alias in the profile.
72
    cp "$built" "$stage/ohub.exe"
73
    cp packaging/windows/install.ps1 "$stage/"
74
    (cd "$OUT/stage" && zip -qr "../$name.zip" "$name")
75
  else
76
    tar -C "$OUT/stage" -czf "$OUT/$name.tar.gz" "$name"
77
  fi
78
  if [ -n "$deb" ]; then
79
    root="$OUT/stage/deb-$deb"
80
    mkdir -p "$root/DEBIAN" "$root/usr/bin" "$root/usr/share/doc/$DEB_NAME"
81
    install -m 0755 "$built" "$root/usr/bin/$BIN"
82
    cp README.md docs/oh.md "$root/usr/share/doc/$DEB_NAME/"
83
    cp LICENSE "$root/usr/share/doc/$DEB_NAME/copyright"
84
    # The apt repository at oxygenhub.io (oxygenhub#85): the package ships
85
    # the archive's key and, on its first install, adds the repository, so
86
    # apt upgrade keeps it current. oxy and oh share the files they write.
87
    mkdir -p "$root/usr/share/$DEB_NAME"
88
    install -m 0644 packaging/oxygenhub-archive-keyring.gpg "$root/usr/share/$DEB_NAME/"
89
    sed "s/@PKG@/$DEB_NAME/" >"$root/DEBIAN/postinst" <<'EOF'
90
#!/bin/sh
91
set -e
92
if [ "$1" = configure ]; then
93
  # The key is refreshed on every install, so a new one reaches everyone.
94
  install -m 0644 /usr/share/@PKG@/oxygenhub-archive-keyring.gpg /usr/share/keyrings/oxygenhub-archive-keyring.gpg
95
  # The repository is added on the first install only: removing it
96
  # keeps it removed.
97
  L=/etc/apt/sources.list.d/oxygenhub.sources
98
  if [ -z "$2" ] && [ ! -e "$L" ] && ! grep -rqs "oxygenhub.io/apt" /etc/apt/sources.list /etc/apt/sources.list.d; then
99
    cat >"$L" <<SRC
100
Types: deb
101
URIs: https://oxygenhub.io/apt
102
Suites: stable
103
Components: main
104
Signed-By: /usr/share/keyrings/oxygenhub-archive-keyring.gpg
105
SRC
106
  fi
107
fi
108
EOF
109
    sed "s/@OTHER@/$OTHER_DEB/" >"$root/DEBIAN/postrm" <<'EOF'
110
#!/bin/sh
111
set -e
112
if [ "$1" = purge ] && ! dpkg-query -W -f='${Status}' @OTHER@ 2>/dev/null | grep -q "ok installed"; then
113
  rm -f /etc/apt/sources.list.d/oxygenhub.sources /usr/share/keyrings/oxygenhub-archive-keyring.gpg
114
fi
115
EOF
116
    chmod 0755 "$root/DEBIAN/postinst" "$root/DEBIAN/postrm"
117
    cat >"$root/DEBIAN/control" <<EOF
118
Package: $DEB_NAME
119
Version: $VERSION
120
Architecture: $deb
121
Maintainer: $MAINTAINER
122
Depends: libc6 (>= 2.28)
123
Section: vcs
124
Priority: optional
125
Homepage: $HOMEPAGE
126
Installed-Size: $(du -sk "$root/usr" | cut -f1)
127
Description: $SUMMARY
128
 $DESCRIPTION
129
EOF
130
    dpkg-deb --build --root-owner-group -Zxz "$root" "$OUT/${DEB_NAME}_${VERSION}_$deb.deb" >/dev/null
131
  fi
132
done
133
134
rm -rf "$OUT/stage"
135
(cd "$OUT" && shopt -s nullglob && sha256sum -- *.tar.gz *.zip *.deb >SHA256SUMS)
136
echo "== $OUT"
137
ls -l "$OUT"