99ca93d6 Andy McCall 1 month ago ↶
1
2
3
4
5
6
7
8
f2c97576 Andy McCall 1 month ago ↶
9
99ca93d6 Andy McCall 1 month ago ↶
10
11
12
13
14
15
set -euo pipefail
16
17
PKG = oh
18
BIN = oh
19
DEB_NAME = oh
f2c97576 Andy McCall 1 month ago ↶
20
OTHER_DEB = oxy
99ca93d6 Andy McCall 1 month ago ↶
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
36
export CARGO_PROFILE_RELEASE_DEBUG = 0 CARGO_PROFILE_RELEASE_STRIP = true CARGO_INCREMENTAL = 0
37
38
export OXY_BUILD = " v$ VERSION "
39
40
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.* } "
f2c97576 Andy McCall 1 month ago ↶
52
53
if [ - n " $ { ONLY :- } " ] && [[ " $ platform " != $ ONLY ]] ; then continue ; fi
99ca93d6 Andy McCall 1 month ago ↶
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
( cd " $ OUT /stage" && zip - qr " ../$ name .zip" " $ name " )
70
else
71
tar - C " $ OUT /stage" - czf " $ OUT /$ name .tar.gz" " $ name "
72
fi
73
if [ - n " $ deb " ] ; then
74
root = " $ OUT /stage/deb-$ deb "
75
mkdir - p " $ root /DEBIAN" " $ root /usr/bin" " $ root /usr/share/doc/$ DEB_NAME "
76
install - m 0755 " $ built " " $ root /usr/bin/$ BIN "
77
cp README.md docs/oh.md " $ root /usr/share/doc/$ DEB_NAME /"
78
cp LICENSE " $ root /usr/share/doc/$ DEB_NAME /copyright"
f2c97576 Andy McCall 1 month ago ↶
79
80
81
82
mkdir - p " $ root /usr/share/$ DEB_NAME "
83
install - m 0644 packaging/oxygenhub-archive-keyring.gpg " $ root /usr/share/$ DEB_NAME /"
84
sed " s/@PKG@/$ DEB_NAME /" > " $ root /DEBIAN/postinst" << ' EOF '
85
#!/bin/sh
86
set -e
87
if [ "$1" = configure ]; then
88
# The key is refreshed on every install, so a new one reaches everyone.
89
install -m 0644 /usr/share/@PKG@/oxygenhub-archive-keyring.gpg /usr/share/keyrings/oxygenhub-archive-keyring.gpg
90
# The repository is added on the first install only: removing it
91
# keeps it removed.
92
L=/etc/apt/sources.list.d/oxygenhub.sources
93
if [ -z "$2" ] && [ ! -e "$L" ] && ! grep -rqs "oxygenhub.io/apt" /etc/apt/sources.list /etc/apt/sources.list.d; then
94
cat >"$L" <<SRC
95
Types: deb
96
URIs: https://oxygenhub.io/apt
97
Suites: stable
98
Components: main
73beb84b Andy McCall 28 days ago ↶
99
Architectures: $(dpkg --print-architecture)
f2c97576 Andy McCall 1 month ago ↶
100
Signed-By: /usr/share/keyrings/oxygenhub-archive-keyring.gpg
101
SRC
102
fi
73beb84b Andy McCall 28 days ago ↶
103
# Only this machine's architecture: with foreign ones enabled (i386 on
104
# most amd64 systems) apt otherwise asks for packages the repository
105
# has not got, and says so on every update. Sources written before
106
# this get the line too.
107
if [ -e "$L" ] && ! grep -q "^Architectures:" "$L"; then
108
sed -i "/^Components:/a Architectures: $(dpkg --print-architecture)" "$L"
109
fi
f2c97576 Andy McCall 1 month ago ↶
110
fi
111
EOF
112
sed " s/@OTHER@/$ OTHER_DEB /" > " $ root /DEBIAN/postrm" << ' EOF '
113
#!/bin/sh
114
set -e
115
if [ "$1" = purge ] && ! dpkg-query -W -f='${Status}' @OTHER@ 2>/dev/null | grep -q "ok installed"; then
116
rm -f /etc/apt/sources.list.d/oxygenhub.sources /usr/share/keyrings/oxygenhub-archive-keyring.gpg
117
fi
118
EOF
119
chmod 0755 " $ root /DEBIAN/postinst" " $ root /DEBIAN/postrm"
99ca93d6 Andy McCall 1 month ago ↶
120
cat > " $ root /DEBIAN/control" << EOF
121
Package: $ DEB_NAME
122
Version: $ VERSION
123
Architecture: $ deb
124
Maintainer: $ MAINTAINER
125
Depends: libc6 (>= 2.28)
126
Section: vcs
127
Priority: optional
128
Homepage: $ HOMEPAGE
129
Installed-Size: $ ( du - sk " $ root /usr" | cut - f1)
130
Description: $ SUMMARY
131
$ DESCRIPTION
132
EOF
133
dpkg-deb -- build -- root-owner-group - Zxz " $ root " " $ OUT /$ { DEB_NAME } _$ { VERSION } _$ deb .deb" > /dev/null
134
fi
135
done
136
137
rm - rf " $ OUT /stage"
f2c97576 Andy McCall 1 month ago ↶
138
( cd " $ OUT " && shopt -s nullglob && sha256sum -- * .tar.gz * .zip * .deb > SHA256SUMS )
99ca93d6 Andy McCall 1 month ago ↶
139
echo " == $ OUT "
140
ls - l " $ OUT "