| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
set -euo pipefail |
| 17 |
|
| 18 |
PKG=oh |
| 19 |
BIN=oh |
| 20 |
DEB_NAME=oh |
| 21 |
OTHER_DEB=oxy |
| 22 |
SUMMARY="OxygenHub from the command line" |
| 23 |
DESCRIPTION="oh talks to an OxygenHub (such as https://oxygenhub.io): issues, |
| 24 |
proposals and their reviews, releases, Flow runs and checks, from the |
| 25 |
terminal. It works alongside oxy, the Oxygen version control client." |
| 26 |
HOMEPAGE="https://oxygenhub.io/andymccall/oxygenhub" |
| 27 |
MAINTAINER="Andy McCall <[email protected]>" |
| 28 |
DOCS=(README.md LICENSE docs/oh.md) |
| 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 |
|
| 37 |
export CARGO_PROFILE_RELEASE_DEBUG=0 CARGO_PROFILE_RELEASE_STRIP=true CARGO_INCREMENTAL=0 |
| 38 |
|
| 39 |
export OXY_BUILD="v$VERSION" |
| 40 |
|
| 41 |
|
| 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.*}" |
| 53 |
|
| 54 |
if [ -n "${ONLY:-}" ] && [[ "$platform" != $ONLY ]]; then continue; fi |
| 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 docs/oh.md "$root/usr/share/doc/$DEB_NAME/" |
| 79 |
cp LICENSE "$root/usr/share/doc/$DEB_NAME/copyright" |
| 80 |
|
| 81 |
|
| 82 |
|
| 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" |
| 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 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
if [ -z "${ONLY:-}" ] || [[ server-linux-x86_64 == $ONLY ]]; then |
| 134 |
echo "== server-linux-x86_64 (postgres)" |
| 135 |
cargo zigbuild -q --release --locked --target x86_64-unknown-linux-gnu.2.28 -p oxygenhub --bin oxygenhub --features postgres |
| 136 |
name="oxygenhub-server-$VERSION-linux-x86_64" |
| 137 |
stage="$OUT/stage/$name" |
| 138 |
mkdir -p "$stage" |
| 139 |
cp target/x86_64-unknown-linux-gnu/release/oxygenhub "$stage/" |
| 140 |
cp LICENSE docs/postgres.md docs/deploy.md "$stage/" |
| 141 |
tar -C "$OUT/stage" -czf "$OUT/$name.tar.gz" "$name" |
| 142 |
fi |
| 143 |
|
| 144 |
rm -rf "$OUT/stage" |
| 145 |
(cd "$OUT" && shopt -s nullglob && sha256sum -- *.tar.gz *.zip *.deb >SHA256SUMS) |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
if [ -n "${DIST_FLAT:-}" ]; then |
| 150 |
mkdir -p "$DIST_FLAT" |
| 151 |
for f in "$OUT"/*.tar.gz "$OUT"/*.zip "$OUT"/*.deb "$OUT"/SHA256SUMS; do |
| 152 |
[ -e "$f" ] || continue |
| 153 |
b=$(basename "$f"); b=${b/-$VERSION-/-}; b=${b/_${VERSION}_/_} |
| 154 |
cp "$f" "$DIST_FLAT/$b" |
| 155 |
done |
| 156 |
fi |
| 157 |
echo "== $OUT" |
| 158 |
ls -l "$OUT" |