| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
set -euo pipefail |
| 17 |
|
| 18 |
PKG=oxy |
| 19 |
BIN=oxy |
| 20 |
DEB_NAME=oxy |
| 21 |
OTHER_DEB=oh |
| 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 |
|
| 38 |
export CARGO_PROFILE_RELEASE_DEBUG=0 CARGO_PROFILE_RELEASE_STRIP=true CARGO_INCREMENTAL=0 |
| 39 |
|
| 40 |
export OXY_BUILD="v$VERSION" |
| 41 |
|
| 42 |
|
| 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 |
|
| 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 |
|
| 83 |
|
| 84 |
|
| 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 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 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 |
|
| 154 |
|
| 155 |
|
| 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" |