99ca93d6 Andy McCall 1 month ago ↶
1
2
3
4
5
e1540908 Andy McCall 20 days ago ↶
6
7
99ca93d6 Andy McCall 1 month ago ↶
8
9
f2c97576 Andy McCall 1 month ago ↶
10
99ca93d6 Andy McCall 1 month ago ↶
11
12
13
14
15
16
set -euo pipefail
17
18
PKG = oh
19
BIN = oh
20
DEB_NAME = oh
f2c97576 Andy McCall 1 month ago ↶
21
OTHER_DEB = oxy
99ca93d6 Andy McCall 1 month ago ↶
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.* } "
f2c97576 Andy McCall 1 month ago ↶
53
54
if [ - n " $ { ONLY :- } " ] && [[ " $ platform " != $ ONLY ]] ; then continue ; fi
99ca93d6 Andy McCall 1 month ago ↶
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
5d66f27c Andy McCall 9 days ago ↶
70
71
72
73
cp " $ built " " $ stage /ohub.exe"
74
cp packaging/windows/install.ps1 " $ stage /"
99ca93d6 Andy McCall 1 month ago ↶
75
( cd " $ OUT /stage" && zip - qr " ../$ name .zip" " $ name " )
76
else
77
tar - C " $ OUT /stage" - czf " $ OUT /$ name .tar.gz" " $ name "
78
fi
79
if [ - n " $ deb " ] ; then
80
root = " $ OUT /stage/deb-$ deb "
81
mkdir - p " $ root /DEBIAN" " $ root /usr/bin" " $ root /usr/share/doc/$ DEB_NAME "
82
install - m 0755 " $ built " " $ root /usr/bin/$ BIN "
83
cp README.md docs/oh.md " $ root /usr/share/doc/$ DEB_NAME /"
84
cp LICENSE " $ root /usr/share/doc/$ DEB_NAME /copyright"
f2c97576 Andy McCall 1 month ago ↶
85
86
87
88
mkdir - p " $ root /usr/share/$ DEB_NAME "
89
install - m 0644 packaging/oxygenhub-archive-keyring.gpg " $ root /usr/share/$ DEB_NAME /"
90
sed " s/@PKG@/$ DEB_NAME /" > " $ root /DEBIAN/postinst" << ' EOF '
91
#!/bin/sh
92
set -e
93
if [ "$1" = configure ]; then
94
# The key is refreshed on every install, so a new one reaches everyone.
95
install -m 0644 /usr/share/@PKG@/oxygenhub-archive-keyring.gpg /usr/share/keyrings/oxygenhub-archive-keyring.gpg
96
# The repository is added on the first install only: removing it
97
# keeps it removed.
98
L=/etc/apt/sources.list.d/oxygenhub.sources
99
if [ -z "$2" ] && [ ! -e "$L" ] && ! grep -rqs "oxygenhub.io/apt" /etc/apt/sources.list /etc/apt/sources.list.d; then
100
cat >"$L" <<SRC
101
Types: deb
102
URIs: https://oxygenhub.io/apt
103
Suites: stable
104
Components: main
105
Signed-By: /usr/share/keyrings/oxygenhub-archive-keyring.gpg
106
SRC
107
fi
108
fi
109
EOF
110
sed " s/@OTHER@/$ OTHER_DEB /" > " $ root /DEBIAN/postrm" << ' EOF '
111
#!/bin/sh
112
set -e
113
if [ "$1" = purge ] && ! dpkg-query -W -f='${Status}' @OTHER@ 2>/dev/null | grep -q "ok installed"; then
114
rm -f /etc/apt/sources.list.d/oxygenhub.sources /usr/share/keyrings/oxygenhub-archive-keyring.gpg
115
fi
116
EOF
117
chmod 0755 " $ root /DEBIAN/postinst" " $ root /DEBIAN/postrm"
99ca93d6 Andy McCall 1 month ago ↶
118
cat > " $ root /DEBIAN/control" << EOF
119
Package: $ DEB_NAME
120
Version: $ VERSION
121
Architecture: $ deb
122
Maintainer: $ MAINTAINER
123
Depends: libc6 (>= 2.28)
124
Section: vcs
125
Priority: optional
126
Homepage: $ HOMEPAGE
127
Installed-Size: $ ( du - sk " $ root /usr" | cut - f1)
128
Description: $ SUMMARY
129
$ DESCRIPTION
130
EOF
131
dpkg-deb -- build -- root-owner-group - Zxz " $ root " " $ OUT /$ { DEB_NAME } _$ { VERSION } _$ deb .deb" > /dev/null
132
fi
133
done
134
e1540908 Andy McCall 20 days ago ↶
135
136
137
138
if [ - z " $ { ONLY :- } " ] || [[ server-linux-x86_64 == $ ONLY ]] ; then
139
echo " == server-linux-x86_64 (postgres)"
140
cargo zigbuild - q -- release -- locked -- target x86_64-unknown-linux-gnu.2.28 - p oxygenhub -- bin oxygenhub -- features postgres
141
name = " oxygenhub-server-$ VERSION -linux-x86_64"
142
stage = " $ OUT /stage/$ name "
143
mkdir - p " $ stage "
144
cp target/x86_64-unknown-linux-gnu/release/oxygenhub " $ stage /"
145
cp LICENSE docs/postgres.md docs/deploy.md " $ stage /"
146
tar - C " $ OUT /stage" - czf " $ OUT /$ name .tar.gz" " $ name "
147
fi
148
93f445fa Andy McCall 7 days ago ↶
149
150
151
152
153
if [ - z " $ { ONLY :- } " ] || [[ src == $ ONLY ]] ; then
154
echo " == src"
155
tar -- sort= name -- mtime= ' 1970-01-01 00:00:00Z' -- owner= 0 -- group= 0 -- numeric-owner \
156
-- mode= ' u+rwX,go+rX,go-w' -- exclude= ./target -- exclude= .oxy \
157
-- transform " s|^\.|oxygenhub-$ VERSION |" - cf - . | gzip - 9n > " $ OUT /$ BIN -$ VERSION -src.tar.gz"
158
fi
159
99ca93d6 Andy McCall 1 month ago ↶
160
rm - rf " $ OUT /stage"
f2c97576 Andy McCall 1 month ago ↶
161
( cd " $ OUT " && shopt -s nullglob && sha256sum -- * .tar.gz * .zip * .deb > SHA256SUMS )
913e5ad2 Andy McCall 1 month ago ↶
162
163
164
165
if [ - n " $ { DIST_FLAT :- } " ] ; then
166
mkdir - p " $ DIST_FLAT "
167
for f in " $ OUT " /* .tar.gz " $ OUT " /* .zip " $ OUT " /* .deb " $ OUT " /SHA256SUMS ; do
168
[ - e " $ f " ] || continue
169
b = $ ( basename " $ f " ) ; b = $ { b / -$ VERSION -/ - } ; b = $ { b / _$ { VERSION } _/ _ }
170
cp " $ f " " $ DIST_FLAT /$ b "
171
done
172
fi
99ca93d6 Andy McCall 1 month ago ↶
173
echo " == $ OUT "
174
ls - l " $ OUT "